#include <string.h>
#include <ctype.h>
#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
#ifndef LISP_FEATURE_WIN32
#include <pwd.h>
#include <sys/wait.h>
#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"
#endif
\f
/*
+ * realpath(3), including a wrapper for Windows.
+ */
+char * sb_realpath (char *path)
+{
+#ifndef LISP_FEATURE_WIN32
+ char *ret;
+ int errnum;
+
+ if ((ret = calloc(PATH_MAX, sizeof(char))) == NULL)
+ return NULL;
+ if (realpath(path, ret) == NULL) {
+ errnum = errno;
+ free(ret);
+ errno = errnum;
+ return NULL;
+ }
+ return(ret);
+#else
+ char *ret;
+ char *cp;
+ int errnum;
+
+ if ((ret = calloc(MAX_PATH, sizeof(char))) == NULL)
+ return NULL;
+ if (GetFullPathName(path, MAX_PATH, ret, cp) == 0) {
+ errnum = errno;
+ free(ret);
+ errno = errnum;
+ return NULL;
+ }
+ return(ret);
+#endif
+}
+\f
+/*
* stat(2) stuff
*/
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
*/
}
#ifdef LISP_FEATURE_WIN32
-#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <time.h>
/*