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>
17 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
19 FILE * fopen( const char * _PDCLIB_restrict filename,
20 const char * _PDCLIB_restrict mode )
22 int imode = _PDCLIB_filemode( mode );
23 _PDCLIB_fd_t fd = _PDCLIB_open( filename, imode );
24 if(fd == _PDCLIB_NOHANDLE) {
28 FILE * f = _PDCLIB_fdopen( fd, imode, filename );
30 int saveErrno = errno;
40 #include <_PDCLIB_test.h>
44 /* Some of the tests are not executed for regression tests, as the libc on
45 my system is at once less forgiving (segfaults on mode NULL) and more
46 forgiving (accepts undefined modes).
50 TESTCASE_NOREG( fopen( NULL, NULL ) == NULL );
51 TESTCASE( fopen( NULL, "w" ) == NULL );
52 TESTCASE_NOREG( fopen( "", NULL ) == NULL );
53 TESTCASE( fopen( "", "w" ) == NULL );
54 TESTCASE( fopen( "foo", "" ) == NULL );
55 TESTCASE_NOREG( fopen( testfile, "wq" ) == NULL ); /* Undefined mode */
56 TESTCASE_NOREG( fopen( testfile, "wr" ) == NULL ); /* Undefined mode */
57 TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL );
58 TESTCASE( fclose( fh ) == 0 );
59 TESTCASE( remove( testfile ) == 0 );