[Pkg-libvirt-commits] [libguestfs] 21/54: mllib: add a binding for mkdtemp
Hilko Bengen
bengen at moszumanska.debian.org
Sun Mar 9 11:21:15 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch debian
in repository libguestfs.
commit a0ae73d16c6ab0c619915a0329e45a438b465ac3
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.
(cherry picked from commit c79c62a3b0f007d5952a75b1cae3f793bd63132f)
---
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 8c8d508..55cfa84 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 \
@@ -70,6 +73,7 @@ OBJECTS = \
progress-c.o \
uri-c.o \
crypt-c.o \
+ mkdtemp-c.o \
config.cmx \
libdir.cmx \
common_gettext.cmx \
@@ -85,6 +89,7 @@ OBJECTS = \
uRI.cmx \
crypt.cmx \
password.cmx
+ mkdtemp.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 56d192e..d8edd99 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -227,6 +227,7 @@ java/com_redhat_et_libguestfs_GuestFS.c
lua/lua-guestfs.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 eff4de4..04b88be 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -14,6 +14,7 @@ mllib/firstboot.ml
mllib/fsync.ml
mllib/hostname.ml
mllib/libdir.ml
+mllib/mkdtemp.ml
mllib/password.ml
mllib/perl_edit.ml
mllib/progress.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