/*
 * lib/fopen.c
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1995 by Ralf Baechle
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <arc/errno.h>
#include <stand/stdio.h>

/*
 * Prototypes
 */
extern FILE *__sflags(const char *mode, int *flags);
extern FILE *__sfp();

FILE *
fopen(const char *file, const char *mode)
{
    FILE *nfp;
    int f;
    int flags;
    char c;

    if (mode == NULL)
	return NULL;
    if(__sflags(mode, &flags) == 0)
	return NULL;
    if((nfp = __sfp()) == NULL)
	return NULL;
    if ((f = open(file, flags, DEFFILEMODE)) < 0)
	return NULL;
    nfp->fh = f;
    /*
     * Seek to the end of file when opening in append mode.
     */
    if (flags & O_APPEND)
	lseek(nfp, (off_t)0, SEEK_END);

    return nfp;
}
