More testing. This time on the groupbox, which acts as a
[mono-project.git] / support / dirent.c
blob6fb49902d0beef6f1284d781c9e68523fd3cbd33
1 /*
2 * <dirent.h> wrapper functions.
4 * Authors:
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2005 Jonathan Pryor
8 */
10 #include <dirent.h>
11 #include <errno.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include <unistd.h>
16 #include "mph.h"
18 G_BEGIN_DECLS
20 struct Mono_Posix_Syscall__Dirent {
21 /* ino_t */ mph_ino_t d_ino;
22 /* off_t */ mph_off_t d_off;
23 /* ushort */ unsigned short d_reclen;
24 /* byte */ unsigned char d_type;
25 /* string */ char *d_name;
28 gint32
29 Mono_Posix_Syscall_seekdir (void *dir, mph_off_t offset)
31 mph_return_if_off_t_overflow (offset);
33 errno = 0;
35 seekdir ((DIR*) dir, (off_t) offset);
37 return errno != 0;
40 mph_off_t
41 Mono_Posix_Syscall_telldir (void *dir)
43 return telldir ((DIR*) dir);
46 static void
47 copy_dirent (struct Mono_Posix_Syscall__Dirent *to, struct dirent *from)
49 memset (to, 0, sizeof(*to));
51 to->d_ino = from->d_ino;
52 to->d_name = strdup (from->d_name);
54 #ifdef HAVE_STRUCT_DIRENT_D_OFF
55 to->d_off = from->d_off;
56 #endif
57 #ifdef HAVE_STRUCT_DIRENT_D_RECLEN
58 to->d_reclen = from->d_reclen;
59 #endif
60 #ifdef HAVE_STRUCT_DIRENT_D_TYPE
61 to->d_type = from->d_type;
62 #endif
65 gint32
66 Mono_Posix_Syscall_readdir (void *dirp, struct Mono_Posix_Syscall__Dirent *entry)
68 struct dirent *d;
70 if (entry == NULL) {
71 errno = EFAULT;
72 return -1;
75 d = readdir (dirp);
77 if (d == NULL) {
78 return -1;
81 copy_dirent (entry, d);
83 return 0;
86 gint32
87 Mono_Posix_Syscall_readdir_r (void *dirp, struct Mono_Posix_Syscall__Dirent *entry, void **result)
89 struct dirent _entry;
90 int r;
92 r = readdir_r (dirp, &_entry, (struct dirent**) result);
94 if (r == 0 && result != NULL) {
95 copy_dirent (entry, &_entry);
98 return r;
102 Mono_Posix_Syscall_rewinddir (void* dir)
104 errno = 0;
105 rewinddir (dir);
106 return errno == 0 ? 0 : -1;
109 G_END_DECLS
112 * vim: noexpandtab