1.0.12.33: Have foreign.test.sh create .so files under the test directory
[sbcl.git] / src / runtime / wrap.c
index 8daf076..af8b30e 100644 (file)
@@ -41,6 +41,8 @@
 
 #if defined(LISP_FEATURE_WIN32)
 #define WIN32_LEAN_AND_MEAN
+#include <fcntl.h>
+#include <errno.h>
 #endif
 
 #include "runtime.h"
@@ -243,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
  */