- PreferredHeight is a little different than i thought.
[mono-project.git] / support / dirent.c
blobae13bf2ea529bd4a9dfbe053221d5c2712b5a75b
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 "map.h"
17 #include "mph.h"
19 G_BEGIN_DECLS
21 gint32
22 Mono_Posix_Syscall_seekdir (void *dir, mph_off_t offset)
24 mph_return_if_off_t_overflow (offset);
26 errno = 0;
28 seekdir ((DIR*) dir, (off_t) offset);
30 return errno != 0;
33 mph_off_t
34 Mono_Posix_Syscall_telldir (void *dir)
36 return telldir ((DIR*) dir);
39 static void
40 copy_dirent (struct Mono_Posix_Syscall__Dirent *to, struct dirent *from)
42 memset (to, 0, sizeof(*to));
44 to->d_ino = from->d_ino;
45 to->d_name = strdup (from->d_name);
47 #ifdef HAVE_STRUCT_DIRENT_D_OFF
48 to->d_off = from->d_off;
49 #endif
50 #ifdef HAVE_STRUCT_DIRENT_D_RECLEN
51 to->d_reclen = from->d_reclen;
52 #endif
53 #ifdef HAVE_STRUCT_DIRENT_D_TYPE
54 to->d_type = from->d_type;
55 #endif
58 gint32
59 Mono_Posix_Syscall_readdir (void *dirp, struct Mono_Posix_Syscall__Dirent *entry)
61 struct dirent *d;
63 if (entry == NULL) {
64 errno = EFAULT;
65 return -1;
68 d = readdir (dirp);
70 if (d == NULL) {
71 return -1;
74 copy_dirent (entry, d);
76 return 0;
79 gint32
80 Mono_Posix_Syscall_readdir_r (void *dirp, struct Mono_Posix_Syscall__Dirent *entry, void **result)
82 struct dirent _entry;
83 int r;
85 r = readdir_r (dirp, &_entry, (struct dirent**) result);
87 if (r == 0 && result != NULL) {
88 copy_dirent (entry, &_entry);
91 return r;
94 int
95 Mono_Posix_Syscall_rewinddir (void* dir)
97 errno = 0;
98 rewinddir (dir);
99 return errno == 0 ? 0 : -1;
102 G_END_DECLS
105 * vim: noexpandtab