]> pd.if.org Git - pdclib/blob - platform/example/functions/_PDCLIB/remove.c
Porting current working set from CVS.
[pdclib] / platform / example / functions / _PDCLIB / remove.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* _PDCLIB_remove( const char * )
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 /* This is an example implementation of _PDCLIB_remove() (declared in
12    _PDCLIB_glue.h), fit for use in POSIX kernels.
13    NOTE: Linux is *not* POSIX-compliant in this, as it sets EISDIR instead of
14    EPERM if you try to unlink a directory. Check the manpage for unlink(2).
15 */
16
17 #ifndef REGTEST
18 #include <_PDCLIB_glue.h>
19 #include <errno.h>
20 #include <unistd.h>
21
22 int _PDCLIB_remove( const char * filename )
23 {
24     int prev_errno = errno;
25     int rc;
26     errno = 0;
27     if ( ( ( rc = unlink( filename ) ) != 0 ) && ( errno == EPERM ) )
28     {
29         rc = rmdir( filename );
30     }
31     errno = prev_errno;
32     return rc;
33 }
34
35 #endif
36
37 #ifdef TEST
38 #include <_PDCLIB_test.h>
39
40 int main( void )
41 {
42     TESTCASE( NO_TESTDRIVER );
43     return TEST_RESULTS;
44 }
45
46 #endif