[Pkg-libvirt-commits] [libguestfs] 12/19: mllib: add a binding for mkdtemp

Hilko Bengen bengen at moszumanska.debian.org
Wed Feb 26 08:45:15 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit c79c62a3b0f007d5952a75b1cae3f793bd63132f
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Fri Feb 21 14:34:36 2014 +0100

    mllib: add a binding for mkdtemp
    
    It seems OCaml has no way to safely create a temporary directory, so add
    a new binding to C's mkdtemp which does that.
---
 mllib/Makefile.am |  5 +++++
 mllib/mkdtemp-c.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 mllib/mkdtemp.ml  | 19 +++++++++++++++++++
 mllib/mkdtemp.mli | 20 ++++++++++++++++++++
 po/POTFILES       |  1 +
 po/POTFILES-ml    |  1 +
 6 files changed, 102 insertions(+)

diff --git a/mllib/Makefile.am b/mllib/Makefile.am
index 67f0a0a..920928d 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -36,6 +36,9 @@ SOURCES = \
 	fsync-c.c \
 	fsync.mli \
 	fsync.ml \
+	mkdtemp.mli \
+	mkdtemp.ml \
+	mkdtemp-c.c \
 	hostname.mli \
 	hostname.ml \
 	password.mli \
@@ -74,6 +77,7 @@ OBJECTS = \
 	progress-c.o \
 	uri-c.o \
 	crypt-c.o \
+	mkdtemp-c.o \
 	config.cmx \
 	libdir.cmx \
 	common_gettext.cmx \
@@ -90,6 +94,7 @@ OBJECTS = \
 	uRI.cmx \
 	crypt.cmx \
 	password.cmx \
+	mkdtemp.cmx \
 	planner.cmx
 
 noinst_SCRIPTS = dummy
diff --git a/mllib/mkdtemp-c.c b/mllib/mkdtemp-c.c
new file mode 100644
index 0000000..2284e3a
--- /dev/null
+++ b/mllib/mkdtemp-c.c
@@ -0,0 +1,56 @@
+/* virt-builder
+ * Copyright (C) 2014 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include <caml/alloc.h>
+#include <caml/fail.h>
+#include <caml/memory.h>
+#include <caml/mlvalues.h>
+
+#ifdef HAVE_CAML_UNIXSUPPORT_H
+#include <caml/unixsupport.h>
+#else
+#define Nothing ((value) 0)
+extern void unix_error (int errcode, char * cmdname, value arg) Noreturn;
+#endif
+
+value
+virt_builder_mkdtemp (value val_pattern)
+{
+  CAMLparam1 (val_pattern);
+  CAMLlocal1 (rv);
+  char *pattern, *ret;
+
+  pattern = strdup (String_val (val_pattern));
+  if (pattern == NULL)
+    unix_error (errno, (char *) "strdup", val_pattern);
+
+  ret = mkdtemp (pattern);
+  if (ret == NULL)
+    unix_error (errno, (char *) "mkdtemp", val_pattern);
+
+  rv = caml_copy_string (ret);
+  free (pattern);
+
+  CAMLreturn (rv);
+}
diff --git a/mllib/mkdtemp.ml b/mllib/mkdtemp.ml
new file mode 100644
index 0000000..2e64862
--- /dev/null
+++ b/mllib/mkdtemp.ml
@@ -0,0 +1,19 @@
+(* virt-builder
+ * Copyright (C) 2014 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+external mkdtemp : string -> string = "virt_builder_mkdtemp"
diff --git a/mllib/mkdtemp.mli b/mllib/mkdtemp.mli
new file mode 100644
index 0000000..674e6f2
--- /dev/null
+++ b/mllib/mkdtemp.mli
@@ -0,0 +1,20 @@
+(* virt-builder
+ * Copyright (C) 2014 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+val mkdtemp : string -> string
+(** [mkdtemp pattern] Tiny wrapper to the C [mkdtemp]. *)
diff --git a/po/POTFILES b/po/POTFILES
index c0d20f0..5b2ec57 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -239,6 +239,7 @@ lua/lua-guestfs.c
 make-fs/make-fs.c
 mllib/crypt-c.c
 mllib/fsync-c.c
+mllib/mkdtemp-c.c
 mllib/progress-c.c
 mllib/tty-c.c
 mllib/uri-c.c
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 301fe81..d3c8918 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -17,6 +17,7 @@ mllib/firstboot.ml
 mllib/fsync.ml
 mllib/hostname.ml
 mllib/libdir.ml
+mllib/mkdtemp.ml
 mllib/password.ml
 mllib/perl_edit.ml
 mllib/planner.ml

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list