undo change in mini.c
[mono-project.git] / mono / utils / mono-stdlib.c
blob232f83708d6913c030cde89184c1f2cf5b11bf7a
1 /**
2 * \file
3 * stdlib replacement functions.
4 *
5 * Authors:
6 * Gonzalo Paniagua Javier (gonzalo@novell.com)
8 * (C) 2006 Novell, Inc. http://www.novell.com
11 #include <config.h>
12 #include <glib.h>
13 #include <errno.h>
14 #include <mono/utils/mono-errno.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <fcntl.h>
19 #ifdef HAVE_UNISTD_H
20 #include <unistd.h>
21 #endif
22 #include "mono-stdlib.h"
24 #ifndef HAVE_MKSTEMP
25 #ifndef O_BINARY
26 #define O_BINARY 0
27 #endif
29 int
30 mono_mkstemp (char *templ)
32 int ret;
33 int count = 27; /* Windows doc. */
34 char *t;
35 int len;
37 len = strlen (templ);
38 do {
39 t = g_mktemp (templ);
41 if (t == NULL) {
42 mono_set_errno (EINVAL);
43 return -1;
46 if (*templ == '\0') {
47 return -1;
50 ret = g_open (templ, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
51 if (ret == -1) {
52 if (errno != EEXIST)
53 return -1;
54 memcpy (templ + len - 6, "XXXXXX", 6);
55 } else {
56 break;
59 } while (count-- > 0);
61 return ret;
63 #endif