/*
 * This module replaces the standard library "fopen(name, mode)" to include
 * some Decus C mode functions:
 *	r	Identical to standard function
 *	w	Creates the file using attributes "rat=CR, rfm=VAR"
 *		so files "look like" standard vax files
 *	a	Identical to standard function
 *	rn	Identical to standard function fopen(name, "r")
 *	wn	Identical to standard function fopen(name, "w")
 * This module compiles, but it hasn't been tested.
 */

#include <stdio.h>

FILE *
fopen(name, mode)
char		*name;		/* File name				*/
char		*mode;		/* Open mode				*/
/*
 * Open the file
 */
{
	int	nonewlines = (mode[1] == 'n');

	switch (mode[0]) {
	case	'r':
		return(fdopen(open(name, 0), "r"));

	case	'a':
		return(fdopen(open(name, 1), mode));

	case	'w':
		return((nonewlines)
			? fdopen(creat(name, 0), "w")
			: fdopen(creat(name, 0, "rat=cr", "rfm=var"), "w")
		);
	}
	fprintf(stderr, "illegal mode \"%s\"\n", mode);
	exit(2);
}

