Add copyright notices and new function String.chomp
[ocaml.git] / otherlibs / unix / readlink.c
blobd2b9c4e125929da061279be0c187581cfc1ef8f9
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 <alloc.h>
18 #include <fail.h>
20 #ifdef HAS_SYMLINK
22 #include <sys/param.h>
23 #include "unixsupport.h"
25 #ifndef PATH_MAX
26 #ifdef MAXPATHLEN
27 #define PATH_MAX MAXPATHLEN
28 #else
29 #define PATH_MAX 512
30 #endif
31 #endif
33 CAMLprim value unix_readlink(value path)
35 char buffer[PATH_MAX];
36 int len;
37 len = readlink(String_val(path), buffer, sizeof(buffer) - 1);
38 if (len == -1) uerror("readlink", path);
39 buffer[len] = '\0';
40 return copy_string(buffer);
43 #else
45 CAMLprim value unix_readlink(value path)
46 { invalid_argument("readlink not implemented"); }
48 #endif