2 * <dirent.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2005 Jonathan Pryor
20 #if defined (PATH_MAX) && defined (NAME_MAX)
21 #define MPH_PATH_MAX MAX(PATH_MAX, NAME_MAX)
22 #elif defined (PATH_MAX)
23 #define MPH_PATH_MAX PATH_MAX
24 #elif defined (NAME_MAX)
25 #define MPH_PATH_MAX NAME_MAX
26 #else /* !defined PATH_MAX && !defined NAME_MAX */
27 #define MPH_PATH_MAX 2048
34 Mono_Posix_Syscall_seekdir (void *dir
, mph_off_t offset
)
36 mph_return_if_off_t_overflow (offset
);
38 seekdir ((DIR*) dir
, (off_t
) offset
);
42 #endif /* def HAVE_SEEKDIR */
46 Mono_Posix_Syscall_telldir (void *dir
)
48 return telldir ((DIR*) dir
);
50 #endif /* def HAVE_TELLDIR */
53 copy_dirent (struct Mono_Posix_Syscall__Dirent
*to
, struct dirent
*from
)
55 memset (to
, 0, sizeof(*to
));
57 to
->d_ino
= from
->d_ino
;
58 to
->d_name
= strdup (from
->d_name
);
60 #ifdef HAVE_STRUCT_DIRENT_D_OFF
61 to
->d_off
= from
->d_off
;
63 #ifdef HAVE_STRUCT_DIRENT_D_RECLEN
64 to
->d_reclen
= from
->d_reclen
;
66 #ifdef HAVE_STRUCT_DIRENT_D_TYPE
67 to
->d_type
= from
->d_type
;
72 Mono_Posix_Syscall_readdir (void *dirp
, struct Mono_Posix_Syscall__Dirent
*entry
)
88 copy_dirent (entry
, d
);
94 Mono_Posix_Syscall_readdir_r (void *dirp
, struct Mono_Posix_Syscall__Dirent
*entry
, void **result
)
96 struct dirent
*_entry
= malloc (sizeof (struct dirent
) + MPH_PATH_MAX
+ 1);
99 r
= readdir_r (dirp
, _entry
, (struct dirent
**) result
);
101 if (r
== 0 && *result
!= NULL
) {
102 copy_dirent (entry
, _entry
);
111 Mono_Posix_Syscall_rewinddir (void* dir
)