1.0.12.33: Have foreign.test.sh create .so files under the test directory
[sbcl.git] / src / runtime / wrap.c
index 1d17e9a..af8b30e 100644 (file)
 #endif
 #include <stdio.h>
 
+#if defined(LISP_FEATURE_WIN32)
+#define WIN32_LEAN_AND_MEAN
+#include <fcntl.h>
+#include <errno.h>
+#endif
+
 #include "runtime.h"
 #include "util.h"
 #include "wrap.h"
@@ -239,6 +245,30 @@ fstat_wrapper(int filedes, struct stat_wrapper *buf)
     return ret;
 }
 \f
+/* A wrapper for mkstemp(3), which seems not to exist on Windows. */
+int sb_mkstemp (char *template) {
+#ifdef LISP_FEATURE_WIN32
+  int fd;
+  char buf[MAX_PATH];
+
+  while (1) {
+    strcpy((char*)&buf, template);
+    if (_mktemp((char*)&buf)) {
+      if ((fd=open((char*)&buf, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR))!=-1) {
+        strcpy(template, (char*)&buf);
+        return (fd);
+      } else
+        if (errno != EEXIST)
+          return (-1);
+    } else
+      return (-1);
+  }
+#else
+  return(mkstemp(template));
+#endif
+}
+
+\f
 /*
  * getpwuid() stuff
  */
@@ -307,7 +337,6 @@ wrapped_environ()
 }
 
 #ifdef LISP_FEATURE_WIN32
-#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <time.h>
 /*