Port: Add compat for mkdtemp
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 9 Oct 2015 16:15:12 +0000 (12:15 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 14 Oct 2015 17:29:46 +0000 (13:29 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
include/Makefile.am
include/babeltrace/compat/stdlib.h [new file with mode: 0644]
tests/lib/test_ctf_writer.c

index e7ac7936c2a604cc481ad12c04edf9f717d594e6..ed4b38b22cb18d9f4a849fa623cfe13b6cf1e0dc 100644 (file)
@@ -95,7 +95,7 @@ AC_CHECK_FUNCS([ \
        gettimeofday munmap strtoul ftruncate gethostbyname \
        localtime_r memset mkdir rmdir setenv socket \
        strchr strdup strerror strndup strrchr strtoull tzset \
-       strnlen \
+       strnlen mkdtemp \
 ])
 
 # Check for MinGW32.
index 30c4cdff299540272fd5c8ab15a773e875dd6d58..981ad91e48319ce02b0e02412148a7bc04ad0b77 100644 (file)
@@ -74,5 +74,6 @@ noinst_HEADERS = \
        babeltrace/compat/glib.h \
        babeltrace/compat/send.h \
        babeltrace/compat/fcntl.h \
+       babeltrace/compat/stdlib.h \
        babeltrace/endian.h \
        babeltrace/mmap-align.h
diff --git a/include/babeltrace/compat/stdlib.h b/include/babeltrace/compat/stdlib.h
new file mode 100644 (file)
index 0000000..57f942d
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef _BABELTRACE_COMPAT_STDLIB_H
+#define _BABELTRACE_COMPAT_STDLIB_H
+
+/*
+ * babeltrace/compat/stdlib.h
+ *
+ * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_MKDTEMP
+static inline
+char *bt_mkdtemp(char *template)
+{
+       return mkdtemp(template);
+}
+#else
+static inline
+char *bt_mkdtemp(char *template)
+{
+       char *ret;
+
+       ret = mktemp(template);
+       if (!ret) {
+               goto end;
+       }
+
+       if(mkdir(template, 0700)) {
+               ret = NULL;
+               goto end;
+       }
+
+       ret = template;
+end:
+       return ret;
+}
+#endif
+
+
+#endif /* _BABELTRACE_COMPAT_STDLIB_H */
index 6d5b42db79f28e51cc98eb7a6ab4c5d64b2b3d88..a5b22d23581e2ec3deeeb916d401a69cebd73636 100644 (file)
@@ -31,7 +31,7 @@
 #include <babeltrace/ctf/events.h>
 #include <babeltrace/values.h>
 #include <unistd.h>
-#include <stdlib.h>
+#include <babeltrace/compat/stdlib.h>
 #include <stdio.h>
 #include <sys/utsname.h>
 #include <babeltrace/compat/limits.h>
@@ -2690,7 +2690,7 @@ int main(int argc, char **argv)
 
        plan_no_plan();
 
-       if (!mkdtemp(trace_path)) {
+       if (!bt_mkdtemp(trace_path)) {
                perror("# perror");
        }
 
This page took 0.029616 seconds and 4 git commands to generate.