1*46079Sbostic /*- 2*46079Sbostic * Copyright (c) 1990 The Regents of the University of California. 3*46079Sbostic * All rights reserved. 4*46079Sbostic * 5*46079Sbostic * This code is derived from software contributed to Berkeley by 6*46079Sbostic * Chris Torek. 7*46079Sbostic * 8*46079Sbostic * %sccs.include.redist.c% 921404Sdist */ 1021404Sdist 1126647Sdonn #if defined(LIBC_SCCS) && !defined(lint) 12*46079Sbostic static char sccsid[] = "@(#)fopen.c 5.3 (Berkeley) 01/20/91"; 13*46079Sbostic #endif /* LIBC_SCCS and not lint */ 1421404Sdist 1517951Sserge #include <sys/types.h> 16*46079Sbostic #include <sys/stat.h> 1717951Sserge #include <stdio.h> 18*46079Sbostic #include <errno.h> 19*46079Sbostic #include "local.h" 202004Swnj 212004Swnj FILE * 222004Swnj fopen(file, mode) 2317951Sserge char *file; 24*46079Sbostic char *mode; 252004Swnj { 26*46079Sbostic register FILE *fp; 27*46079Sbostic register int f; 28*46079Sbostic int flags, oflags; 292004Swnj 30*46079Sbostic if ((flags = __sflags(mode, &oflags)) == 0) 3117951Sserge return (NULL); 32*46079Sbostic if ((fp = __sfp()) == NULL) 3317951Sserge return (NULL); 34*46079Sbostic if ((f = open(file, oflags, DEFFILEMODE)) < 0) { 35*46079Sbostic fp->_flags = 0; /* release */ 36*46079Sbostic return (NULL); 3717951Sserge } 38*46079Sbostic fp->_file = f; 39*46079Sbostic fp->_flags = flags; 40*46079Sbostic fp->_cookie = fp; 41*46079Sbostic fp->_read = __sread; 42*46079Sbostic fp->_write = __swrite; 43*46079Sbostic fp->_seek = __sseek; 44*46079Sbostic fp->_close = __sclose; 45*46079Sbostic return (fp); 462004Swnj } 47