summaryrefslogtreecommitdiffstats
path: root/time.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-10-16 07:47:30 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-10-16 07:47:30 -0700
commitb25204fce729d4973f2c9c707c06abed7759a959 (patch)
tree49ef7e184726d0cc79ca70d0c413d56f271014cb /time.c
parentfdec8e9d07ff614834c0f39ddd04513cc5648b9a (diff)
downloadtxr-b25204fce729d4973f2c9c707c06abed7759a959.tar.gz
txr-b25204fce729d4973f2c9c707c06abed7759a959.tar.bz2
txr-b25204fce729d4973f2c9c707c06abed7759a959.zip
time: don't emulate setenv with putenv
* time.c (setenv, unsetenv): Removed. (timegm_hack): Now defined earnestly only if HAVE_SETENV is true, otherwise a stub is defined that throws an error. (time_init): Don't register make-time-utc intrinsic if we don't have a timegm function.
Diffstat (limited to 'time.c')
-rw-r--r--time.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/time.c b/time.c
index ea4b3065..fe1d431b 100644
--- a/time.c
+++ b/time.c
@@ -337,26 +337,7 @@ val time_parse(val format, val string)
#endif
-#if !HAVE_SETENV
-
-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);
-}
-
-void unsetenv(const char *name)
-{
- setenv(name, "", 1);
-}
-
-#endif
-
-
-#if !HAVE_TIMEGM
+#if !HAVE_TIMEGM && HAVE_SETENV
static time_t timegm_hack(struct tm *tm)
{
@@ -379,6 +360,16 @@ static time_t timegm_hack(struct tm *tm)
return ret;
}
+
+#endif
+
+#if !HAVE_TIMEGM && !HAVE_SETENV
+
+static time_t timegm_hack(struct tm *tm)
+{
+ uw_throw(system_error_s, lit("timegm function missing"));
+}
+
#endif
val make_time_utc(val year, val month, val day,
@@ -520,7 +511,9 @@ void time_init(void)
reg_fun(intern(lit("time-struct-local"), user_package), func_n1(time_struct_local));
reg_fun(intern(lit("time-struct-utc"), user_package), func_n1(time_struct_utc));
reg_fun(intern(lit("make-time"), user_package), func_n7(make_time));
+#if HAVE_TIMEGM || HAVE_SETENV
reg_fun(intern(lit("make-time-utc"), user_package), func_n7(make_time_utc));
+#endif
reg_fun(intern(lit("time-parse"), user_package), func_n2(time_parse));
reg_fun(intern(lit("time-parse-local"), user_package), func_n2(time_parse_local));
reg_fun(intern(lit("time-parse-utc"), user_package), func_n2(time_parse_utc));