5 /* fopen( const char *, const char * )
7 This file is part of the Public Domain C Library (PDCLib).
8 Permission is granted to use, modify, and / or redistribute at will.
15 #include <_PDCLIB_glue.h>
17 static const FILE * _PDCLIB_filelist = NULL;
19 static int filemode( char const * const mode )
31 rc |= _PDCLIB_FAPPEND;
36 for ( size_t i = 1; i < 4; ++i )
41 if ( rc & _PDCLIB_FRW ) return -1;
45 if ( rc & _PDCLIB_FBIN ) return -1;
57 FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode )
60 if ( mode == NULL || filename == NULL || filename[0] == '\0' )
64 if ( ( rc = calloc( 1, sizeof( FILE ) ) ) == NULL ) return rc; /* no space for another FILE */
65 if ( ( rc->status = filemode( mode ) ) == -1 ) goto fail; /* invalid mode given */
66 if ( ( rc->handle = _PDCLIB_open( filename, rc->status ) ) == -1 ) goto fail; /* OS "open" failed */
67 rc->next = _PDCLIB_filelist;
68 _PDCLIB_filelist = rc;
69 /* TODO: Continue here: Set up PDCLib FILE contents */
79 #include <_PDCLIB_test.h>
83 TESTCASE( NO_TESTDRIVER );