Skip to content
Browse files

add a binding for realpath(2)

  • Loading branch information...
1 parent a1e19ba commit 2155c2ef7a5524eb4998c7cf01249f53117303ac @avsm committed Mar 10, 2009
Showing with 14 additions and 0 deletions.
  1. +11 −0 custom_unix_stubs.c
  2. +3 −0 utils.ml
View
11 custom_unix_stubs.c
@@ -11,6 +11,7 @@
#include <caml/unixsupport.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <dirent.h>
typedef struct dirent directory_entry;
@@ -28,3 +29,13 @@ CAMLprim value unix_read_next_dir(value vd)
return copy_string(e->d_name);
}
+CAMLprim value unix_realpath(value path)
+{
+ char buffer[PATH_MAX];
+ char *r;
+ r = realpath(String_val(path), buffer);
+ if (r == NULL) uerror("realpath", path);
+ return copy_string(buffer);
+}
+
+
View
3 utils.ml
@@ -29,6 +29,9 @@ let current_datetime () =
(* read next directory in an open dir_handle *)
external read_next_dir : Unix.dir_handle -> string = "unix_read_next_dir"
+(* wrapper for realpath(2) *)
+external realpath : string -> string = "unix_realpath"
+
exception Unable_to_make_dirs of (string * string)
let make_dirs dir =

0 comments on commit 2155c2e

Please sign in to comment.
Something went wrong with that request. Please try again.