-
Notifications
You must be signed in to change notification settings - Fork 19
/
mktemp.c
73 lines (59 loc) · 1.54 KB
/
mktemp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#define EXTUNIX_WANT_MKDTEMP
#define EXTUNIX_WANT_MKSTEMPS
#define EXTUNIX_WANT_MKOSTEMPS
#include "config.h"
#if defined(EXTUNIX_HAVE_MKDTEMP)
CAMLprim value caml_extunix_mkdtemp(value v_path)
{
CAMLparam1(v_path);
char* path = caml_stat_strdup(String_val(v_path));
char *ret;
caml_enter_blocking_section();
ret = mkdtemp(path);
caml_leave_blocking_section();
if (NULL == ret)
{
caml_stat_free(path);
uerror("mkdtemp", v_path);
}
v_path = caml_copy_string(ret);
caml_stat_free(path);
CAMLreturn(v_path);
}
#endif
#if defined(EXTUNIX_HAVE_MKSTEMPS)
CAMLprim value caml_extunix_internal_mkstemps(value v_template, value v_suffixlen)
{
CAMLparam2(v_template, v_suffixlen);
unsigned char *template = Bytes_val(v_template);
int suffixlen = Int_val(v_suffixlen);
int ret;
ret = mkstemps((char *)template, suffixlen);
if (ret == -1)
{
uerror("mkstemps", v_template);
}
CAMLreturn(Val_int(ret));
}
#endif
#if defined(EXTUNIX_HAVE_MKOSTEMPS)
/* FIXME: also in atfile.c, move to common file */
#include <fcntl.h>
#ifndef O_CLOEXEC
# define O_CLOEXEC 0
#endif
CAMLprim value caml_extunix_internal_mkostemps(value v_template, value v_suffixlen, value v_flags)
{
CAMLparam3(v_template, v_suffixlen, v_flags);
unsigned char *template = Bytes_val(v_template);
int flags = extunix_open_flags(v_flags) | O_CLOEXEC;
int suffixlen = Int_val(v_suffixlen);
int ret;
ret = mkostemps((char*) template, suffixlen, flags);
if (ret == -1)
{
uerror("mkostemps", v_template);
}
CAMLreturn(Val_int(ret));
}
#endif