Usermode/libc-libposix - Features for SpiderWeb/SpiderScript
[tpg/acess2.git] / Usermode / Libraries / libposix.so_src / dirent.c
1 /*
2  * Acess2 C Library
3  * - By John Hodge (thePowersGang)
4  *
5  * dirent.c
6  * - Directory Functions
7  */
8 #include <dirent.h>
9 #include <stddef.h>     // NULL
10 #include <acess/sys.h>
11 #include <errno.h>
12
13 struct DIR_s
14 {
15          int    fd;
16          int    pos;
17         struct dirent   tmpent;
18 };
19
20 // === CODE ===
21 DIR *fdopendir(int fd)
22 {
23         t_sysFInfo      info;
24         if( _SysFInfo(fd, &info, 0) != 0 )
25                 return NULL;
26
27         
28
29         return NULL;
30 }
31
32 DIR *opendir(const char *name)
33 {
34         int fd = _SysOpen(name, OPENFLAG_READ);
35         if( fd == -1 )
36                 return NULL;
37         
38         DIR *ret = fdopendir(fd);
39         if( !ret ) {
40                 _SysClose(fd);
41         }
42         return ret;
43 }
44
45 int closedir(DIR *dp)
46 {
47         if( !dp ) {
48                 errno = EINVAL;
49                 return -1;
50         }
51         return 0;
52 }
53
54 struct dirent *readdir(DIR *dp)
55 {
56         if( !dp ) {
57                 errno = EINVAL;
58                 return NULL;
59         }
60
61         errno = EOK;
62         int rv = _SysReadDir(dp->fd, dp->tmpent.d_name);
63         if( rv != 1 ) {
64                 // TODO: Fix kernel-land API
65                 return NULL;
66         }
67         dp->tmpent.d_ino = 0;
68
69         return &dp->tmpent;
70 }
71
72 extern int      readdir_r(DIR *, struct dirent *, struct dirent **);
73 extern void     rewinddir(DIR *);
74 extern void     seekdir(DIR *, long int);
75 extern long int telldir(DIR *);

UCC git Repository :: git.ucc.asn.au