[tz] NetBSD and Android bionic APIs for tz values
Paul Eggert
eggert at cs.ucla.edu
Sun Aug 17 17:08:47 UTC 2014
Christos Zoulas wrote:
> just adjust the prototypes how you like them,
> and I will take care of the rest
Thanks. I looked into doing that and found two more issues.
First, there's no need for timelocal_z. timelocal is merely an ancient
(pre-C89) compatibility function, superseded by mktime. There's no need
to expand it, as callers can easily use mktime_z. Let's remove it.
Second and more important, strftime_z has an unnecessary timezone_t
argument. This argument is present to format %Z and %z, but NetBSD can
format %Z from the tm_zone member of struct tm, and similarly for %z and
tm_gmtoff.
The timezone_t argument was invented under the idea that a strictly
conforming C application can leave tm_zone and tm_gmtoff in an undefined
state. Although this is true for strftime, it need not and should not
be true for a new function that we define, as we can impose the
restriction that if the new function is used with %Z and %z, its struct
tm argument must have filled-in values.
This way, the new function will do the right thing in zones that have
three or more time zone abbreviations, or three or more UTC offsets,
which is relatively common. In contrast strftime_z handles only the two
most-current abbreviations and offsets, and this botches historical time
stamps.
Let's call the new function tm_strftime instead of strftime_z. It
doesn't have a time zone argument so the trailing "_z" would be
misleading. The "tm_" prefix can be a mnemonic that this strftime
trusts its struct tm argument; also, the "tm_" prefix is reserved by
POSIX for time.h extensions so it helps to avoids namespace pollution.
Similarly for strftime_lz, renaming it to tm_strftime_l.
A preliminary proposed patch to NetBSD-current sources attached. Again,
I don't know how NetBSD does deprecation. Also, I have not tried to
compile or test this.
-------------- next part --------------
Index: distrib/sets/lists/comp/mi
===================================================================
RCS file: /cvsroot/src/distrib/sets/lists/comp/mi,v
retrieving revision 1.1906
diff -b -w -u -r1.1906 mi
--- distrib/sets/lists/comp/mi 10 Aug 2014 17:07:04 -0000 1.1906
+++ distrib/sets/lists/comp/mi 17 Aug 2014 17:02:53 -0000
@@ -5888,7 +5888,6 @@
./usr/share/man/cat3/ctermid.0 comp-c-catman .cat
./usr/share/man/cat3/ctime.0 comp-c-catman .cat
./usr/share/man/cat3/ctime_r.0 comp-c-catman .cat
-./usr/share/man/cat3/ctime_rz.0 comp-c-catman .cat
./usr/share/man/cat3/ctype.0 comp-c-catman .cat
./usr/share/man/cat3/current_field.0 comp-c-catman .cat
./usr/share/man/cat3/current_item.0 comp-c-catman .cat
@@ -9127,7 +9126,6 @@
./usr/share/man/cat3/stresep.0 comp-c-catman .cat
./usr/share/man/cat3/strfmon.0 comp-c-catman .cat
./usr/share/man/cat3/strftime.0 comp-c-catman .cat
-./usr/share/man/cat3/strftime_z.0 comp-c-catman .cat
./usr/share/man/cat3/string.0 comp-c-catman .cat
./usr/share/man/cat3/string_to_flags.0 comp-c-catman .cat
./usr/share/man/cat3/stringlist.0 comp-c-catman .cat
@@ -9331,6 +9329,7 @@
./usr/share/man/cat3/timezone.0 comp-c-catman .cat
./usr/share/man/cat3/tiparm.0 comp-c-catman .cat
./usr/share/man/cat3/tm.0 comp-c-catman .cat
+./usr/share/man/cat3/tm_strftime.0 comp-c-catman .cat
./usr/share/man/cat3/tmpfile.0 comp-c-catman .cat
./usr/share/man/cat3/tmpnam.0 comp-c-catman .cat
./usr/share/man/cat3/toascii.0 comp-c-catman .cat
@@ -9367,7 +9366,6 @@
./usr/share/man/cat3/types.0 comp-c-catman .cat
./usr/share/man/cat3/tzalloc.0 comp-c-catman .cat
./usr/share/man/cat3/tzfree.0 comp-c-catman .cat
-./usr/share/man/cat3/tzgetname.0 comp-c-catman .cat
./usr/share/man/cat3/tzset.0 comp-c-catman .cat
./usr/share/man/cat3/tzsetwall.0 comp-c-catman .cat
./usr/share/man/cat3/ualarm.0 comp-c-catman .cat
@@ -12722,7 +12720,6 @@
./usr/share/man/html3/ctermid.html comp-c-htmlman html
./usr/share/man/html3/ctime.html comp-c-htmlman html
./usr/share/man/html3/ctime_r.html comp-c-htmlman html
-./usr/share/man/html3/ctime_rz.html comp-c-htmlman html
./usr/share/man/html3/ctype.html comp-c-htmlman html
./usr/share/man/html3/current_field.html comp-c-htmlman html
./usr/share/man/html3/current_item.html comp-c-htmlman html
@@ -15896,7 +15893,6 @@
./usr/share/man/html3/stresep.html comp-c-htmlman html
./usr/share/man/html3/strfmon.html comp-c-htmlman html
./usr/share/man/html3/strftime.html comp-c-htmlman html
-./usr/share/man/html3/strftime_z.html comp-c-htmlman html
./usr/share/man/html3/string.html comp-c-htmlman html
./usr/share/man/html3/string_to_flags.html comp-c-htmlman html
./usr/share/man/html3/stringlist.html comp-c-htmlman html
@@ -16084,6 +16080,7 @@
./usr/share/man/html3/timezone.html comp-c-htmlman html
./usr/share/man/html3/tiparm.html comp-c-htmlman html
./usr/share/man/html3/tm.html comp-c-htmlman html
+./usr/share/man/html3/tm_strftime.html comp-c-htmlman html
./usr/share/man/html3/tmpfile.html comp-c-htmlman html
./usr/share/man/html3/tmpnam.html comp-c-htmlman html
./usr/share/man/html3/toascii.html comp-c-htmlman html
@@ -16120,7 +16117,6 @@
./usr/share/man/html3/types.html comp-c-htmlman html
./usr/share/man/html3/tzalloc.html comp-c-htmlman html
./usr/share/man/html3/tzfree.html comp-c-htmlman html
-./usr/share/man/html3/tzgetname.html comp-c-htmlman html
./usr/share/man/html3/tzset.html comp-c-htmlman html
./usr/share/man/html3/tzsetwall.html comp-c-htmlman html
./usr/share/man/html3/ualarm.html comp-c-htmlman html
@@ -19465,7 +19461,6 @@
./usr/share/man/man3/ctermid.3 comp-c-man .man
./usr/share/man/man3/ctime.3 comp-c-man .man
./usr/share/man/man3/ctime_r.3 comp-c-man .man
-./usr/share/man/man3/ctime_rz.3 comp-c-man .man
./usr/share/man/man3/ctype.3 comp-c-man .man
./usr/share/man/man3/current_field.3 comp-c-man .man
./usr/share/man/man3/current_item.3 comp-c-man .man
@@ -22701,7 +22696,6 @@
./usr/share/man/man3/stresep.3 comp-c-man .man
./usr/share/man/man3/strfmon.3 comp-c-man .man
./usr/share/man/man3/strftime.3 comp-c-man .man
-./usr/share/man/man3/strftime_z.3 comp-c-man .man
./usr/share/man/man3/string.3 comp-c-man .man
./usr/share/man/man3/string_to_flags.3 comp-c-man .man
./usr/share/man/man3/stringlist.3 comp-c-man .man
@@ -22905,6 +22899,7 @@
./usr/share/man/man3/timezone.3 comp-c-man .man
./usr/share/man/man3/tiparm.3 comp-c-man .man
./usr/share/man/man3/tm.3 comp-c-man .man
+./usr/share/man/man3/tm_strftime.3 comp-c-man .man
./usr/share/man/man3/tmpfile.3 comp-c-man .man
./usr/share/man/man3/tmpnam.3 comp-c-man .man
./usr/share/man/man3/toascii.3 comp-c-man .man
@@ -22941,7 +22936,6 @@
./usr/share/man/man3/types.3 comp-c-man .man
./usr/share/man/man3/tzalloc.3 comp-c-man .man
./usr/share/man/man3/tzfree.3 comp-c-man .man
-./usr/share/man/man3/tzgetname.3 comp-c-man .man
./usr/share/man/man3/tzset.3 comp-c-man .man
./usr/share/man/man3/tzsetwall.3 comp-c-man .man
./usr/share/man/man3/ualarm.3 comp-c-man .man
Index: include/time.h
===================================================================
RCS file: /cvsroot/src/include/time.h,v
retrieving revision 1.43
diff -b -w -u -r1.43 time.h
--- include/time.h 21 Apr 2013 17:54:56 -0000 1.43
+++ include/time.h 17 Aug 2014 17:03:11 -0000
@@ -198,24 +198,21 @@
void tzsetwall(void) __RENAME(__tzsetwall50);
struct tm *offtime_r(const time_t *, long, struct tm *) __RENAME(__offtime_r50);
-struct tm *localtime_rz(const timezone_t, const time_t * __restrict,
+struct tm *localtime_rz(timezone_t __restrict, const time_t * __restrict,
struct tm * __restrict) __RENAME(__localtime_rz50);
-char *ctime_rz(const timezone_t, const time_t *, char *) __RENAME(__ctime_rz50);
-time_t mktime_z(const timezone_t, struct tm *) __RENAME(__mktime_z50);
-time_t timelocal_z(const timezone_t, struct tm *) __RENAME(__timelocal_z50);
-time_t time2posix_z(const timezone_t, time_t) __RENAME(__time2posix_z50);
-time_t posix2time_z(const timezone_t, time_t) __RENAME(__posix2time_z50);
+time_t mktime_z(timezone_t __restrict, struct tm * __restrict) __RENAME(__mktime_z50);
+time_t time2posix_z(timezone_t, time_t) __RENAME(__time2posix_z50);
+time_t posix2time_z(timezone_t, time_t) __RENAME(__posix2time_z50);
timezone_t tzalloc(const char *) __RENAME(__tzalloc50);
-void tzfree(const timezone_t) __RENAME(__tzfree50);
-const char *tzgetname(const timezone_t, int) __RENAME(__tzgetname50);
+void tzfree(timezone_t) __RENAME(__tzfree50);
#endif
-size_t strftime_lz(const timezone_t, char * __restrict, size_t,
+size_t tm_strftime_l(char * __restrict, size_t,
const char * __restrict, const struct tm * __restrict, locale_t)
- __attribute__((__format__(__strftime__, 4, 0)));
-size_t strftime_z(const timezone_t, char * __restrict, size_t,
+ __attribute__((__format__(__strftime__, 3, 0)));
+size_t tm_strftime(char * __restrict, size_t,
const char * __restrict, const struct tm * __restrict)
- __attribute__((__format__(__strftime__, 4, 0)));
+ __attribute__((__format__(__strftime__, 3, 0)));
char *strptime_l(const char * __restrict, const char * __restrict,
struct tm * __restrict, locale_t);
Index: lib/libc/compat/include/time.h
===================================================================
RCS file: /cvsroot/src/lib/libc/compat/include/time.h,v
retrieving revision 1.3
diff -b -w -u -r1.3 time.h
--- lib/libc/compat/include/time.h 16 Dec 2010 18:38:06 -0000 1.3
+++ lib/libc/compat/include/time.h 17 Aug 2014 17:03:11 -0000
@@ -92,15 +92,12 @@
int32_t timeoff(struct tm *, long);
int32_t time2posix(int32_t);
int32_t posix2time(int32_t);
-struct tm *localtime_rz(const timezone_t, const int32_t * __restrict,
+struct tm *localtime_rz(timezone_t __restrict, const int32_t * __restrict,
struct tm * __restrict);
-char *ctime_rz(const timezone_t, const int32_t *, char *);
-int32_t mktime_z(const timezone_t, struct tm *);
-int32_t timelocal_z(const timezone_t, struct tm *);
-int32_t time2posix_z(const timezone_t, int32_t);
-int32_t posix2time_z(const timezone_t, int32_t);
+int32_t mktime_z(timezone_t __restrict, struct tm * __restrict);
+int32_t time2posix_z(timezone_t, int32_t);
+int32_t posix2time_z(timezone_t, int32_t);
timezone_t tzalloc(const char *);
-void tzfree(const timezone_t);
-const char *tzgetname(const timezone_t, int);
+void tzfree(timezone_t);
#endif /* !_COMPAT_TIME_H_ */
Index: lib/libc/compat/time/compat_localtime.c
===================================================================
RCS file: /cvsroot/src/lib/libc/compat/time/compat_localtime.c,v
retrieving revision 1.3
diff -b -w -u -r1.3 compat_localtime.c
--- lib/libc/compat/time/compat_localtime.c 21 Feb 2011 22:07:44 -0000 1.3
+++ lib/libc/compat/time/compat_localtime.c 17 Aug 2014 17:03:11 -0000
@@ -16,7 +16,6 @@
#ifdef __weak_alias
__weak_alias(ctime_r,_ctime_r)
-__weak_alias(ctime_rz,_ctime_rz)
__weak_alias(gmtime_r,_gmtime_r)
__weak_alias(localtime_r,_localtime_r)
__weak_alias(localtime_rz,_localtime_rz)
@@ -35,9 +34,6 @@
__warn_references(ctime_r,
"warning: reference to compatibility ctime_r();"
" include <time.h> for correct reference")
-__warn_references(ctime_rz,
- "warning: reference to compatibility ctime_rz();"
- " include <time.h> for correct reference")
__warn_references(gmtime_r,
"warning: reference to compatibility gmtime_r();"
" include <time.h> for correct reference")
Index: lib/libc/include/namespace.h
===================================================================
RCS file: /cvsroot/src/lib/libc/include/namespace.h,v
retrieving revision 1.174
diff -b -w -u -r1.174 namespace.h
--- lib/libc/include/namespace.h 13 Jun 2014 15:45:05 -0000 1.174
+++ lib/libc/include/namespace.h 17 Aug 2014 17:03:11 -0000
@@ -244,7 +244,6 @@
#define csetexpandtc _csetexpandtc
#define ctermid _ctermid
#define ctime_r _ctime_r
-#define ctime_rz _ctime_rz
#define daemon _daemon
#define dbopen _dbopen
#define devname _devname
@@ -629,8 +628,6 @@
#define strdup _strdup
#define stresep _stresep
#define strftime_l _strftime_l
-#define strftime_lz _strftime_lz
-#define strftime_z _strftime_z
#define strndup _strndup
#define strncasecmp _strncasecmp
#define strptime _strptime
@@ -704,6 +701,8 @@
#define timelocal _timelocal
#define timeoff _timeoff
#define times _times
+#define tm_strftime _tm_strftime
+#define tm_strftime_l _tm_strftime_l
#define ttyname _ttyname
#define ttyname_r _ttyname_r
#define ttyslot _ttyslot
Index: lib/libc/time/Makefile.inc
===================================================================
RCS file: /cvsroot/src/lib/libc/time/Makefile.inc,v
retrieving revision 1.18
diff -b -w -u -r1.18 Makefile.inc
--- lib/libc/time/Makefile.inc 16 Jan 2014 20:31:43 -0000 1.18
+++ lib/libc/time/Makefile.inc 17 Aug 2014 17:03:11 -0000
@@ -8,7 +8,6 @@
CPPFLAGS+=-DALL_STATE -DUSG_COMPAT
MLINKS+=ctime.3 ctime_r.3 \
- ctime.3 ctime_rz.3 \
ctime.3 asctime.3 \
ctime.3 asctime_r.3 \
ctime.3 difftime.3 \
@@ -21,7 +20,6 @@
ctime.3 mktime_z.3 \
ctime.3 tzalloc.3 \
ctime.3 tzfree.3 \
- ctime.3 tzgetname.3 \
getdate.3 getdate_err.3 \
offtime.3 offtime_r.3 \
offtime.3 timeoff.3 \
@@ -32,6 +30,6 @@
time2posix.3 time2posix_z.3 \
tzset.3 daylight.3 \
tzset.3 tzsetwall.3 \
- strftime.3 strftime_z.3
+ strftime.3 tm_strftime.3
COPTS.strftime.c = -Wno-format-nonliteral
Index: lib/libc/time/ctime.3
===================================================================
RCS file: /cvsroot/src/lib/libc/time/ctime.3,v
retrieving revision 1.50
diff -b -w -u -r1.50 ctime.3
--- lib/libc/time/ctime.3 15 Aug 2014 11:04:07 -0000 1.50
+++ lib/libc/time/ctime.3 17 Aug 2014 17:03:11 -0000
@@ -10,7 +10,6 @@
.Nm asctime_r ,
.Nm ctime ,
.Nm ctime_r ,
-.Nm ctime_rz ,
.Nm difftime ,
.Nm gmtime ,
.Nm gmtime_r ,
@@ -20,7 +19,6 @@
.Nm mktime ,
.Nm mktime_z ,
.Nm tzalloc ,
-.Nm tzgetname ,
.Nm tzfree ,
.Nd convert date and time
.Sh LIBRARY
@@ -36,8 +34,6 @@
.Fn ctime "const time_t *clock"
.Ft char *
.Fn ctime_r "const time_t *clock" "char *buf"
-.Ft char *
-.Fn ctime_rz "const timezone_t tz" "const time_t *clock" "char *buf"
.Ft double
.Fn difftime "time_t time1" "time_t time0"
.Ft struct tm *
@@ -49,17 +45,16 @@
.Ft struct tm *
.Fn localtime_r "const time_t * restrict clock" "struct tm * restrict result"
.Ft struct tm *
-.Fn localtime_rz "const timezone_t tz" "const time_t * restrict clock" "struct tm * restrict result"
+.Fn localtime_rz "timezone_t restrict tz" "const time_t * restrict clock" "struct tm * restrict result"
.Ft time_t
.Fn mktime "struct tm *tm"
.Ft time_t
-.Fn mktime_z "const timezone_t tz" "struct tm *tm"
+.Fn mktime_z "timezone_t restrict tz" "struct tm * restrict tm"
.Ft timezone_t
.Fn tzalloc "const char *zone"
.Ft void
-.Fn tzfree "const timezone_t tz"
+.Fn tzfree "timezone_t tz"
.Ft const char *
-.Fn tzgetname "const timezone_t tz" "int isdst"
.Sh DESCRIPTION
The
.Nm
@@ -127,18 +122,6 @@
.Fa buf
argument, which should be 26 or more bytes long,
instead of using a global static buffer.
-.It Fn ctime_rz "tz" "clock" "buf"
-The
-.Fn ctime_rz
-function is similar to
-.Fn ctime_r ,
-but it also takes a
-.Ft "const timezone_t"
-argument, as returned by a previous call to
-.Fn tzalloc ,
-or a null pointer denoting
-Coordinated Universal Time
-.Pq Tn UTC .
.It Fn difftime "time1" "time2"
The
.Fn difftime
@@ -200,7 +183,7 @@
function is similar to
.Fn localtime_r ,
but it also takes a
-.Ft "const timezone_t"
+.Ft timezone_t
argument, returned by a previous call to
.Fn tzalloc ,
or a null pointer denoting
@@ -280,7 +263,7 @@
function is similar to
.Fn mktime
but it also takes a
-.Ft "const timezone_t"
+.Ft timezone_t
argument, returned by a previous call to
.Fn tzalloc ,
or a null pointer denoting
@@ -292,8 +275,7 @@
function takes as an argument a timezone name and returns a
.Ft timezone_t
object suitable to be used in the
-.Fn ctime_rz ,
-.Fn localtime_rz ,
+.Fn localtime_rz
and
.Fn mktime_z
functions.
@@ -321,23 +303,6 @@
.Fa tz ,
which was previously allocated by
.Fn tzalloc .
-.It Fn "tzgetname"
-Finally,
-.Fn tzgetname
-returns the name for the given
-.Fa tz .
-If
-.Fa isdst
-is
-.Va 0 ,
-the call is equivalent to
-.Va tzname[0] .
-If
-.Fa isdst
-is set to
-.Va 1
-the call is equivalent to
-.Va tzname[1] .
.El
.Pp
Declarations of all the functions and externals, and the
@@ -389,11 +354,10 @@
and
.Fn ctime
functions return a pointer to a static character buffer, and the
-.Fn asctime_r ,
-.Fn ctime_r ,
+.Fn asctime_r
and
-.Fn ctime_rz
-function return a pointer to the user-supplied buffer.
+.Fn ctime_r
+functions return a pointer to the user-supplied buffer.
On failure they all return
.Dv NULL
and no errors are defined for them.
Index: lib/libc/time/localtime.c
===================================================================
RCS file: /cvsroot/src/lib/libc/time/localtime.c,v
retrieving revision 1.85
diff -b -w -u -r1.85 localtime.c
--- lib/libc/time/localtime.c 16 Aug 2014 16:22:21 -0000 1.85
+++ lib/libc/time/localtime.c 17 Aug 2014 17:03:11 -0000
@@ -286,19 +286,6 @@
return result;
}
-const char *
-tzgetname(const timezone_t sp, int isdst)
-{
- int i;
- for (i = 0; i < sp->timecnt; ++i) {
- const struct ttinfo *const ttisp = &sp->ttis[sp->types[i]];
-
- if (ttisp->tt_isdst == isdst)
- return &sp->chars[ttisp->tt_abbrind];
- }
- return NULL;
-}
-
static void
settzname_z(timezone_t sp)
{
@@ -1728,17 +1715,6 @@
return asctime_r(rtm, buf);
}
-char *
-ctime_rz(const timezone_t sp, const time_t * timep, char *buf)
-{
- struct tm mytm, *rtm;
-
- rtm = localtime_rz(sp, timep, &mytm);
- if (rtm == NULL)
- return NULL;
- return asctime_r(rtm, buf);
-}
-
/*
** Adapted from code provided by Robert Elz, who writes:
** The "best" way to do mktime I think is based on an idea of Bob
@@ -2158,14 +2134,6 @@
#ifdef STD_INSPIRED
time_t
-timelocal_z(const timezone_t sp, struct tm *const tmp)
-{
- if (tmp != NULL)
- tmp->tm_isdst = -1; /* in case it wasn't initialized */
- return mktime_z(sp, tmp);
-}
-
-time_t
timelocal(struct tm *const tmp)
{
if (tmp != NULL)
Index: lib/libc/time/strftime.3
===================================================================
RCS file: /cvsroot/src/lib/libc/time/strftime.3,v
retrieving revision 1.30
diff -b -w -u -r1.30 strftime.3
--- lib/libc/time/strftime.3 20 Sep 2013 19:06:54 -0000 1.30
+++ lib/libc/time/strftime.3 17 Aug 2014 17:03:11 -0000
@@ -37,7 +37,7 @@
.Os
.Sh NAME
.Nm strftime ,
-.Nm strftime_z
+.Nm tm_strftime
.Nd format date and time
.Sh LIBRARY
.Lb libc
@@ -46,7 +46,7 @@
.Ft size_t
.Fn strftime "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr"
.Ft size_t
-.Fn strftime_z "const timezone_t tz" "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr"
+.Fn tm_strftime "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr"
.Sh DESCRIPTION
The
.Fn strftime
@@ -201,13 +201,15 @@
.El
.Pp
The
-.Fn strftime_z
+.Fn tm_strftime
function is similar to
.Fn strftime ,
-but it also takes a
-.Ft "const timezone_t"
-.Fa tz
-argument.
+except that it takes its time zone information from the
+.Fa timeptr 's
+.Fa tm_gmtoff
+and
+.Fa tm_zone
+members instead of inferring it (sometimes incorrectly) from global settings.
.Sh SEE ALSO
.Xr date 1 ,
.Xr printf 1 ,
Index: lib/libc/time/strftime.c
===================================================================
RCS file: /cvsroot/src/lib/libc/time/strftime.c,v
retrieving revision 1.31
diff -b -w -u -r1.31 strftime.c
--- lib/libc/time/strftime.c 15 Aug 2014 11:04:07 -0000 1.31
+++ lib/libc/time/strftime.c 17 Aug 2014 17:03:11 -0000
@@ -27,17 +27,6 @@
#include "private.h"
/*
-** We don't use these extensions in strftime operation even when
-** supported by the local tzcode configuration. A strictly
-** conforming C application may leave them in undefined state.
-*/
-
-#ifdef _LIBC
-#undef TM_ZONE
-#undef TM_GMTOFF
-#endif
-
-/*
** Copyright (c) 1989, 1993
** The Regents of the University of California. All rights reserved.
**
@@ -76,8 +65,8 @@
#ifdef __weak_alias
__weak_alias(strftime_l, _strftime_l)
-__weak_alias(strftime_lz, _strftime_lz)
-__weak_alias(strftime_z, _strftime_z)
+__weak_alias(tm_strftime_l, _tm_strftime_l)
+__weak_alias(tm_strftime, _tm_strftime)
#endif
#include "sys/localedef.h"
@@ -85,9 +74,11 @@
((_TimeLocale *)((loc)->part_impl[(size_t)LC_TIME]))
#define c_fmt d_t_fmt
+static size_t _format_time(char *, size_t, const char *, const struct tm *,
+ locale_t, int);
static char * _add(const char *, char *, const char *);
static char * _conv(int, const char *, char *, const char *);
-static char * _fmt(const timezone_t, const char *, const struct tm *, char *,
+static char * _fmt(int, const char *, const struct tm *, char *,
const char *, int *, locale_t);
static char * _yconv(int, int, int, int, char *, const char *);
@@ -103,16 +94,24 @@
#define IN_ALL 3
size_t
-strftime_z(const timezone_t sp, char * __restrict s, size_t maxsize,
+tm_strftime(char * __restrict s, size_t maxsize,
const char * __restrict format, const struct tm * __restrict t)
{
- return strftime_lz(sp, s, maxsize, format, t, _current_locale());
+ return tm_strftime_l(s, maxsize, format, t, _current_locale());
}
size_t
-strftime_lz(const timezone_t sp, char *const s, const size_t maxsize,
+tm_strftime_l(char *const s, const size_t maxsize,
const char *const format, const struct tm *const t, locale_t loc)
{
+ return _format_time(s, maxsize, format, t, loc, 1);
+}
+
+static size_t
+_format_time(char *const s, const size_t maxsize,
+ const char *const format, const struct tm *const t, locale_t loc,
+ int sp)
+{
char * p;
int warn;
@@ -142,7 +141,7 @@
}
static char *
-_fmt(const timezone_t sp, const char *format, const struct tm *const t,
+_fmt(int sp, const char *format, const struct tm *const t,
char *pt, const char *const ptlim, int *warnp, locale_t loc)
{
for ( ; *format; ++format) {
@@ -472,15 +471,10 @@
pt, ptlim);
continue;
case 'Z':
-#ifdef TM_ZONE
- if (t->TM_ZONE != NULL)
- pt = _add(t->TM_ZONE, pt, ptlim);
- else
-#endif /* defined TM_ZONE */
- if (t->tm_isdst >= 0)
- pt = _add((sp ?
- tzgetname(sp, t->tm_isdst) :
- tzname[t->tm_isdst != 0]),
+ if (sp && t->tm_zone != NULL)
+ pt = _add(t->tm_zone, pt, ptlim);
+ else if (t->tm_isdst >= 0)
+ pt = _add(tzname[t->tm_isdst != 0],
pt, ptlim);
/*
** C99 says that %Z must be replaced by the
@@ -495,9 +489,9 @@
if (t->tm_isdst < 0)
continue;
-#ifdef TM_GMTOFF
- diff = (int)t->TM_GMTOFF;
-#else /* !defined TM_GMTOFF */
+ if (sp)
+ diff = (int)t->tm_gmtoff;
+ else {
/*
** C99 says that the UT offset must
** be computed by looking only at
@@ -559,7 +553,7 @@
diff = (intmax_t)gct - (intmax_t)lct;
}
#endif /* defined STD_INSPIRED */
-#endif /* !defined TM_GMTOFF */
+ }
if (diff < 0) {
sign = "-";
diff = -diff;
@@ -599,8 +593,7 @@
strftime(char * const s, const size_t maxsize,
const char * const format, const struct tm * const t)
{
- tzset();
- return strftime_z(NULL, s, maxsize, format, t);
+ return strftime_l(s, maxsize, format, t, _current_locale());
}
size_t
@@ -608,7 +601,7 @@
const struct tm * __restrict t, locale_t loc)
{
tzset();
- return strftime_lz(NULL, s, maxsize, format, t, loc);
+ return _format_time(s, maxsize, format, t, loc, 0);
}
static char *
Index: lib/libc/time/time2posix.3
===================================================================
RCS file: /cvsroot/src/lib/libc/time/time2posix.3,v
retrieving revision 1.18
diff -b -w -u -r1.18 time2posix.3
--- lib/libc/time/time2posix.3 15 Aug 2014 11:04:07 -0000 1.18
+++ lib/libc/time/time2posix.3 17 Aug 2014 17:03:12 -0000
@@ -15,11 +15,11 @@
.Ft time_t
.Fn time2posix "time_t t"
.Ft time_t
-.Fn time2posix_z "const timezone_t tz" "time_t t"
+.Fn time2posix_z "timezone_t tz" "time_t t"
.Ft time_t
.Fn posix2time "time_t t"
.Ft time_t
-.Fn posix2time_z "const timezone_t tz" "time_t t"
+.Fn posix2time_z "timezone_t tz" "time_t t"
.Sh DESCRIPTION
.St -p1003.1
legislates that a
Index: share/man/man3/tm.3
===================================================================
RCS file: /cvsroot/src/share/man/man3/tm.3,v
retrieving revision 1.4
diff -b -w -u -r1.4 tm.3
--- share/man/man3/tm.3 14 Apr 2011 05:45:34 -0000 1.4
+++ share/man/man3/tm.3 17 Aug 2014 17:03:12 -0000
@@ -95,7 +95,7 @@
was returned by
.Xr localtime_rz 3
and the
-.Ft "const timezone_t"
+.Ft timezone_t
.Fa tz
argument has been freed by
.Xr tzfree 3 .
More information about the tz
mailing list