146079Sbostic /*- 246079Sbostic * Copyright (c) 1990 The Regents of the University of California. 346079Sbostic * All rights reserved. 446079Sbostic * 546079Sbostic * This code is derived from software contributed to Berkeley by 646079Sbostic * Chris Torek. 746079Sbostic * 846079Sbostic * %sccs.include.redist.c% 921404Sdist */ 1021404Sdist 1126647Sdonn #if defined(LIBC_SCCS) && !defined(lint) 12*46271Storek static char sccsid[] = "@(#)fopen.c 5.4 (Berkeley) 02/05/91"; 1346079Sbostic #endif /* LIBC_SCCS and not lint */ 1421404Sdist 1517951Sserge #include <sys/types.h> 1646079Sbostic #include <sys/stat.h> 1717951Sserge #include <stdio.h> 1846079Sbostic #include <errno.h> 1946079Sbostic #include "local.h" 202004Swnj 212004Swnj FILE * 222004Swnj fopen(file, mode) 23*46271Storek const char *file; 24*46271Storek const char *mode; 252004Swnj { 2646079Sbostic register FILE *fp; 2746079Sbostic register int f; 2846079Sbostic int flags, oflags; 292004Swnj 3046079Sbostic if ((flags = __sflags(mode, &oflags)) == 0) 3117951Sserge return (NULL); 3246079Sbostic if ((fp = __sfp()) == NULL) 3317951Sserge return (NULL); 3446079Sbostic if ((f = open(file, oflags, DEFFILEMODE)) < 0) { 3546079Sbostic fp->_flags = 0; /* release */ 3646079Sbostic return (NULL); 3717951Sserge } 3846079Sbostic fp->_file = f; 3946079Sbostic fp->_flags = flags; 4046079Sbostic fp->_cookie = fp; 4146079Sbostic fp->_read = __sread; 4246079Sbostic fp->_write = __swrite; 4346079Sbostic fp->_seek = __sseek; 4446079Sbostic fp->_close = __sclose; 4546079Sbostic return (fp); 462004Swnj } 47