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_io.h>
14 #include <_PDCLIB_glue.h>
18 extern FILE * _PDCLIB_filelist;
20 FILE * fopen( const char * _PDCLIB_restrict filename,
21 const char * _PDCLIB_restrict mode )
23 int imode = _PDCLIB_filemode( mode );
25 if( imode == 0 || filename == NULL )
29 const _PDCLIB_fileops_t * ops;
30 if(!_PDCLIB_open( &fd, &ops, filename, imode )) {
34 FILE * f = _PDCLIB_fvopen( fd, ops, imode, filename );
36 int saveErrno = errno;
46 #include <_PDCLIB_test.h>
50 /* Some of the tests are not executed for regression tests, as the libc on
51 my system is at once less forgiving (segfaults on mode NULL) and more
52 forgiving (accepts undefined modes).
56 TESTCASE_NOREG( fopen( NULL, NULL ) == NULL );
57 TESTCASE( fopen( NULL, "w" ) == NULL );
58 TESTCASE_NOREG( fopen( "", NULL ) == NULL );
59 TESTCASE( fopen( "", "w" ) == NULL );
60 TESTCASE( fopen( "foo", "" ) == NULL );
61 TESTCASE_NOREG( fopen( testfile, "wq" ) == NULL ); /* Undefined mode */
62 TESTCASE_NOREG( fopen( testfile, "wr" ) == NULL ); /* Undefined mode */
63 TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL );
64 TESTCASE( fclose( fh ) == 0 );
65 TESTCASE( remove( testfile ) == 0 );