From: Michael Jeanson Date: Fri, 9 Oct 2015 16:15:12 +0000 (-0400) Subject: Port: Add compat for mkdtemp X-Git-Tag: v1.3.0~16 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=559455a97078bcf4040a95f611a33b7fd569402b Port: Add compat for mkdtemp Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/configure.ac b/configure.ac index 0edc2a3c..9757663f 100644 --- a/configure.ac +++ b/configure.ac @@ -81,7 +81,7 @@ AC_TYPE_SIZE_T # Checks for library functions. AC_FUNC_MALLOC AC_FUNC_MMAP -AC_CHECK_FUNCS([gettimeofday munmap strtoul strndup strnlen]) +AC_CHECK_FUNCS([gettimeofday munmap strtoul strndup strnlen mkdtemp]) # Check for MinGW32. MINGW32=no diff --git a/include/Makefile.am b/include/Makefile.am index d183dbe0..513194ef 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -55,5 +55,6 @@ noinst_HEADERS = \ babeltrace/compat/limits.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 index 00000000..57f942d9 --- /dev/null +++ b/include/babeltrace/compat/stdlib.h @@ -0,0 +1,60 @@ +#ifndef _BABELTRACE_COMPAT_STDLIB_H +#define _BABELTRACE_COMPAT_STDLIB_H + +/* + * babeltrace/compat/stdlib.h + * + * Copyright (C) 2015 Michael Jeanson + * + * 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 +#include + +#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 */ diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index cef54123..ce656b31 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -728,7 +728,7 @@ int main(int argc, char **argv) plan_no_plan(); - if (!mkdtemp(trace_path)) { + if (!bt_mkdtemp(trace_path)) { perror("# perror"); }