unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* stime.c forcing errno
@ 2004-02-14  0:09 Kevin Ryde
  2004-02-14  3:52 ` Paul Jarc
  2004-02-23 19:32 ` Marius Vollmer
  0 siblings, 2 replies; 5+ messages in thread
From: Kevin Ryde @ 2004-02-14  0:09 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 717 bytes --]

        * 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.


[-- Attachment #2: stime.c.errno.diff --]
[-- Type: text/plain, Size: 1357 bytes --]

--- 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;
 

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stime.c forcing errno
  2004-02-14  0:09 stime.c forcing errno Kevin Ryde
@ 2004-02-14  3:52 ` Paul Jarc
  2004-02-14  3:58   ` Paul Jarc
  2004-02-14 22:54   ` Kevin Ryde
  2004-02-23 19:32 ` Marius Vollmer
  1 sibling, 2 replies; 5+ messages in thread
From: Paul Jarc @ 2004-02-14  3:52 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> wrote:
> I'm not sure what the standards say about these time functions setting
> errno.

<URL:http://www.opengroup.org/onlinepubs/007904975/functions/localtime.html>:
# If an error is detected, localtime() shall return a null pointer and
# set errno to indicate the error.

<URL:http://www.opengroup.org/onlinepubs/007904975/functions/gmtime.html>:
# If an error is detected, gmtime() shall return a null pointer and
# set errno to indicate the error.

<URL:http://www.opengroup.org/onlinepubs/007904975/functions/mktime.html>:
# No errors are defined.

<URL:http://www.opengroup.org/onlinepubs/007904975/functions/strptime.html>:
# No errors are defined.

<URL:http://www.opengroup.org/onlinepubs/007904975/functions/errno.html>:
# The value of errno shall be defined only after a call to a function
# for which it is explicitly stated to be set

So for localtime/gmtime, set errno beforehand just in case libc fails
to conform.  But for mktime/strptime, test for failure afterwards and
set errno in that case.  Setting it beforehand may not help; since
these functions are not documented to have any particular effect on
errno, they might have any effect at all - such as replacing our
EINVAL with something nonsensical.


paul


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stime.c forcing errno
  2004-02-14  3:52 ` Paul Jarc
@ 2004-02-14  3:58   ` Paul Jarc
  2004-02-14 22:54   ` Kevin Ryde
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Jarc @ 2004-02-14  3:58 UTC (permalink / raw)


I wrote:
> So for localtime/gmtime, set errno beforehand just in case libc fails
> to conform.  But for mktime/strptime, test for failure afterwards and
> set errno in that case.  Setting it beforehand may not help; since
> these functions are not documented to have any particular effect on
> errno, they might have any effect at all - such as replacing our
> EINVAL with something nonsensical.

It would also be ok to test afterwards for localtime/gmtime as well.
POSIX says they should set errno, but the C standard doesn't, so that
might be a good idea.


paul


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stime.c forcing errno
  2004-02-14  3:52 ` Paul Jarc
  2004-02-14  3:58   ` Paul Jarc
@ 2004-02-14 22:54   ` Kevin Ryde
  1 sibling, 0 replies; 5+ messages in thread
From: Kevin Ryde @ 2004-02-14 22:54 UTC (permalink / raw)


prj@po.cwru.edu (Paul Jarc) writes:
>
> But for mktime/strptime, test for failure afterwards and
> set errno in that case.  Setting it beforehand may not help; since
> these functions are not documented to have any particular effect on
> errno, they might have any effect at all - such as replacing our
> EINVAL with something nonsensical.

I guess it's a possibility.  I'll set it afterwards.

> It would also be ok to test afterwards for localtime/gmtime as well.
> POSIX says they should set errno, but the C standard doesn't, so that
> might be a good idea.

Ok, then I'll go with what I made.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stime.c forcing errno
  2004-02-14  0:09 stime.c forcing errno Kevin Ryde
  2004-02-14  3:52 ` Paul Jarc
@ 2004-02-23 19:32 ` Marius Vollmer
  1 sibling, 0 replies; 5+ messages in thread
From: Marius Vollmer @ 2004-02-23 19:32 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> This would be for the 1.6 branch too I think.

Yes.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-02-23 19:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-14  0:09 stime.c forcing errno Kevin Ryde
2004-02-14  3:52 ` Paul Jarc
2004-02-14  3:58   ` Paul Jarc
2004-02-14 22:54   ` Kevin Ryde
2004-02-23 19:32 ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).