mllib: Add a binding for realpath(3).

This is a copy of the supermin binding:

https://github.com/libguestfs/supermin/tree/master/src realpath*
This commit is contained in:
Richard W.M. Jones
2017-03-10 16:51:36 +00:00
parent e48c17b10d
commit 5da5718084
3 changed files with 26 additions and 0 deletions

View File

@@ -57,6 +57,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. */
@@ -195,6 +196,22 @@ guestfs_int_mllib_mkdtemp (value val_pattern)
CAMLreturn (rv);
}
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)
{

View File

@@ -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"

View File

@@ -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