In Test/System.Data:
[mono-project.git] / mono / utils / mono-stdlib.c
blobf0f4bcfb77ddbae05f02ebe4662df3deea93af87
1 /*
2 * mono-stdlib.c: stdlib replacement functions.
3 *
4 * Authors:
5 * Gonzalo Paniagua Javier (gonzalo@novell.com)
7 * (C) 2006 Novell, Inc. http://www.novell.com
9 */
10 #include <config.h>
11 #include <glib.h>
12 #include <errno.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <fcntl.h>
17 #include <unistd.h>
18 #include "mono-stdlib.h"
20 #ifndef HAVE_MKSTEMP
21 #ifndef O_BINARY
22 #define O_BINARY 0
23 #endif
25 int
26 mono_mkstemp (char *templ)
28 int ret;
29 int count = 27; /* Windows doc. */
30 char *t;
31 int len;
33 len = strlen (templ);
34 do {
35 t = mktemp (templ);
36 if (t == NULL) {
37 errno = EINVAL;
38 return -1;
41 if (*templ == '\0') {
42 return -1;
45 ret = open (templ, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
46 if (ret == -1) {
47 if (errno != EEXIST)
48 return -1;
49 memcpy (templ + len - 6, "XXXXXX", 6);
50 } else {
51 break;
54 } while (count-- > 0);
56 return ret;
58 #endif