unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: gmtime_r
Date: Sat, 20 Mar 2004 08:11:13 +1000	[thread overview]
Message-ID: <87oeqsh4hq.fsf@zip.com.au> (raw)

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

        * stime.c (scm_gmtime): Use gmtime_r when available, for thread safety.


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

--- stime.c.~1.86.~	2004-03-07 09:04:24.000000000 +1000
+++ stime.c	2004-03-18 15:15:33.000000000 +1000
@@ -397,6 +397,13 @@
 }
 #undef FUNC_NAME
 
+/* tm_zone is normally a pointer, not an array within struct tm, so we might
+   have to worry about the lifespan of what it points to.  The posix specs
+   don't seem to say anything about this, let's assume for gmtime that
+   tm_zone will be a constant and therefore no protection or anything is
+   needed in between it returning and our making a copy of the string in
+   filltime().  */
+
 SCM_DEFINE (scm_gmtime, "gmtime", 1, 0, 0,
             (SCM time),
 	    "Return an object representing the broken down components of\n"
@@ -405,26 +412,33 @@
 #define FUNC_NAME s_scm_gmtime
 {
   timet itime;
-  struct tm *bd_time;
-  SCM result;
+  struct tm bd_buf, *bd_time;
   const char *zname;
 
   itime = SCM_NUM2LONG (1, time);
-  SCM_DEFER_INTS;
+
   /* POSIX says gmtime sets errno, but C99 doesn't say that.
      Give a sensible default value in case gmtime doesn't set it.  */
   errno = EINVAL;
+
+#if HAVE_GMTIME_R
+  bd_time = gmtime_r (&itime, &bd_buf);
+#else
+  SCM_DEFER_INTS;
   bd_time = gmtime (&itime);
+  if (bd_time != NULL)
+    bd_buf = *bd_time;
+  SCM_ALLOW_INTS;
+#endif
   if (bd_time == NULL)
     SCM_SYSERROR;
+
 #if HAVE_STRUCT_TM_TM_ZONE
-  zname = bd_time->tm_zone;
+  zname = bd_buf.tm_zone;
 #else
   zname = "GMT";
 #endif
-  result = filltime (bd_time, 0, zname);
-  SCM_ALLOW_INTS;
-  return result;
+  return filltime (&bd_buf, 0, zname);
 }
 #undef FUNC_NAME
 

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

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

                 reply	other threads:[~2004-03-19 22:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oeqsh4hq.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).