]> pd.if.org Git - pdclib/blob - platform/example/functions/stdio/remove.c
8bf3040cf03c9f821f68ecff2325a7c63b4e66af
[pdclib] / platform / example / functions / stdio / remove.c
1 /* $Id$ */
2
3 /* remove( const char * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 /* This is an example implementation of remove() fit for use with POSIX kernels.
10 */
11
12 #include <stdio.h>
13
14 #ifndef REGTEST
15
16 #include <string.h>
17
18 #include "/usr/include/errno.h"
19
20 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
21
22 extern int unlink( const char * pathname );
23
24 int remove( const char * pathname )
25 {
26     int rc;
27     struct _PDCLIB_file_t * current = _PDCLIB_filelist;
28     while ( current != NULL )
29     {
30         if ( ( current->filename != NULL ) && ( strcmp( current->filename, pathname ) == 0 ) )
31         {
32             return EOF;
33         }
34         current = current->next;
35     }
36     if ( ( rc = unlink( pathname ) ) == -1 )
37     {
38         switch ( errno )
39         {
40             /* These are the values possible on a Linux machine. Adapt the
41                values and their mapping to PDCLib errno values at will. (This
42                is an example implementation, so we keep it very simple.)
43             */
44             case EACCES:
45             case EFAULT:
46             case EIO:
47             case EISDIR:
48             case ELOOP:
49             case ENAMETOOLONG:
50             case ENOENT:
51             case ENOMEM:
52             case ENOTDIR:
53             case EPERM:
54             case EROFS:
55                 _PDCLIB_errno = _PDCLIB_EIO;
56                 break;
57             default:
58                 _PDCLIB_errno = _PDCLIB_EUNKNOWN;
59                 break;
60         }
61     }
62     return rc;
63 }
64
65 #endif
66
67 #ifdef TEST
68 #include <_PDCLIB_test.h>
69
70 int main( void )
71 {
72     /* Testing covered by ftell.c (and several others) */
73     return TEST_RESULTS;
74 }
75
76 #endif
77