Move to kernel style SPDX license identifiers
[babeltrace.git] / src / compat / stdlib.h
CommitLineData
2bb37f06 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
2bb37f06 3 *
0235b0db 4 * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
2bb37f06
MJ
5 */
6
0235b0db
MJ
7#ifndef _BABELTRACE_COMPAT_STDLIB_H
8#define _BABELTRACE_COMPAT_STDLIB_H
9
9679ac43
MJ
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
b8d6e1fc 15#include <unistd.h>
2bb37f06
MJ
16#include <stdlib.h>
17#include <sys/stat.h>
9679ac43 18#include <glib.h>
2bb37f06
MJ
19
20#ifdef HAVE_MKDTEMP
9679ac43 21
2bb37f06
MJ
22static inline
23char *bt_mkdtemp(char *template)
24{
25 return mkdtemp(template);
26}
9679ac43
MJ
27
28#elif GLIB_CHECK_VERSION(2,30,0)
29
30#include <glib/gstdio.h>
31static inline
32char *bt_mkdtemp(char *template)
33{
34 return g_mkdtemp(template);
35}
36
2bb37f06 37#else
9679ac43 38
2bb37f06
MJ
39static inline
40char *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;
55end:
56 return ret;
57}
2bb37f06 58
9679ac43 59#endif
2bb37f06
MJ
60
61#endif /* _BABELTRACE_COMPAT_STDLIB_H */
This page took 0.068556 seconds and 4 git commands to generate.