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
| /**
| * \file
| * stdlib replacement functions.
| *
| * Authors:
| * Gonzalo Paniagua Javier (gonzalo@novell.com)
| *
| * (C) 2006 Novell, Inc. http://www.novell.com
| *
| */
| #include <config.h>
| #include <glib.h>
| #include <errno.h>
| #include <stdio.h>
| #include <stdlib.h>
| #include <string.h>
| #include <fcntl.h>
| #ifdef HAVE_UNISTD_H
| #include <unistd.h>
| #endif
| #include "mono-stdlib.h"
|
| #ifndef HAVE_MKSTEMP
| #ifndef O_BINARY
| #define O_BINARY 0
| #endif
|
| int
| mono_mkstemp (char *templ)
| {
| int ret;
| int count = 27; /* Windows doc. */
| char *t;
| int len;
|
| len = strlen (templ);
| do {
| #if HOST_WIN32
| t = _mktemp (templ);
| #else
| t = mktemp (templ);
| #endif
|
| if (t == NULL) {
| errno = EINVAL;
| return -1;
| }
|
| if (*templ == '\0') {
| return -1;
| }
|
| #if HOST_WIN32
| ret = _open (templ, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
| #else
| ret = open(templ, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
| #endif
| if (ret == -1) {
| if (errno != EEXIST)
| return -1;
| memcpy (templ + len - 6, "XXXXXX", 6);
| } else {
| break;
| }
|
| } while (count-- > 0);
|
| return ret;
| }
| #endif
|
|