Skip to contentSkip to conversation

Add a wrapper for access() when compiling via Visual Studio

PATCH In review David Sommerseth 5 participants 14 messages Dec 8, 2011 – Jan 10, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add a wrapper for access() when compiling via Visual Studio

This adds the access() function as a wrapper for _access() to be able to compile OpenVPN via Visual Studio. It also adds the required macros which used in POSIX environments (R_OK, W_OK, X_OK, F_OK).

This patch will also disable a compiler warning, C4996, as the compiler complains about the usage of access() - despite it is being redefinded as _access().

---
 configure.ac    |    2 +-
 options.c       |    1 -
 win/config.h.in |   29 +++++++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)
configure.ac +1 -1
index 173d6e2..f8b3dd6 100644
@@ -515,7 +515,7 @@ AC_CHECK_FUNCS(daemon chroot getpwnam setuid nice system getpid dup dup2 dnl
 	       getpass strerror syslog openlog mlockall getgrnam setgid dnl
 	       setgroups stat flock readv writev time dnl
 	       setsid chdir putenv getpeername unlink dnl
-	       chsize ftruncate execve getpeereid umask basename dirname)
+	       chsize ftruncate execve getpeereid umask basename dirname access)
 
 # Windows use stdcall for winsock so we cannot auto detect these
 m4_define([SOCKET_FUNCS], [socket recv recvfrom send sendto listen dnl
options.c +0 -1
index 2280e9b..508fc82 100644
@@ -52,7 +52,6 @@
 #include "configure.h"
 #include "forward.h"
 #include <ctype.h>
-#include <unistd.h>
 
 #include "memdbg.h"
 
win/config.h.in +29 -0
index e9df379..b44f564 100644
@@ -223,6 +223,35 @@ typedef unsigned long in_addr_t;
 /* Special Windows version of getpass() defined in io.c */
 #define HAVE_GETPASS 1
 
+
+/* The POSIX access() function is called via _access() on Windows,
+ * defined in io.h
+ */
+#define HAVE_ACCESS 1
+#define access _access
+#pragma warning(disable : 4996) /* Avoid Visual Studio to complain about access(), which is redefined */
+
+/* Macros used by the POSIX access() function might not be available on Windows.
+ * 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
+
+#ifndef F_OK
+#define F_OK 0
+#endif
+
+
 /* Define to the full name and version of this package. */
 #ifdef DEBUG_LABEL
 #define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION " " DEBUG_LABEL
Signature · 1 line
1.7.4.4
#1 lore raw

win/config.h.in typedef unsigned long in_addr_t; · line 232

Quoted 6 lines · David Sommerseth
win/config.h.in +6 -0
+/* The POSIX access() function is called via _access() on Windows,
+ * defined in io.h
+ */
+#define HAVE_ACCESS 1
+#define access _access
+#pragma warning(disable : 4996) /* Avoid Visual Studio to complain about access(), which is redefined */

Where is it defined?
Anyway, won't it better:
---
#ifdef access
#undef access
#endif
#define access _access
---

Alon.

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 9 lines · Alon Bar-Lev
Quoted 4 lines · David Sommerseth

+/* The POSIX access() function is called via _access() on Windows,
+ * defined in io.h + */ +#define HAVE_ACCESS 1 +#define access _access +#pragma warning(disable : 4996) /* Avoid Visual Studio to complain about access(), which is redefined */

Where is it defined? Anyway, won't it better: --- #ifdef access #undef access #endif #define access _access ---

I tried that approach as well, and I still got this warning:
- ------------------------------------------------------------------------- options.c(2619) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
c:\Program Files (x86)\Microsoft Visual Studio
9.0\VC\INCLUDE\io.h(185): see declaration of '_access' options.c(2625) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
c:\Program Files (x86)\Microsoft Visual Studio
9.0\VC\INCLUDE\io.h(185): see declaration of '_access' options.c(2629) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
c:\Program Files (x86)\Microsoft Visual Studio
9.0\VC\INCLUDE\io.h(185): see declaration of '_access' options.c(2630) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
c:\Program Files (x86)\Microsoft Visual Studio
9.0\VC\INCLUDE\io.h(185): see declaration of '_access'
- -------------------------------------------------------------------------

In io.h:185, this line can be found:
- ------------------------------------------------------------------------- _Check_return_ _CRTIMP int __cdecl _access(_In_z_ const char * _Filename, _In_ int _AccessMode);
- -------------------------------------------------------------------------

And access() is declared like this in io.h:303
- ------------------------------------------------------------------------- _Check_return_ _CRT_NONSTDC_DEPRECATE(_access) _CRTIMP int __cdecl access(_In_z_ const char * _Filename, _In_ int _AccessMode);
- -------------------------------------------------------------------------

The only way around this warning was to use the #pragma declaration to disable the C4996 warning. But I'm no Visual Studio expert, I might have overlooked something.

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7glRwACgkQDC186MBRfrrM3QCgpgkDi4JWMaa4mmWjDeopDQfG iWMAoKsMJC5zp4O9UwAwNtDXIM7wHkcB
=+4J5
-----END PGP SIGNATURE-----

#3 lore raw
Quoted 14 lines · David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 9 lines · Alon Bar-Lev
Quoted 4 lines · David Sommerseth

+/* The POSIX access() function is called via _access() on Windows,
+ * defined in io.h + */ +#define HAVE_ACCESS 1 +#define access _access +#pragma warning(disable : 4996) /* Avoid Visual Studio to complain about access(), which is redefined */

Where is it defined? Anyway, won't it better: --- #ifdef access #undef access #endif #define access _access ---

Quoted 10 lines

I tried that approach as well, and I still got this warning:
- ------------------------------------------------------------------------- options.c(2619) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
       c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\io.h(185): see declaration of '_access' options.c(2625) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.

This is something else!
Try defining _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS.

Alon.

#4 lore raw
Quoted 27 lines · Alon Bar-Lev
Quoted 14 lines · David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 9 lines · Alon Bar-Lev
Quoted 4 lines · David Sommerseth

+/* The POSIX access() function is called via _access() on Windows,
+ * defined in io.h + */ +#define HAVE_ACCESS 1 +#define access _access +#pragma warning(disable : 4996) /* Avoid Visual Studio to complain about access(), which is redefined */

Where is it defined? Anyway, won't it better: --- #ifdef access #undef access #endif #define access _access ---

Quoted 10 lines

I tried that approach as well, and I still got this warning:
- ------------------------------------------------------------------------- options.c(2619) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
       c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\io.h(185): see declaration of '_access' options.c(2625) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.

Quoted 4 lines

This is something else!
Try defining _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS.

Alon.

This of course should be only in your vcproj not anywhere in openvpn.

Alon.

#5 lore raw
Quoted 28 lines · Alon Bar-Lev
Quoted 27 lines · Alon Bar-Lev
Quoted 24 lines · David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 9 lines · Alon Bar-Lev
Quoted 4 lines · David Sommerseth

+/* The POSIX access() function is called via _access() on Windows,
+ * defined in io.h + */ +#define HAVE_ACCESS 1 +#define access _access +#pragma warning(disable : 4996) /* Avoid Visual Studio to complain about access(), which is redefined */

Where is it defined? Anyway, won't it better: --- #ifdef access #undef access #endif #define access _access ---

I tried that approach as well, and I still got this warning:
- ------------------------------------------------------------------------- options.c(2619) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.
       c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\io.h(185): see declaration of '_access' options.c(2625) : warning C4996: '_access': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _access. See online help for details.

Quoted 8 lines
Quoted 4 lines

This is something else!
Try defining _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS.

Alon.

This of course should be only in your vcproj not anywhere in openvpn.

Alon.

Just checked, with this enabled you don't need to override access at all.

Alon.

#6 lore raw

PATCH 1/1 Enable access() when building in Visual Studio

In reply to Alon Bar-Lev

Visual Studio does not enable certiain standard Unix functions, such as access(). By defining _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS, these functions are enabled.

This patch also adds a ./configure check for access() as well, in case this needs to be implemented on other platforms lacking this feature. Which is why HAVE_ACCESS is defined in win/config.h.in

Thanks to Alon Bar-Lev for helping solving this.

---
 configure.ac    |    2 +-
 options.c       |    1 -
 win/config.h.in |   28 ++++++++++++++++++++++++++++
 win/msvc.mak.in |    2 +-
 4 files changed, 30 insertions(+), 3 deletions(-)
configure.ac +1 -1
index 173d6e2..f8b3dd6 100644
@@ -515,7 +515,7 @@ AC_CHECK_FUNCS(daemon chroot getpwnam setuid nice system getpid dup dup2 dnl
 	       getpass strerror syslog openlog mlockall getgrnam setgid dnl
 	       setgroups stat flock readv writev time dnl
 	       setsid chdir putenv getpeername unlink dnl
-	       chsize ftruncate execve getpeereid umask basename dirname)
+	       chsize ftruncate execve getpeereid umask basename dirname access)
 
 # Windows use stdcall for winsock so we cannot auto detect these
 m4_define([SOCKET_FUNCS], [socket recv recvfrom send sendto listen dnl
options.c +0 -1
index 2280e9b..508fc82 100644
@@ -52,7 +52,6 @@
 #include "configure.h"
 #include "forward.h"
 #include <ctype.h>
-#include <unistd.h>
 
 #include "memdbg.h"
 
win/config.h.in +28 -0
index e9df379..b5c31b8 100644
@@ -223,6 +223,34 @@ typedef unsigned long in_addr_t;
 /* Special Windows version of getpass() defined in io.c */
 #define HAVE_GETPASS 1
 
+
+/* The POSIX access() function is available, but requires
+ * _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS
+ * to be defined
+ */
+#define HAVE_ACCESS 1
+
+/* Macros used by the POSIX access() function might not be available on Windows.
+ * 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
+
+#ifndef F_OK
+#define F_OK 0
+#endif
+
+
 /* Define to the full name and version of this package. */
 #ifdef DEBUG_LABEL
 #define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION " " DEBUG_LABEL
win/msvc.mak.in +1 -1
index 26d7a33..115e395 100644
@@ -38,7 +38,7 @@ LIB_DIRS = -LIBPATH:$(OPENSSL)\lib -LIBPATH:$(POLARSSL)\build\library -LIBPATH:$
 EXE = openvpn.exe
 
 CPP=cl.exe
-CPP_ARG_COMMON=/nologo /W3 -DWIN32 -DWIN32_LEAN_AND_MEAN -D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_DEPRECATE $(INCLUDE_DIRS) /FD /c
+CPP_ARG_COMMON=/nologo /W3 -DWIN32 -DWIN32_LEAN_AND_MEAN -D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS $(INCLUDE_DIRS) /FD /c
 
 LINK32=link.exe
 
Signature · 1 line
1.7.4.4
#7 lore raw

Re: [Openvpn-devel] [PATCH] Enable access() when building in Visual Studio

Well, this is small and beautiful! :)

Quoted 98 lines · David Sommerseth

Visual Studio does not enable certiain standard Unix functions, such as access().  By defining _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS, these functions are enabled.

This patch also adds a ./configure check for access() as well, in case this needs to be implemented on other platforms lacking this feature.  Which is why HAVE_ACCESS is defined in win/config.h.in

Thanks to Alon Bar-Lev for helping solving this.

---
 configure.ac    |    2 +-
 options.c       |    1 -
 win/config.h.in |   28 ++++++++++++++++++++++++++++ win/msvc.mak.in |    2 +-

 4 files changed, 30 insertions(+), 3 deletions(-)
configure.ac +0 -0
index 173d6e2..f8b3dd6 100644
@@ -515,7 +515,7 @@ AC_CHECK_FUNCS(daemon chroot getpwnam setuid nice system getpid dup dup2 dnl

              getpass strerror syslog openlog mlockall getgrnam setgid dnl setgroups stat flock readv writev time dnl
              setsid chdir putenv getpeername unlink dnl
-              chsize ftruncate execve getpeereid umask basename dirname)
+              chsize ftruncate execve getpeereid umask basename dirname access)

 # Windows use stdcall for winsock so we cannot auto detect these m4_define([SOCKET_FUNCS], [socket recv recvfrom send sendto listen dnl

options.c +0 -1
index 2280e9b..508fc82 100644
@@ -52,7 +52,6 @@
  #include "configure.h"
  #include "forward.h"
  #include <ctype.h>
-#include <unistd.h>
 
  #include "memdbg.h"
 
win/config.h.in +28 -0
index e9df379..b5c31b8 100644
@@ -223,6 +223,34 @@ typedef unsigned long in_addr_t;
  /* Special Windows version of getpass() defined in io.c */
  #define HAVE_GETPASS 1
 
+
+/* The POSIX access() function is available, but requires
+ * _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS
+ * to be defined
+ */
+#define HAVE_ACCESS 1
+
+/* Macros used by the POSIX access() function might not be available on Windows.
+ * 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
+
+#ifndef F_OK
+#define F_OK 0
+#endif
+
+
  /* Define to the full name and version of this package. */
  #ifdef DEBUG_LABEL
  #define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION " " DEBUG_LABEL
win/msvc.mak.in +0 -0
index 26d7a33..115e395 100644
@@ -38,7 +38,7 @@ LIB_DIRS = -LIBPATH:$(OPENSSL)\lib -LIBPATH:$(POLARSSL)\build\library -LIBPATH:$

 EXE = openvpn.exe

 CPP=cl.exe

win/msvc.mak.in +1 -1
-CPP_ARG_COMMON=/nologo /W3 -DWIN32 -DWIN32_LEAN_AND_MEAN -D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_DEPRECATE $(INCLUDE_DIRS) /FD /c
+CPP_ARG_COMMON=/nologo /W3 -DWIN32 -DWIN32_LEAN_AND_MEAN -D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS $(INCLUDE_DIRS) /FD /c

 LINK32=link.exe

--
1.7.4.4

#8 lore raw

Re: [Openvpn-devel] [PATCH] Enable access() when building in Visual Studio

In reply to David Sommerseth

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 8 lines · David Sommerseth

Visual Studio does not enable certiain standard Unix functions, such as access(). By defining _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS, these functions are enabled.

This patch also adds a ./configure check for access() as well, in case this needs to be implemented on other platforms lacking this feature. Which is why HAVE_ACCESS is defined in win/config.h.in

Quoted 6 lines

Thanks to Alon Bar-Lev for helping solving this.

2 +- options.c | 1 - win/config.h.in | 28
++++++++++++++++++++++++++++ win/msvc.mak.in | 2 +- 4 files
changed, 30 insertions(+), 3 deletions(-)

Applied to master branch on -testing and -stable

commit a4234e1e26693e8fe6a67eea5824ef02d11c825e

Author: David Sommerseth <[email protected]...>
Date:   Thu Dec 8 12:38:57 2011 +0100
    Signed-off-by: David Sommerseth <[email protected]...>
    Acked-by: Alon Bar-Lev <[email protected]...>
    Acked-by: Gert Doering <[email protected]...>
    URL:

<http://thread.gmane.org/gmane.network.openvpn.devel/5179/focus=5200>

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8MiLUACgkQDC186MBRfroMzgCfV8EIUlYNx+ezvsbDHO2ShwCz 79MAn0IBrPeP6c8TM1hkeyeN+KJJAgYA
=BftI
-----END PGP SIGNATURE-----

#9 lore raw

PATCH 1/1 Move away from openvpn_basename() over to platform provided basename()

In reply to Alon Bar-Lev

This kicks out the openvpn_basename() function from misc.[ch] andputs it into compat.[ch]. This is to provide the same functionality on platforms not having a native basename() function available.

In addition this patch adds dirname() which commit 0f2bc0dd92f43c91e depends. Without dirname(), openvpn won't build in Visual Studio.

v2: Move all functions from compat.h to compat.c

---
 Makefile.am  |    1 +
 compat.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 compat.h     |   42 +++++++++++++++++++++++++++++
 configure.ac |    2 +-
 init.c       |    6 +++-
 misc.c       |   23 ++--------------
 misc.h       |    3 --
 options.c    |    1 -
 syshead.h    |    2 +
 9 files changed, 135 insertions(+), 27 deletions(-)
 create mode 100644 compat.c
 create mode 100644 compat.h
Makefile.am +1 -0
index 075270f..437f939 100644
@@ -84,6 +84,7 @@ openvpn_SOURCES = \
 	circ_list.h \
 	clinat.c clinat.h \
 	common.h \
+	compat.h compat.c \
 	config-win32.h \
 	crypto.c crypto.h crypto_backend.h \
 	crypto_openssl.c crypto_openssl.h \
compat.c new file +82 -0

82 lines not on this page · raw message

compat.h new file +42 -0

42 lines not on this page · raw message

configure.ac +1 -1
index a4d68e6..173d6e2 100644
@@ -515,7 +515,7 @@ AC_CHECK_FUNCS(daemon chroot getpwnam setuid nice system getpid dup dup2 dnl
 	       getpass strerror syslog openlog mlockall getgrnam setgid dnl
 	       setgroups stat flock readv writev time dnl
 	       setsid chdir putenv getpeername unlink dnl
-	       chsize ftruncate execve getpeereid umask)
+	       chsize ftruncate execve getpeereid umask basename dirname)
 
 # Windows use stdcall for winsock so we cannot auto detect these
 m4_define([SOCKET_FUNCS], [socket recv recvfrom send sendto listen dnl
init.c +4 -2
index 82c1000..368adb4 100644
@@ -862,8 +862,10 @@ init_verb_mute (struct context *c, unsigned int flags)
 void
 init_options_dev (struct options *options)
 {
-  if (!options->dev)
-    options->dev = openvpn_basename (options->dev_node);
+  if (!options->dev && options->dev_node) {
+    char *dev_node = strdup(options->dev_node); /* POSIX basename() implementaions may modify its arguments */
+    options->dev = basename (dev_node);
+  }
 }
 
 bool
misc.c +3 -20
index 99e5bc5..aec12b8 100644
@@ -2022,13 +2022,15 @@ argv_extract_cmd_name (const char *path)
 {
   if (path)
     {
-      const char *bn = openvpn_basename (path);
+      char *path_cp = strdup(path); /* POSIX basename() implementaions may modify its arguments */
+      const char *bn = basename (path_cp);
       if (bn)
 	{
 	  char *ret = string_alloc (bn, NULL);
 	  char *dot = strrchr (ret, '.');
 	  if (dot)
 	    *dot = '\0';
+	  free(path_cp);
 	  if (ret[0] != '\0')
 	    return ret;
 	}
@@ -2370,25 +2372,6 @@ argv_test (void)
 }
 #endif
 
-const char *
-openvpn_basename (const char *path)
-{
-  const char *ret;
-  const int dirsep = OS_SPECIFIC_DIRSEP;
-
-  if (path)
-    {
-      ret = strrchr (path, dirsep);
-      if (ret && *ret)
-	++ret;
-      else
-	ret = path;
-      if (*ret)
-	return ret;
-    }
-  return NULL;
-}
-
 /*
  * Remove security-sensitive strings from control message
  * so that they will not be output to log file.
misc.h +0 -3
index b2e6f91..b1badd9 100644
@@ -381,9 +381,6 @@ extern int script_method; /* GLOBAL */
 /* return the next largest power of 2 */
 size_t adjust_power_of_2 (size_t u);
 
-/* return the basename of path */
-const char *openvpn_basename (const char *path);
-
 /*
  * A printf-like function (that only recognizes a subset of standard printf
  * format operators) that prints arguments to an argv list instead
options.c +0 -1
index 3a819c9..2280e9b 100644
@@ -53,7 +53,6 @@
 #include "forward.h"
 #include <ctype.h>
 #include <unistd.h>
-#include <libgen.h>
 
 #include "memdbg.h"
 
syshead.h +2 -0
index f3c0ac9..020b81f 100644
@@ -36,6 +36,8 @@
 #include "config.h"
 #endif
 
+#include "compat.h"
+
 /* branch prediction hints */
 #if defined(__GNUC__)
 # define likely(x)       __builtin_expect((x),1)
Signature · 1 line
1.7.4.4
#10 lore raw

Re: [Openvpn-devel] [PATCH] Move away from openvpn_basename() over to platform provided basename()

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Please ignore! Troubles with SMTP relay, and I managed to resend the wrong patch to the wrong thread. Sorry!

David S.

Quoted 9 lines · David Sommerseth

This kicks out the openvpn_basename() function from misc.[ch] andputs it into compat.[ch]. This is to provide the same functionality on platforms not having a native basename() function available.

In addition this patch adds dirname() which commit 0f2bc0dd92f43c91e depends. Without dirname(), openvpn won't build in Visual Studio.

v2: Move all functions from compat.h to compat.c

Quoted 8 lines

1 + compat.c | 82
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ compat.h

|   42 +++++++++++++++++++++++++++++ configure.ac |    2 +- init.c
|    6 +++- misc.c       |   23 ++-------------- misc.h       |    3
-- options.c    |    1 - syshead.h    |    2 + 9 files changed, 135

insertions(+), 27 deletions(-) create mode 100644 compat.c create mode 100644 compat.h

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7gteoACgkQDC186MBRfroregCfdHxwZmFUlx3ptHoYTJXhWMiM pfkAn15AHPu+hkVg3H4j78wIEbLWrGIO
=X+IE
-----END PGP SIGNATURE-----

#11 lore raw

PATCH 1/1 Enable access() when building in Visual Studio

In reply to Alon Bar-Lev

Visual Studio does not enable certiain standard Unix functions, such as access(). By defining _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS, these functions are enabled.

This patch also adds a ./configure check for access() as well, in case this needs to be implemented on other platforms lacking this feature. Which is why HAVE_ACCESS is defined in win/config.h.in

Thanks to Alon Bar-Lev for helping solving this.

---
 configure.ac    |    2 +-
 options.c       |    1 -
 win/config.h.in |   28 ++++++++++++++++++++++++++++
 win/msvc.mak.in |    2 +-
 4 files changed, 30 insertions(+), 3 deletions(-)
configure.ac +1 -1
index 173d6e2..f8b3dd6 100644
@@ -515,7 +515,7 @@ AC_CHECK_FUNCS(daemon chroot getpwnam setuid nice system getpid dup dup2 dnl
 	       getpass strerror syslog openlog mlockall getgrnam setgid dnl
 	       setgroups stat flock readv writev time dnl
 	       setsid chdir putenv getpeername unlink dnl
-	       chsize ftruncate execve getpeereid umask basename dirname)
+	       chsize ftruncate execve getpeereid umask basename dirname access)
 
 # Windows use stdcall for winsock so we cannot auto detect these
 m4_define([SOCKET_FUNCS], [socket recv recvfrom send sendto listen dnl
options.c +0 -1
index 2280e9b..508fc82 100644
@@ -52,7 +52,6 @@
 #include "configure.h"
 #include "forward.h"
 #include <ctype.h>
-#include <unistd.h>
 
 #include "memdbg.h"
 
win/config.h.in +28 -0
index e9df379..b5c31b8 100644
@@ -223,6 +223,34 @@ typedef unsigned long in_addr_t;
 /* Special Windows version of getpass() defined in io.c */
 #define HAVE_GETPASS 1
 
+
+/* The POSIX access() function is available, but requires
+ * _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS
+ * to be defined
+ */
+#define HAVE_ACCESS 1
+
+/* Macros used by the POSIX access() function might not be available on Windows.
+ * 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
+
+#ifndef F_OK
+#define F_OK 0
+#endif
+
+
 /* Define to the full name and version of this package. */
 #ifdef DEBUG_LABEL
 #define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION " " DEBUG_LABEL
win/msvc.mak.in +1 -1
index 26d7a33..115e395 100644
@@ -38,7 +38,7 @@ LIB_DIRS = -LIBPATH:$(OPENSSL)\lib -LIBPATH:$(POLARSSL)\build\library -LIBPATH:$
 EXE = openvpn.exe
 
 CPP=cl.exe
-CPP_ARG_COMMON=/nologo /W3 -DWIN32 -DWIN32_LEAN_AND_MEAN -D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_DEPRECATE $(INCLUDE_DIRS) /FD /c
+CPP_ARG_COMMON=/nologo /W3 -DWIN32 -DWIN32_LEAN_AND_MEAN -D_CONSOLE -D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS $(INCLUDE_DIRS) /FD /c
 
 LINK32=link.exe
 
Signature · 1 line
1.7.4.4
#12 lore raw

Re: [Openvpn-devel] [PATCH] Enable access() when building in Visual Studio

Hi,

Quoted 9 lines · David Sommerseth

Visual Studio does not enable certiain standard Unix functions, such as access(). By defining _CRT_NONSTDC_NO_WARNINGS and _CRT_SECURE_NO_WARNINGS, these functions are enabled.

This patch also adds a ./configure check for access() as well, in case this needs to be implemented on other platforms lacking this feature. Which is why HAVE_ACCESS is defined in win/config.h.in

Thanks to Alon Bar-Lev for helping solving this.

ACK!

And thanks to Alon.

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]...
#13 lore raw
In reply to David Sommerseth
Quoted 3 lines · On Thursday 08 December 2011 00:13:49 David Sommerseth wrote:

This adds the access() function as a wrapper for _access() to be able to compile OpenVPN via Visual Studio. It also adds the required macros which used in POSIX environments (R_OK, W_OK, X_OK, F_OK).

Depending on the order this and my "Windows unicode paths" patch are merged there needs to be some additions code here or in that patch that converts the path using wide_string() passing it to _waccess().

Heiko

Signature · 8 lines
Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200
Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany
Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe
 
Represented by the General Partner Astaro Verwaltungs GmbH
Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany 
Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen,
Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen