diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2003-03-03 17:16:15 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2003-03-03 17:16:15 +0000 |
commit | 859efb84a8160e694b35a90fd60fcb3606ca8ef9 (patch) | |
tree | d09e19f7742c3914e33e92e56451a5021ba1740a /byterun/unix.c | |
parent | dc64ea8cc7ed73b7b67f8554f29b95575883b81b (diff) |
Ajout de Sys.readdir
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5415 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/unix.c')
-rw-r--r-- | byterun/unix.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/byterun/unix.c b/byterun/unix.c index 65c960a3b..c47544217 100644 --- a/byterun/unix.c +++ b/byterun/unix.c @@ -32,6 +32,11 @@ #ifdef HAS_UNISTD #include <unistd.h> #endif +#ifdef HAS_DIRENT +#include <dirent.h> +#else +#include <sys/dir.h> +#endif #include "memory.h" #include "misc.h" #include "osdeps.h" @@ -322,6 +327,34 @@ void aligned_munmap (char * addr, asize_t size) #endif +/* Add to [contents] the (short) names of the files contained in + the directory named [dirname]. No entries are added for [.] and [..]. + Return 0 on success, -1 on error; set errno in the case of error. */ + +int caml_read_directory(char * dirname, struct ext_table * contents) +{ + DIR * d; +#ifdef HAS_DIRENT + struct dirent * e; +#else + struct direct * e; +#endif + char * p; + + d = opendir(dirname); + if (d == NULL) return -1; + while (1) { + e = readdir(d); + if (e == NULL) break; + if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0) continue; + p = stat_alloc(strlen(e->d_name) + 1); + strcpy(p, e->d_name); + ext_table_add(contents, p); + } + closedir(d); + return 0; +} + /* Recover executable name from /proc/self/exe if possible */ #ifdef __linux__ |