[PATCH 5/8] Fix compat.c compilation with mingw32
Ladislav Michl <[email protected]> Tue, 4 Dec 2018 22:25:42 +0100
| Newsgroups | gmane.linux.drivers.gnokii |
|---|---|
| Message-ID | <20181204212542.GF10937@lenoch> |
Guard Windows version of setenv with HAVE_SETENV for setups
where setenv is already provided.
---
common/compat.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/common/compat.c b/common/compat.c
index 35673caa..99b777f1 100644
--- a/common/compat.c
+++ b/common/compat.c
@@ -15,13 +15,10 @@
#include "compat.h"
+#ifndef HAVE_SETENV
+
#ifdef WIN32
# include <windows.h>
-# include <sys/timeb.h>
-# include <time.h>
-# define ftime _ftime
-# define timeb _timeb
-
int setenv(const char *name, const char *value, int overwrite)
{
return (int)SetEnvironmentVariable(name, value);
@@ -32,10 +29,7 @@ int unsetenv(const char *name)
SetEnvironmentVariable(name, NULL);
return 0;
}
-
-#endif
-
-#ifndef HAVE_SETENV
+#else
# include <stdlib.h>
/* Implemented according to http://www.greenend.org.uk/rjk/2008/putenv.html and Linux manpage */
int setenv(const char *envname, const char *envvalue, int overwrite)
@@ -65,12 +59,21 @@ int unsetenv(const char *name)
}
#endif
+#endif
+
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifndef HAVE_GETTIMEOFDAY
+#ifdef WIN32
+# include <sys/timeb.h>
+# include <time.h>
+# define ftime _ftime
+# define timeb _timeb
+#endif
+
int gettimeofday(struct timeval *tv, void *tz)
{
struct timeb t;
@@ -88,7 +91,6 @@ int gettimeofday(struct timeval *tv, void *tz)
#endif
-
#ifndef HAVE_STRSEP
/*
@@ -149,7 +151,7 @@ char *strsep(char **stringp, const char *delim)
register const char *spanp;
register int c, sc;
char *tok;
-
+
if ((s = *stringp) == NULL)
return (NULL);
for (tok = s;;) {
--
2.20.0.rc2