mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 12:20:26 +02:00
Use Gnulib's `strftime' to address bug #24130.
* libguile/stime.c (scm_strftime): Use `nstrftime ()' from Gnulib. This provides the same semantics on all platforms, thereby fixing bug #24130. * doc/ref/posix.texi (Time): Remove note about non-portable `%Z' behavior. Describe the new, portable behavior. * test-suite/tests/time.test ("strftime")["strftime %Z doesn't return garbage"]: Reinstate. ["C99 %z format"](have-strftime-%z): Remove. ("GMT", "EST+5"): Don't use `have-strftime-%z'.
This commit is contained in:
parent
e65fc94b7a
commit
69f23174d3
3 changed files with 14 additions and 59 deletions
|
@ -1,6 +1,6 @@
|
||||||
@c -*-texinfo-*-
|
@c -*-texinfo-*-
|
||||||
@c This is part of the GNU Guile Reference Manual.
|
@c This is part of the GNU Guile Reference Manual.
|
||||||
@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007
|
@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008
|
||||||
@c Free Software Foundation, Inc.
|
@c Free Software Foundation, Inc.
|
||||||
@c See the file guile.texi for copying conditions.
|
@c See the file guile.texi for copying conditions.
|
||||||
|
|
||||||
|
@ -1264,27 +1264,8 @@ formatting.
|
||||||
If @code{setlocale} has been called (@pxref{Locales}), month and day
|
If @code{setlocale} has been called (@pxref{Locales}), month and day
|
||||||
names are from the current locale and in the locale character set.
|
names are from the current locale and in the locale character set.
|
||||||
|
|
||||||
Note that @samp{%Z} might print the @code{tm:zone} in @var{tm} or it
|
Note that @samp{%Z} always ignores the @code{tm:zone} in @var{tm};
|
||||||
might print just the current zone (@code{tzset} above). A GNU system
|
instead it prints just the current zone (@code{tzset} above).
|
||||||
prints @code{tm:zone}, a strict C99 system like NetBSD prints the
|
|
||||||
current zone. Perhaps in the future Guile will try to get
|
|
||||||
@code{tm:zone} used always.
|
|
||||||
@c
|
|
||||||
@c The issue in the above is not just whether tm_zone exists in
|
|
||||||
@c struct tm, but whether libc feels it should read it. Being a
|
|
||||||
@c non-C99 field, a strict C99 program won't know to set it, quite
|
|
||||||
@c likely leaving garbage there. NetBSD, which has the field,
|
|
||||||
@c therefore takes the view that it mustn't read it. See the PR
|
|
||||||
@c about this at
|
|
||||||
@c
|
|
||||||
@c http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=21722
|
|
||||||
@c
|
|
||||||
@c Uniformly making tm:zone used on all systems (all those which have
|
|
||||||
@c %Z at all of course) might be nice (either mung TZ and tzset, or
|
|
||||||
@c mung tzname[]). On the other hand it would make us do more than
|
|
||||||
@c C99 says, and we really don't want to get intimate with the gory
|
|
||||||
@c details of libc time funcs, no more than can be helped.
|
|
||||||
@c
|
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
@deffn {Scheme Procedure} strptime format string
|
@deffn {Scheme Procedure} strptime format string
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <strftime.h>
|
||||||
|
|
||||||
#include "libguile/_scm.h"
|
#include "libguile/_scm.h"
|
||||||
#include "libguile/async.h"
|
#include "libguile/async.h"
|
||||||
|
@ -689,10 +690,9 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0,
|
||||||
tzset ();
|
tzset ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* POSIX says strftime returns 0 on buffer overrun, but old
|
/* Use `nstrftime ()' from Gnulib, which supports all GNU extensions
|
||||||
systems (i.e. libc 4 on GNU/Linux) might return `size' in that
|
supported by glibc. */
|
||||||
case. */
|
while ((len = nstrftime (tbuf, size, myfmt, &t, 0, 0)) == 0)
|
||||||
while ((len = strftime (tbuf, size, myfmt, &t)) == 0 || len == size)
|
|
||||||
{
|
{
|
||||||
free (tbuf);
|
free (tbuf);
|
||||||
size *= 2;
|
size *= 2;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
;;;; time.test --- test suite for Guile's time functions -*- scheme -*-
|
;;;; time.test --- test suite for Guile's time functions -*- scheme -*-
|
||||||
;;;; Jim Blandy <jimb@red-bean.com> --- June 1999, 2004
|
;;;; Jim Blandy <jimb@red-bean.com> --- June 1999, 2004
|
||||||
;;;;
|
;;;;
|
||||||
;;;; Copyright (C) 1999, 2004, 2006, 2007 Free Software Foundation, Inc.
|
;;;; Copyright (C) 1999, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||||
;;;;
|
;;;;
|
||||||
;;;; This program is free software; you can redistribute it and/or modify
|
;;;; This program is free software; you can redistribute it and/or modify
|
||||||
;;;; it under the terms of the GNU General Public License as published by
|
;;;; it under the terms of the GNU General Public License as published by
|
||||||
|
@ -196,44 +196,19 @@
|
||||||
|
|
||||||
(with-test-prefix "strftime"
|
(with-test-prefix "strftime"
|
||||||
|
|
||||||
;; Note we must force isdst to get the ZOW zone name out of %Z on HP-UX.
|
(pass-if "strftime %Z doesn't return garbage"
|
||||||
;; If localtime is in daylight savings then it will decide there's no
|
(let ((t (localtime (current-time))))
|
||||||
;; daylight savings zone name for the fake ZOW, and come back empty.
|
(set-tm:zone t "ZOW")
|
||||||
;;
|
(set-tm:isdst t 0)
|
||||||
;; This test is disabled because on NetBSD %Z doesn't look at the tm_zone
|
(string=? (strftime "%Z" t)
|
||||||
;; field in struct tm passed by guile. That behaviour is reasonable
|
"ZOW")))
|
||||||
;; enough since that field is not in C99 so a C99 program won't know it
|
|
||||||
;; has to be set. For the details on that see
|
|
||||||
;;
|
|
||||||
;; http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=21722
|
|
||||||
;;
|
|
||||||
;; Not sure what to do about this in guile, it'd be nice for %Z to look at
|
|
||||||
;; tm:zone everywhere.
|
|
||||||
;;
|
|
||||||
;;
|
|
||||||
;; (pass-if "strftime %Z doesn't return garbage"
|
|
||||||
;; (let ((t (localtime (current-time))))
|
|
||||||
;; (set-tm:zone t "ZOW")
|
|
||||||
;; (set-tm:isdst t 0)
|
|
||||||
;; (string=? (strftime "%Z" t)
|
|
||||||
;; "ZOW")))
|
|
||||||
|
|
||||||
(with-test-prefix "C99 %z format"
|
(with-test-prefix "C99 %z format"
|
||||||
|
|
||||||
;; C99 spec is empty string if no zone determinable
|
|
||||||
;;
|
|
||||||
;; on pre-C99 systems not sure what to expect if %z unsupported, probably
|
|
||||||
;; "%z" unchanged in C99 if timezone
|
|
||||||
;;
|
|
||||||
(define have-strftime-%z
|
|
||||||
(not (member (strftime "%z" (gmtime 0))
|
|
||||||
'("" "%z"))))
|
|
||||||
|
|
||||||
;; %z here is quite possibly affected by the same tm:gmtoff vs current
|
;; %z here is quite possibly affected by the same tm:gmtoff vs current
|
||||||
;; zone as %Z above is, so in the following tests we make them the same.
|
;; zone as %Z above is, so in the following tests we make them the same.
|
||||||
|
|
||||||
(pass-if "GMT"
|
(pass-if "GMT"
|
||||||
(or have-strftime-%z (throw 'unsupported))
|
|
||||||
(putenv "TZ=GMT+0")
|
(putenv "TZ=GMT+0")
|
||||||
(tzset)
|
(tzset)
|
||||||
(let ((tm (localtime 86400)))
|
(let ((tm (localtime 86400)))
|
||||||
|
@ -243,7 +218,6 @@
|
||||||
;; because we didn't adjust for tm:gmtoff being west of Greenwich versus
|
;; because we didn't adjust for tm:gmtoff being west of Greenwich versus
|
||||||
;; tm_gmtoff being east of Greenwich
|
;; tm_gmtoff being east of Greenwich
|
||||||
(pass-if "EST+5"
|
(pass-if "EST+5"
|
||||||
(or have-strftime-%z (throw 'unsupported))
|
|
||||||
(putenv "TZ=EST+5")
|
(putenv "TZ=EST+5")
|
||||||
(tzset)
|
(tzset)
|
||||||
(let ((tm (localtime 86400)))
|
(let ((tm (localtime 86400)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue