guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stime.c forcing errno


From: Kevin Ryde
Subject: stime.c forcing errno
Date: Sat, 14 Feb 2004 10:09:59 +1000
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux)

        * stime.c (scm_localtime, scm_gmtime, scm_mktime, scm_strptime): Set
        errno = EINVAL ahead of time calls, for the benefit of SCM_SYSERROR if
        those calls don't set errno themselves.  For glibc 2.3.2 mktime with a
        year out of range returns -1 and doesn't set errno.

This is something I'd mentioned a while ago.  For instance a bogus
errno can be seen from

        (mktime #(0 0 0 1 0 9999 4 0 0 0 "GMT"))

This would be for the 1.6 branch too I think.

I'm not sure what the standards say about these time functions setting
errno.  Perhaps being libc functions rather than system calls they
don't ever set it, or only set it incidentally if some timezone data
file is not found or something.

--- stime.c.~1.82.~     2004-01-04 08:25:02.000000000 +1000
+++ stime.c     2004-02-13 11:22:51.000000000 +1000
@@ -327,6 +327,7 @@
 #ifdef LOCALTIME_CACHE
   tzset ();
 #endif
+  errno = EINVAL; /* in case localtime doesn't set this */
   ltptr = localtime (&itime);
   err = errno;
   if (ltptr)
@@ -347,6 +348,7 @@
   /* the struct is copied in case localtime and gmtime share a buffer.  */
   if (ltptr)
     lt = *ltptr;
+  errno = EINVAL; /* in case gmtime doesn't set errno */
   utc = gmtime (&itime);
   if (utc == NULL)
     err = errno;
@@ -389,6 +391,7 @@
 
   itime = SCM_NUM2LONG (1, time);
   SCM_DEFER_INTS;
+  errno = EINVAL; /* in case gmtime doesn't set errno */
   bd_time = gmtime (&itime);
   if (bd_time == NULL)
     SCM_SYSERROR;
@@ -460,6 +463,7 @@
 #ifdef LOCALTIME_CACHE
   tzset ();
 #endif
+  errno = EINVAL; /* in case mktime doesn't set this */
   itime = mktime (&lt);
   err = errno;
 
@@ -480,6 +484,7 @@
     }
 
   /* get timezone offset in seconds west of UTC.  */
+  errno = EINVAL; /* in case gmtime doesn't set errno */
   utc = gmtime (&itime);
   if (utc == NULL)
     err = errno;
@@ -659,6 +664,7 @@
      fields, hence the use of SCM_DEFER_INTS.  */
   t.tm_isdst = -1;
   SCM_DEFER_INTS;
+  errno = EINVAL; /* in case strptime doesn't set errno */
   if ((rest = strptime (str, fmt, &t)) == NULL)
     SCM_SYSERROR;
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]