/* @(#)fileluopen.c	1.13 00/12/04 Copyright 1986, 1995 J. Schilling */
/*
 *	Copyright (c) 1986, 1995 J. Schilling
 */
/*@@C@@*/

#include "io.h"

/*
 * XXX We need to switch to fseeko()/ftello() sometime in the future.
 * XXX See io.h hack.
 */

/*
 *	fileluopen - open a stream for lun
 */
EXPORT FILE *
fileluopen(f, mode)
	int		f;
	const char	*mode;
{
	int	omode = 0;
	int	flag = 0;

	if (!_cvmod(mode, &omode, &flag))
		return ((FILE*) NULL);

	if (omode & (O_NDELAY|O_CREAT|O_TRUNC|O_EXCL)) {
		raisecond(_badmode, 0L);
		return ((FILE*) NULL);
	}

	if (fcntl(f, F_GETFD, 0) < 0) {
		raisecond(_badfile, 0L);
		return ((FILE*) NULL);
	}		

	if (omode & O_APPEND)
		lseek(f, (off_t)0, SEEK_END);

	return (_fcons((FILE *)0, f, flag));
}
