Modules/E1000 - Enabled bus master for qemu (which doesn't enable it)
[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         DIR     *ret = malloc(sizeof(DIR));
28         ret->fd = fd;
29         ret->pos = 0;
30         return ret;
31 }
32
33 DIR *opendir(const char *name)
34 {
35         int fd = _SysOpen(name, OPENFLAG_READ);
36         if( fd == -1 )
37                 return NULL;
38         
39         DIR *ret = fdopendir(fd);
40         if( !ret ) {
41                 _SysClose(fd);
42         }
43         return ret;
44 }
45
46 int closedir(DIR *dp)
47 {
48         if( !dp ) {
49                 errno = EINVAL;
50                 return -1;
51         }
52         _SysClose(dp->fd);
53         free(dp);
54         return 0;
55 }
56
57 struct dirent *readdir(DIR *dp)
58 {
59         if( !dp ) {
60                 errno = EINVAL;
61                 return NULL;
62         }
63
64         errno = EOK;
65         int rv = _SysReadDir(dp->fd, dp->tmpent.d_name);
66         if( rv != 1 ) {
67                 // TODO: Fix kernel-land API
68                 return NULL;
69         }
70         dp->tmpent.d_ino = 0;
71
72         return &dp->tmpent;
73 }
74
75 extern int      readdir_r(DIR *, struct dirent *, struct dirent **);
76 extern void     rewinddir(DIR *);
77 extern void     seekdir(DIR *, long int);
78 extern long int telldir(DIR *);

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