From 439bd03e10053c088eac26da28c0a85be0c325a4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 9 Jan 2014 21:08:11 -0800 Subject: Long overdue MinGW port maintenance. * Makefile: Use new EXE variable from config.mk. * configure (exe, have_windows_h): New variables. Handle situations with .exe suffix; on MiGW, the rm command doesn't work on executables if the .exe suffix is not given. New tests for localtime_r and gmtime_r. * lib.c: Supply declarations which are missing on MinGW because we use gcc -ansi, because MinGW doesn't follow established conventions like -D_POSIX_SOURCE. Supply definitions for gmtime_r, localtime_r, setenv and unsetenv. * parser.l: Supply declarations which are missing on MinGW. * signal.h (async_sig_enabled): Declare differently based on HAVE_POSIX_SIGS. Misspelled typedef fixed in the code for !HAVE_POSIX_SIGS that has hitherto not been compiled. (sig_mask): Wrap declaration in #ifdef HAVE_POSIX_SIGS because it relies on sigset_t. * stream.c: Supply declarations which are missing on MinGW. Include if we have it. (sleep): Define for Windows. (statf): Handle missing st_blksize and st_blocks members in struct stat. (stream_init): Handle numerous missing S_* macros. * utf8.c: Supply declarations which are missing on MinGW. --- lib.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'lib.c') diff --git a/lib.c b/lib.c index 0939bd9a..54927f81 100644 --- a/lib.c +++ b/lib.c @@ -60,6 +60,15 @@ #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) +#if HAVE_WINDOWS_H +int putenv(const char *); +int tzset(void); +#endif + +#if !HAVE_POSIX_SIGS +int async_sig_enabled = 0; +#endif + val packages; val system_package, keyword_package, user_package; @@ -5086,6 +5095,29 @@ val time_sec_usec(void) return cons(num(tv.tv_sec), num(tv.tv_usec)); } +#if !HAVE_GMTIME_R +/* + * Ugly hacks for MingW, which uses the Microsft C Run Time Library, + * whic in turn is stuck in the Dark Ages * without _r functions. + */ +struct tm *gmtime_r(const time_t *timep, struct tm *result); +struct tm *localtime_r(const time_t *timep, struct tm *result); + +struct tm *gmtime_r(const time_t *timep, struct tm *result) +{ + struct tm *hack = gmtime(timep); + *result = *hack; + return hack; +} + +struct tm *localtime_r(const time_t *timep, struct tm *result) +{ + struct tm *hack = localtime(timep); + *result = *hack; + return hack; +} +#endif + static val string_time(struct tm *(*break_time_fn)(const time_t *, struct tm *), char *format, time_t time) { @@ -5158,6 +5190,25 @@ val make_time(val year, val month, val day, return make_time_impl(mktime, year, month, day, hour, minute, second, isdst); } +#if !HAVE_SETENV +static void +setenv(const char *name, const char *value, int overwrite) +{ + int len = strlen(name)+1+strlen(value)+1; + char *str = (char *) chk_malloc(len); + (void) overwrite; + sprintf(str, "%s=%s", name, value); + putenv(str); +} + +static void +unsetenv(const char *name) +{ + setenv(name, "", 1); +} + +#endif + #if !HAVE_TIMEGM static time_t timegm_hack(struct tm *tm) { -- cgit v1.2.3