Move to kernel style SPDX license identifiers
[babeltrace.git] / src / compat / stdlib.h
... / ...
CommitLineData
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
22static inline
23char *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>
31static inline
32char *bt_mkdtemp(char *template)
33{
34 return g_mkdtemp(template);
35}
36
37#else
38
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}
58
59#endif
60
61#endif /* _BABELTRACE_COMPAT_STDLIB_H */
This page took 0.023283 seconds and 4 git commands to generate.