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