summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-01-09 21:08:11 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-01-09 21:08:11 -0800
commit439bd03e10053c088eac26da28c0a85be0c325a4 (patch)
treebfb2a5bd8e7a74ceb3db4fec8b4378d72aa441f3 /lib.c
parent0b86366870e0a1e45955881a2d3206175061271e (diff)
downloadtxr-439bd03e10053c088eac26da28c0a85be0c325a4.tar.gz
txr-439bd03e10053c088eac26da28c0a85be0c325a4.tar.bz2
txr-439bd03e10053c088eac26da28c0a85be0c325a4.zip
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 <windows.h> 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.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c51
1 files changed, 51 insertions, 0 deletions
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)
{