X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=support%2Fdirent.c;h=bc1b3e238e16730ad5113258b05eb174ec214b6f;hb=ab0b591ca59d99a2370bf9f579b091c5edf09ae5;hp=4be44d8a1de7807442ce00d2487817e3760019ae;hpb=04cf475e40fbe9e876eb5abb617332b3f3361e43;p=mono.git diff --git a/support/dirent.c b/support/dirent.c index 4be44d8a1de..bc1b3e238e1 100644 --- a/support/dirent.c +++ b/support/dirent.c @@ -4,60 +4,72 @@ * Authors: * Jonathan Pryor (jonpryor@vt.edu) * - * Copyright (C) 2004 Jonathan Pryor + * Copyright (C) 2004-2005 Jonathan Pryor */ #include #include #include #include +#include +#include +#include "map.h" #include "mph.h" -G_BEGIN_DECLS +#if defined (PATH_MAX) && defined (NAME_MAX) + #define MPH_PATH_MAX MAX(PATH_MAX, NAME_MAX) +#elif defined (PATH_MAX) + #define MPH_PATH_MAX PATH_MAX +#elif defined (NAME_MAX) + #define MPH_PATH_MAX NAME_MAX +#else /* !defined PATH_MAX && !defined NAME_MAX */ + #define MPH_PATH_MAX 2048 +#endif -struct Mono_Posix_Syscall__Dirent { - /* ino_t */ mph_ino_t d_ino; - /* off_t */ mph_off_t d_off; - /* ushort */ unsigned short d_reclen; - /* byte */ unsigned char d_type; - /* string */ char *d_name; -}; +G_BEGIN_DECLS +#if HAVE_SEEKDIR gint32 -Mono_Posix_Syscall_seekdir (DIR *dir, mph_off_t offset) +Mono_Posix_Syscall_seekdir (void *dir, mph_off_t offset) { mph_return_if_off_t_overflow (offset); - errno = 0; - - seekdir (dir, (off_t) offset); + seekdir ((DIR*) dir, (off_t) offset); - return errno != 0; + return 0; } +#endif /* def HAVE_SEEKDIR */ +#if HAVE_TELLDIR mph_off_t -Mono_Posix_Syscall_telldir (DIR *dir) +Mono_Posix_Syscall_telldir (void *dir) { - return telldir (dir); + return telldir ((DIR*) dir); } +#endif /* def HAVE_TELLDIR */ static void copy_dirent (struct Mono_Posix_Syscall__Dirent *to, struct dirent *from) { + memset (to, 0, sizeof(*to)); + to->d_ino = from->d_ino; -#ifdef MPH_ON_BSD - to->d_off = 0; -#else + to->d_name = strdup (from->d_name); + +#ifdef HAVE_STRUCT_DIRENT_D_OFF to->d_off = from->d_off; #endif +#ifdef HAVE_STRUCT_DIRENT_D_RECLEN to->d_reclen = from->d_reclen; +#endif +#ifdef HAVE_STRUCT_DIRENT_D_TYPE to->d_type = from->d_type; - to->d_name = strdup (from->d_name); +#endif } gint32 -Mono_Posix_Syscall_readdir (DIR *dirp, struct Mono_Posix_Syscall__Dirent *entry) +Mono_Posix_Syscall_readdir (void *dirp, struct Mono_Posix_Syscall__Dirent *entry) { struct dirent *d; @@ -66,6 +78,7 @@ Mono_Posix_Syscall_readdir (DIR *dirp, struct Mono_Posix_Syscall__Dirent *entry) return -1; } + errno = 0; d = readdir (dirp); if (d == NULL) { @@ -78,20 +91,29 @@ Mono_Posix_Syscall_readdir (DIR *dirp, struct Mono_Posix_Syscall__Dirent *entry) } gint32 -Mono_Posix_Syscall_readdir_r (DIR *dirp, struct Mono_Posix_Syscall__Dirent *entry, void **result) +Mono_Posix_Syscall_readdir_r (void *dirp, struct Mono_Posix_Syscall__Dirent *entry, void **result) { - struct dirent _entry; + struct dirent *_entry = malloc (sizeof (struct dirent) + MPH_PATH_MAX + 1); int r; - r = readdir_r (dirp, &_entry, (struct dirent**) result); + r = readdir_r (dirp, _entry, (struct dirent**) result); - if (r == 0 && result != NULL) { - copy_dirent (entry, &_entry); + if (r == 0 && *result != NULL) { + copy_dirent (entry, _entry); } + free (_entry); + return r; } +int +Mono_Posix_Syscall_rewinddir (void* dir) +{ + rewinddir (dir); + return 0; +} + G_END_DECLS /*