From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: gmtime_r Date: Sat, 20 Mar 2004 08:11:13 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87oeqsh4hq.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1079734523 10834 80.91.224.253 (19 Mar 2004 22:15:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 19 Mar 2004 22:15:23 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Mar 19 23:15:13 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1B4SGm-00074z-01 for ; Fri, 19 Mar 2004 23:15:12 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B4SDo-0000ma-Vd for guile-devel@m.gmane.org; Fri, 19 Mar 2004 17:12:08 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B4SDj-0000mG-Fc for guile-devel@gnu.org; Fri, 19 Mar 2004 17:12:03 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B4SDD-0000gb-NZ for guile-devel@gnu.org; Fri, 19 Mar 2004 17:12:02 -0500 Original-Received: from [61.8.0.84] (helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B4SDD-0000fr-2c for guile-devel@gnu.org; Fri, 19 Mar 2004 17:11:31 -0500 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i2JMBO4u032614 for ; Sat, 20 Mar 2004 09:11:24 +1100 Original-Received: from localhost (ppp220.dyn11.pacific.net.au [61.8.11.220]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i2JMBM66016138 for ; Sat, 20 Mar 2004 09:11:23 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1B4SCw-0000du-00; Sat, 20 Mar 2004 08:11:14 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3531 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3531 --=-=-= * stime.c (scm_gmtime): Use gmtime_r when available, for thread safety. --=-=-= Content-Disposition: inline; filename=stime.c.gmtime_r.diff --- 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 --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--