]> pd.if.org Git - pdclib/blob - platform/example/functions/stdio/remove.c
Addressed ticket #40 (non-standard errno values).
[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             /* See the comments on implementation-defined errno values in
41                <_PDCLIB_config.h>.
42             */
43             case EACCES:
44             case EFAULT:
45             case EIO:
46             case EISDIR:
47             case ELOOP:
48             case ENAMETOOLONG:
49             case ENOENT:
50             case ENOMEM:
51             case ENOTDIR:
52             case EPERM:
53             case EROFS:
54                 _PDCLIB_errno = _PDCLIB_ERROR;
55                 break;
56             default:
57                 /* This should be something like EUNKNOWN. */
58                 _PDCLIB_errno = _PDCLIB_ERROR;
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