Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Provide a re-entrant and thread-safe set of timezone API's that



details:   https://anonhg.NetBSD.org/src/rev/5dc0d799d9f1
branches:  trunk
changeset: 759791:5dc0d799d9f1
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Dec 16 18:36:47 2010 +0000

description:
Provide a re-entrant and thread-safe set of timezone API's that
don't require locking and can operate on user-specified timezones
as opposed to having to alter the environment to change a timezone.
This work was presented to the tzcode folks and it was generally
accepted, but there seems to be a lot of inertia.

diffstat:

 include/time.h                 |   26 +-
 lib/libc/compat/include/time.h |   14 +-
 lib/libc/include/namespace.h   |    7 +-
 lib/libc/shlib_version         |    4 +-
 lib/libc/time/Makefile.inc     |   12 +-
 lib/libc/time/ctime.3          |  155 ++++++++-
 lib/libc/time/localtime.c      |  676 +++++++++++++++++++---------------------
 lib/libc/time/offtime.3        |   15 +-
 lib/libc/time/strftime.3       |   18 +-
 lib/libc/time/strftime.c       |   65 ++-
 lib/libc/time/time2posix.3     |   42 ++-
 11 files changed, 619 insertions(+), 415 deletions(-)

diffs (truncated from 2204 to 300 lines):

diff -r 5c813ba07b24 -r 5dc0d799d9f1 include/time.h
--- a/include/time.h    Thu Dec 16 18:29:47 2010 +0000
+++ b/include/time.h    Thu Dec 16 18:36:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: time.h,v 1.39 2009/05/14 02:37:36 ginsbach Exp $       */
+/*     $NetBSD: time.h,v 1.40 2010/12/16 18:36:47 christos Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -174,6 +174,9 @@
 #endif
 
 #if defined(_NETBSD_SOURCE)
+
+typedef struct __state *timezone_t;
+
 #ifndef __LIBC12_SOURCE__
 time_t time2posix(time_t) __RENAME(__time2posix50);
 time_t posix2time(time_t) __RENAME(__posix2time50);
@@ -181,10 +184,25 @@
 time_t timeoff(struct tm *, long) __RENAME(__timeoff50);
 time_t timelocal(struct tm *) __RENAME(__timelocal50);
 struct tm *offtime(const time_t *, long) __RENAME(__offtime50);
+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 * __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);
+timezone_t tzalloc(const char *) __RENAME(__tzalloc50);
+void tzfree(const timezone_t) __RENAME(__tzfree50);
+const char *tzgetname(const timezone_t, int) __RENAME(__tzgetname50);
 #endif
-#ifndef __LIBC12_SOURCE__
-void tzsetwall(void) __RENAME(__tzsetwall50);
-#endif
+
+size_t strftime_z(const timezone_t, char * __restrict, size_t,
+    const char * __restrict, const struct tm * __restrict)
+    __attribute__((__format__(__strftime__, 4, 0)));
+
 #endif /* _NETBSD_SOURCE */
 
 __END_DECLS
diff -r 5c813ba07b24 -r 5dc0d799d9f1 lib/libc/compat/include/time.h
--- a/lib/libc/compat/include/time.h    Thu Dec 16 18:29:47 2010 +0000
+++ b/lib/libc/compat/include/time.h    Thu Dec 16 18:36:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: time.h,v 1.2 2009/01/11 02:46:25 christos Exp $        */
+/*     $NetBSD: time.h,v 1.3 2010/12/16 18:38:06 christos Exp $        */
 
 /*
  * Copyright (c) 1989, 1993
@@ -86,9 +86,21 @@
 struct tm *gmtime_r(const int32_t * __restrict, struct tm * __restrict);
 struct tm *localtime_r(const int32_t * __restrict, struct tm * __restrict);
 struct tm *offtime(const int32_t *, long);
+struct tm *offtime_r(const int32_t *, long, struct tm *);
 int32_t timelocal(struct tm *);
 int32_t timegm(struct tm *);
 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 * __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);
+timezone_t tzalloc(const char *);
+void tzfree(const timezone_t);
+const char *tzgetname(const timezone_t, int);
+
 #endif /* !_COMPAT_TIME_H_ */
diff -r 5c813ba07b24 -r 5dc0d799d9f1 lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h      Thu Dec 16 18:29:47 2010 +0000
+++ b/lib/libc/include/namespace.h      Thu Dec 16 18:36:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: namespace.h,v 1.145 2010/11/17 13:19:32 tron Exp $     */
+/*     $NetBSD: namespace.h,v 1.146 2010/12/16 18:38:06 christos Exp $ */
 
 /*-
  * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -221,6 +221,7 @@
 #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
@@ -432,12 +433,14 @@
 #define llabs                  _llabs
 #define lldiv                  _lldiv
 #define localtime_r            _localtime_r
+#define localtime_rz           _localtime_rz
 #define lockf                  _lockf
 #define lrand48                        _lrand48
 #define lseek                  _lseek
 #define mergesort              _mergesort
 #define mi_vector_hash         _mi_vector_hash
 #define mkstemp                        _mkstemp
+#define mktime_z               _mktime_z
 #define mmap                   _mmap
 #define mpool_close            _mpool_close
 #define mpool_filter           _mpool_filter
@@ -474,6 +477,7 @@
 #define pollts                 _pollts
 #define popen                  _popen
 #define posix2time             _posix2time
+#define posix2time_z           _posix2time_z
 #define pread                  _pread
 #define pselect                        _pselect
 #define psignal                        _psignal
@@ -579,6 +583,7 @@
 #define strcasecmp             _strcasecmp
 #define strdup                 _strdup
 #define stresep                        _stresep
+#define strftime_z             _strftime_z
 #define strndup                        _strndup
 #define strncasecmp            _strncasecmp
 #define strptime               _strptime
diff -r 5c813ba07b24 -r 5dc0d799d9f1 lib/libc/shlib_version
--- a/lib/libc/shlib_version    Thu Dec 16 18:29:47 2010 +0000
+++ b/lib/libc/shlib_version    Thu Dec 16 18:36:47 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: shlib_version,v 1.219 2010/09/24 09:21:53 tnozaki Exp $
+#      $NetBSD: shlib_version,v 1.220 2010/12/16 18:38:06 christos Exp $
 #      Remember to update distrib/sets/lists/base/shl.* when changing
 #
 # things we wish to do on next major version bump:
@@ -31,4 +31,4 @@
 #   it's insufficient bitwidth to implement all ctype class.
 #   see isblank's comment in ctype.h.
 major=12
-minor=174
+minor=175
diff -r 5c813ba07b24 -r 5dc0d799d9f1 lib/libc/time/Makefile.inc
--- a/lib/libc/time/Makefile.inc        Thu Dec 16 18:29:47 2010 +0000
+++ b/lib/libc/time/Makefile.inc        Thu Dec 16 18:36:47 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.13 2009/05/15 02:23:42 jakllsch Exp $
+#      $NetBSD: Makefile.inc,v 1.14 2010/12/16 18:38:07 christos Exp $
 
 .PATH: ${.CURDIR}/time
 
@@ -9,6 +9,7 @@
 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      \
@@ -16,10 +17,17 @@
        ctime.3 gmtime_r.3      \
        ctime.3 localtime.3     \
        ctime.3 localtime_r.3   \
+       ctime.3 localtime_rz.3  \
        ctime.3 mktime.3        \
+       ctime.3 mktime_z.3      \
        getdate.3 getdate_err.3 \
+       offtime.3 offtime_r.3   \
        offtime.3 timeoff.3     \
        offtime.3 timegm.3      \
        offtime.3 timelocal.3   \
+       time2posix.3 posix2time.3 \
+       time2posix.3 posix2time_z.3 \
+       time2posix.3 time2posix_z.3 \
        tzset.3 daylight.3      \
-       tzset.3 tzsetwall.3
+       tzset.3 tzsetwall.3     \
+       strftime.3 strftime_z.3
diff -r 5c813ba07b24 -r 5dc0d799d9f1 lib/libc/time/ctime.3
--- a/lib/libc/time/ctime.3     Thu Dec 16 18:29:47 2010 +0000
+++ b/lib/libc/time/ctime.3     Thu Dec 16 18:36:47 2010 +0000
@@ -1,5 +1,5 @@
-.\"    $NetBSD: ctime.3,v 1.35 2010/12/09 09:22:31 njoly Exp $
-.Dd October 27, 2010
+.\" $NetBSD: ctime.3,v 1.36 2010/12/16 18:38:07 christos Exp $
+.Dd December 14, 2010
 .Dt CTIME 3
 .Os
 .Sh NAME
@@ -7,22 +7,30 @@
 .Nm asctime_r ,
 .Nm ctime ,
 .Nm ctime_r ,
+.Nm ctime_rz ,
 .Nm difftime ,
 .Nm gmtime ,
 .Nm gmtime_r ,
 .Nm localtime ,
 .Nm localtime_r ,
-.Nm mktime
+.Nm localtime_rz ,
+.Nm mktime ,
+.Nm mktime_z ,
+.Nm tzalloc ,
+.Nm tzgetname ,
+.Nm tzfree ,
 .Nd convert date and time to ASCII
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
 .In time.h
-.Vt extern char *tzname[2];
+.Dv extern char *tzname[2];
 .Ft char *
 .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 char *
@@ -34,15 +42,25 @@
 .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"
+.Ft struct tm *
 .Fn gmtime "const time_t *clock"
 .Ft struct tm *
 .Fn gmtime_r "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"
+.Ft timezone_t
+.Fn tzalloc "const char *zone"
+.Ft const char *
+.Fn tzgetname "const timezone_t tz" "int isdst"
+.Ft void
+.Fn tzfree "const timezone_t tz"
 .Sh DESCRIPTION
 .Fn ctime
-converts a
-.Vt time_t ,
+converts a 
+.Tp time_t ,
 pointed to by
 .Fa clock ,
 representing the time in seconds since
@@ -61,11 +79,19 @@
 .Fn ctime_r
 is similar to
 .Fn ctime ,
-except it places the result of the conversion on the
+except it places the result of the convertion on the
 .Fa buf
 argument which should be 26 or more bytes long, instead of using a global
 static buffer.
 .Pp
+.Fn ctime_rz
+is similar to
+.Fn ctime_r ,
+but it also takes a
+.Ft "const timezone_t"
+argument, returned by a previous call to
+.Fn tzalloc .
+.Pp
 .Fn localtime
 and
 .Fn gmtime
@@ -107,10 +133,17 @@
 the application may need to do so by calling
 .Xr tzset 3 .
 .Pp
+.Fn localtime_rz
+is similar to
+.Fn localtime_r ,
+but it also takes a
+.Ft "const timezone_t"
+argument, returned by a previous call to
+.Fn tzalloc .
+.Pp
 .Fn asctime
 converts a time value contained in a
-.Dq tm
-structure to a string,
+``tm'' structure to a string,
 as shown in the above example,
 and returns a pointer to the string.
 .Pp
@@ -163,11 +196,60 @@
 represented, it returns
 .Va "(time_t)-1" .
 .Pp
+.Fn mktime_z
+is similar to
+.Fn mktime
+but it also takes a
+.Ft "const timezone_t"



Home | Main Index | Thread Index | Old Index