This is a copy of the supermin binding:
https://github.com/libguestfs/supermin/tree/master/src realpath*
---
mllib/unix_utils-c.c | 18 ++++++++++++++++++
mllib/unix_utils.ml | 4 ++++
mllib/unix_utils.mli | 5 +++++
3 files changed, 27 insertions(+)
diff --git a/mllib/unix_utils-c.c b/mllib/unix_utils-c.c
index f5aaaf6..7e90541 100644
--- a/mllib/unix_utils-c.c
+++ b/mllib/unix_utils-c.c
@@ -25,6 +25,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <fnmatch.h>
+#include <limits.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/statvfs.h>
@@ -57,6 +58,7 @@ extern value guestfs_int_mllib_fnmatch (value patternv, value strv,
value flagsv
extern value guestfs_int_mllib_sync (value unitv);
extern value guestfs_int_mllib_fsync_file (value filenamev);
extern value guestfs_int_mllib_mkdtemp (value val_pattern);
+extern value guestfs_int_mllib_realpath (value pathv);
extern value guestfs_int_mllib_statvfs_free_space (value pathv);
/* NB: This is a "noalloc" call. */
@@ -196,6 +198,22 @@ guestfs_int_mllib_mkdtemp (value val_pattern)
}
value
+guestfs_int_mllib_realpath (value pathv)
+{
+ CAMLparam1 (pathv);
+ CAMLlocal1 (rv);
+ char *r;
+
+ r = realpath (String_val (pathv), NULL);
+ if (r == NULL)
+ unix_error (errno, (char *) "realpath", pathv);
+
+ rv = caml_copy_string (r);
+ free (r);
+ CAMLreturn (rv);
+}
+
+value
guestfs_int_mllib_statvfs_free_space (value pathv)
{
CAMLparam1 (pathv);
diff --git a/mllib/unix_utils.ml b/mllib/unix_utils.ml
index 66b6e4f..8ac3683 100644
--- a/mllib/unix_utils.ml
+++ b/mllib/unix_utils.ml
@@ -56,6 +56,10 @@ module Mkdtemp = struct
mkdtemp (Filename.concat base_dir (prefix ^ "XXXXXX" ^ suffix))
end
+module Realpath = struct
+ external realpath : string -> string = "guestfs_int_mllib_realpath"
+end
+
module StatVFS = struct
external free_space : string -> int64 =
"guestfs_int_mllib_statvfs_free_space"
diff --git a/mllib/unix_utils.mli b/mllib/unix_utils.mli
index 0a4c1b3..4795cb3 100644
--- a/mllib/unix_utils.mli
+++ b/mllib/unix_utils.mli
@@ -88,6 +88,11 @@ module Mkdtemp : sig
[Filename.temp_dir_name] is used. *)
end
+module Realpath : sig
+ val realpath : string -> string
+ (** [realpath(3)] returns the canonicalized absolute pathname. *)
+end
+
module StatVFS : sig
val free_space : string -> int64
(** [free_space path] returns the free space available on the
--
2.9.3