a06844d559096dbaf157e7aa6d9e40ac1ef5eae2
[babeltrace.git] / src / compat / stdlib.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
5 */
6
7 #ifndef _BABELTRACE_COMPAT_STDLIB_H
8 #define _BABELTRACE_COMPAT_STDLIB_H
9
10 /*
11 * This compat wrapper can be removed and replaced by g_mkdtemp() when we bump
12 * the requirement on glib to version 2.30.
13 */
14
15 #include <unistd.h>
16 #include <stdlib.h>
17 #include <sys/stat.h>
18 #include <glib.h>
19
20 #ifdef HAVE_MKDTEMP
21
22 static inline
23 char *bt_mkdtemp(char *template)
24 {
25 return mkdtemp(template);
26 }
27
28 #elif GLIB_CHECK_VERSION(2,30,0)
29
30 #include <glib/gstdio.h>
31 static inline
32 char *bt_mkdtemp(char *template)
33 {
34 return g_mkdtemp(template);
35 }
36
37 #else
38
39 static inline
40 char *bt_mkdtemp(char *template)
41 {
42 char *ret;
43
44 ret = mktemp(template);
45 if (!ret) {
46 goto end;
47 }
48
49 if(mkdir(template, 0700)) {
50 ret = NULL;
51 goto end;
52 }
53
54 ret = template;
55 end:
56 return ret;
57 }
58
59 #endif
60
61 #endif /* _BABELTRACE_COMPAT_STDLIB_H */
This page took 0.030675 seconds and 4 git commands to generate.