[cert-sync]: Make the new store the default and add '--legacy' for the old one.
[mono-project.git] / mono / utils / mono-stdlib.c
blob7fed904e27264f0f9fdcfc838cab3edc6f536aca
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 #ifdef HAVE_UNISTD_H
18 #include <unistd.h>
19 #endif
20 #include "mono-stdlib.h"
22 #ifndef HAVE_MKSTEMP
23 #ifndef O_BINARY
24 #define O_BINARY 0
25 #endif
27 int
28 mono_mkstemp (char *templ)
30 int ret;
31 int count = 27; /* Windows doc. */
32 char *t;
33 int len;
35 len = strlen (templ);
36 do {
37 t = mktemp (templ);
38 if (t == NULL) {
39 errno = EINVAL;
40 return -1;
43 if (*templ == '\0') {
44 return -1;
47 ret = open (templ, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
48 if (ret == -1) {
49 if (errno != EEXIST)
50 return -1;
51 memcpy (templ + len - 6, "XXXXXX", 6);
52 } else {
53 break;
56 } while (count-- > 0);
58 return ret;
60 #endif