Add copyright notices and new function String.chomp
[ocaml.git] / otherlibs / unix / readdir.c
blobfb8a67b20e5d8fe702f2b541cebb716bfbe9edee
1 /***********************************************************************/
2 /* */
3 /* Objective Caml */
4 /* */
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
6 /* */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../../LICENSE. */
11 /* */
12 /***********************************************************************/
14 /* $Id$ */
16 #include <mlvalues.h>
17 #include <fail.h>
18 #include <alloc.h>
19 #include "unixsupport.h"
20 #include <errno.h>
21 #include <sys/types.h>
22 #ifdef HAS_DIRENT
23 #include <dirent.h>
24 typedef struct dirent directory_entry;
25 #else
26 #include <sys/dir.h>
27 typedef struct direct directory_entry;
28 #endif
30 CAMLprim value unix_readdir(value vd)
32 DIR * d;
33 directory_entry * e;
34 d = DIR_Val(vd);
35 if (d == (DIR *) NULL) unix_error(EBADF, "readdir", Nothing);
36 e = readdir((DIR *) d);
37 if (e == (directory_entry *) NULL) raise_end_of_file();
38 return copy_string(e->d_name);