Skip to contentSkip to conversation

Provide an access() wrapper for Windows

PATCH Superseded David Sommerseth 2 participants 3 messages Dec 2, 2011 – Dec 3, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Provide an access() wrapper for Windows

Commit 0f2bc0dd92f43c91e33bba8a66b06b98f281efc1 adds extra file and directory checks at startup. However, this patch makes use of some features not directly available in Windows.

This patch avoids #include <unistd.h> on Windows and provides a wrapper for the needed access() function.

---
 options.c |    1 -
 syshead.h |    3 +++
 win32.h   |   21 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletions(-)
options.c +0 -1
index a29c115..090bbde 100644
@@ -52,7 +52,6 @@
 #include "configure.h"
 #include "forward.h"
 #include <ctype.h>
-#include <unistd.h>
 
 #include "memdbg.h"
 
syshead.h +3 -0
index f3c0ac9..232c214 100644
@@ -52,9 +52,12 @@
 #ifdef WIN32
 #include <windows.h>
 #include <winsock2.h>
+#include <io.h>
 #define sleep(x) Sleep((x)*1000)
 #define random rand
 #define srandom srand
+#else
+#include <unistd.h>
 #endif
 
 #if defined(__APPLE__)
win32.h +21 -0
index 23c04be..f973849 100644
@@ -70,6 +70,27 @@ struct security_attributes
 
 #define HANDLE_DEFINED(h) ((h) != NULL && (h) != INVALID_HANDLE_VALUE)
 
+/* Provide wrapper for the access() function
+ * based on information found here:
+ * http://msdn.microsoft.com/en-us/library/1w06ktdy%28v=vs.80%29.aspx
+ */
+#ifndef R_OK
+#define R_OK 4
+#endif
+
+#ifndef W_OK
+#define W_OK 2
+#endif
+
+#ifndef X_OK
+#define X_OK 1
+#endif
+
+static inline int
+access( const char *path, int mode) {
+  return _access(path, mode);
+}
+
 /*
  * Save old window title.
  */
Signature · 1 line
1.7.4.4
#1 lore raw

Hi,

Quoted 6 lines · David Sommerseth

Commit 0f2bc0dd92f43c91e33bba8a66b06b98f281efc1 adds extra file and directory checks at startup. However, this patch makes use of some features not directly available in Windows.

This patch avoids #include <unistd.h> on Windows and provides a wrapper for the needed access() function.

ACK.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#2 lore raw

Hi,

Quoted 9 lines · Gert Doering
Quoted 6 lines · David Sommerseth

Commit 0f2bc0dd92f43c91e33bba8a66b06b98f281efc1 adds extra file and directory checks at startup. However, this patch makes use of some features not directly available in Windows.

This patch avoids #include <unistd.h> on Windows and provides a wrapper for the needed access() function.

ACK.

... reading up further mails related to this patch, I like Alon's idea to do this with autoconf/compat.h/compat.c - this looks like it would save us much work in the long run, instead of coming up with hacks of our own every time a function is missing.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...