[interp] Remove unreachable code (#12411)
[mono-project.git] / mono / utils / mono-stdlib.c
blobd055b04a6d8522b8513b9030ee9b3ddcb9070ded
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 <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <fcntl.h>
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif
21 #include "mono-stdlib.h"
23 #ifndef HAVE_MKSTEMP
24 #ifndef O_BINARY
25 #define O_BINARY 0
26 #endif
28 int
29 mono_mkstemp (char *templ)
31 int ret;
32 int count = 27; /* Windows doc. */
33 char *t;
34 int len;
36 len = strlen (templ);
37 do {
38 t = g_mktemp (templ);
40 if (t == NULL) {
41 errno = EINVAL;
42 return -1;
45 if (*templ == '\0') {
46 return -1;
49 ret = g_open (templ, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
50 if (ret == -1) {
51 if (errno != EEXIST)
52 return -1;
53 memcpy (templ + len - 6, "XXXXXX", 6);
54 } else {
55 break;
58 } while (count-- > 0);
60 return ret;
62 #endif