3 /* fopen( const char *, const char * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
13 #include <_PDCLIB_glue.h>
15 static FILE * _PDCLIB_filelist = NULL;
17 static int filemode( char const * const mode )
29 rc |= _PDCLIB_FAPPEND;
34 for ( size_t i = 1; i < 4; ++i )
39 if ( rc & _PDCLIB_FRW ) return -1;
43 if ( rc & _PDCLIB_FBIN ) return -1;
55 FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode )
58 if ( mode == NULL || filename == NULL || filename[0] == '\0' )
62 if ( ( rc = calloc( 1, sizeof( FILE ) ) ) == NULL ) return rc; /* no space for another FILE */
63 if ( ( rc->status = filemode( mode ) ) == -1 ) goto fail; /* invalid mode given */
64 if ( ( rc->handle = _PDCLIB_open( filename, rc->status ) ) == -1 ) goto fail; /* OS "open" failed */
65 rc->next = _PDCLIB_filelist;
66 _PDCLIB_filelist = rc;
67 /* TODO: Continue here: Set up PDCLib FILE contents */
77 #include <_PDCLIB_test.h>
81 TESTCASE( NO_TESTDRIVER );