Browse code

use the underscore version of stat on Windows

MSVC does not know wstat(). Instead _wstat() must be used here.
Unfortunately _wstat() takes a 'struct _stat'. A type 'stat_t' is
introduced to handle this situation in a portable way.

[v2: Use openvpn_stat_t instead of stat_t (David Sommerseth)]

Signed-off-by: Heiko Hund <heiko.hund@sophos.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
Acked-by: Gert Doering <gert@greenie.muc.de>

Heiko Hund authored on 2012/02/17 02:30:40
Showing 3 changed files
... ...
@@ -168,10 +168,12 @@ openvpn_open (const char *path, int flags, mode_t mode)
168 168
 #endif
169 169
 
170 170
 #ifdef WIN32
171
-int openvpn_stat (const char *path, struct stat *buf);
171
+typedef struct _stat openvpn_stat_t;
172
+int openvpn_stat (const char *path, openvpn_stat_t *buf);
172 173
 #else
174
+typedef struct stat openvpn_stat_t;
173 175
 static inline int
174
-openvpn_stat (const char *path, struct stat *buf)
176
+openvpn_stat (const char *path, openvpn_stat_t *buf)
175 177
 {
176 178
   return stat (path, buf);
177 179
 }
... ...
@@ -498,7 +498,7 @@ pf_check_reload (struct context *c)
498 498
       && c->c2.pf.filename
499 499
       && event_timeout_trigger (&c->c2.pf.reload, &c->c2.timeval, ETT_DEFAULT))
500 500
     {
501
-      struct stat s;
501
+      openvpn_stat_t s;
502 502
       if (!openvpn_stat (c->c2.pf.filename, &s))
503 503
 	{
504 504
 	  if (s.st_mtime > c->c2.pf.file_last_mod)
... ...
@@ -1073,10 +1073,10 @@ openvpn_open (const char *path, int flags, int mode)
1073 1073
 }
1074 1074
 
1075 1075
 int
1076
-openvpn_stat (const char *path, struct stat *buf)
1076
+openvpn_stat (const char *path, openvpn_stat_t *buf)
1077 1077
 {
1078 1078
   struct gc_arena gc = gc_new ();
1079
-  int res = wstat (wide_string (path, &gc), buf);
1079
+  int res = _wstat (wide_string (path, &gc), buf);
1080 1080
   gc_free (&gc);
1081 1081
   return res;
1082 1082
 }