3 /* _PDCLIB_remove( 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.
9 /* This is an example implementation of _PDCLIB_remove() (declared in
10 _PDCLIB_glue.h), fit for use in POSIX kernels.
11 NOTE: Linux is *not* POSIX-compliant in this, as it sets EISDIR instead of
12 EPERM if you try to unlink a directory. Check the manpage for unlink(2).
16 #include <_PDCLIB_glue.h>
20 int _PDCLIB_remove( const char * filename )
22 int prev_errno = errno;
25 if ( ( ( rc = unlink( filename ) ) != 0 ) && ( errno == EISDIR ) )
27 rc = rmdir( filename );
36 /* TODO: Work around the following undef */
38 #include <_PDCLIB_test.h>
45 char filename[] = "touch testfile";
47 /* file is actually readable */
48 TESTCASE( fopen( filename + 6, "r" ) != NULL );
49 /* remove function does not return error */
50 TESTCASE( _PDCLIB_remove( filename + 6 ) == 0 );
51 /* file is no longer readable */
52 TESTCASE( fopen( filename + 6, "r" ) == NULL );
53 /* remove function does return error */
54 TESTCASE( _PDCLIB_remove( filename + 6 ) != 0 );
55 memcpy( filename, "mkdir", 5 );
56 /* create directory */
58 /* remove function does not return error */
59 TESTCASE( _PDCLIB_remove( filename + 6 ) == 0 );
60 /* remove function does return error */
61 TESTCASE( _PDCLIB_remove( filename + 6 ) != 0 );