]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml/contrib/otherlibs/unix/getcwd.c
Update
[l4.git] / l4 / pkg / ocaml / ocaml / contrib / otherlibs / unix / getcwd.c
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 /***********************************************************************/
13
14 /* $Id: getcwd.c 6824 2005-03-24 17:20:54Z doligez $ */
15
16 #include <mlvalues.h>
17 #include <alloc.h>
18 #include <fail.h>
19 #include "unixsupport.h"
20
21 #if !defined (_WIN32) && !macintosh
22 #include <sys/param.h>
23 #endif
24
25 #ifndef PATH_MAX
26 #ifdef MAXPATHLEN
27 #define PATH_MAX MAXPATHLEN
28 #else
29 #define PATH_MAX 512
30 #endif
31 #endif
32
33 #ifdef HAS_GETCWD
34
35 CAMLprim value unix_getcwd(value unit)
36 {
37   char buff[PATH_MAX];
38   if (getcwd(buff, sizeof(buff)) == 0) uerror("getcwd", Nothing);
39   return copy_string(buff);
40 }
41
42 #else
43 #ifdef HAS_GETWD
44
45 CAMLprim value unix_getcwd(value unit)
46 {
47   char buff[PATH_MAX];
48   if (getwd(buff) == 0) uerror("getcwd", copy_string(buff));
49   return copy_string(buff);
50 }
51
52 #else
53
54 CAMLprim value unix_getcwd(value unit)
55 { invalid_argument("getcwd not implemented"); }
56
57 #endif
58 #endif