Fix a few more cases of bad token verification.
[mono.git] / mono / utils / mono-stdlib.c
index a84bcf84ba48c1cc669c7b3d949ae26160a2f13e..7fed904e27264f0f9fdcfc838cab3edc6f536aca 100644 (file)
@@ -14,7 +14,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include "mono-stdlib.h"
 
 #ifndef HAVE_MKSTEMP
@@ -42,14 +44,13 @@ mono_mkstemp (char *templ)
                        return -1;
                }
 
-                       
                ret = open (templ, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600);
-               if (ret == -1 && errno != EEXIST) {
-                       return -1;
-               }
-
                if (ret == -1) {
+                       if (errno != EEXIST)
+                               return -1;
                        memcpy (templ + len - 6, "XXXXXX", 6);
+               } else {
+                       break;
                }
 
        } while (count-- > 0);