240 lines
6.8 KiB
Diff
240 lines
6.8 KiB
Diff
Description: add GNU extensions for struct tm.
|
|
This might be incomplete.
|
|
Omly localtime() and gmtime() work.
|
|
Index: libc/usr/src/head/iso/time_iso.h
|
|
===================================================================
|
|
--- libc.orig/usr/src/head/iso/time_iso.h
|
|
+++ libc/usr/src/head/iso/time_iso.h
|
|
@@ -45,7 +45,7 @@
|
|
|
|
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.18 */
|
|
|
|
-#include <sys/feature_tests.h>
|
|
+#include <features.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
@@ -94,6 +94,13 @@ struct tm { /* see ctime(3) */
|
|
int tm_wday;
|
|
int tm_yday;
|
|
int tm_isdst;
|
|
+#if defined (_BSD_SOURCE)
|
|
+ long tm_gmtoff;
|
|
+ const char *tm_zone;
|
|
+#else
|
|
+ long __tm_gmtoff;
|
|
+ const char *__tm_zone;
|
|
+#endif
|
|
};
|
|
|
|
|
|
Index: libc/usr/src/head/time.h
|
|
===================================================================
|
|
--- libc.orig/usr/src/head/time.h
|
|
+++ libc/usr/src/head/time.h
|
|
@@ -33,7 +33,7 @@
|
|
#ifndef _TIME_H
|
|
#define _TIME_H
|
|
|
|
-#include <sys/feature_tests.h>
|
|
+#include <features.h>
|
|
#include <iso/time_iso.h>
|
|
#if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
|
|
(_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)
|
|
@@ -80,10 +80,21 @@ typedef int timer_t;
|
|
#if defined(__EXTENSIONS__) || \
|
|
(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
|
|
(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
|
|
+extern struct tm *__gnu_gmtime_r(const time_t *_RESTRICT_KYWD,
|
|
+ struct tm *_RESTRICT_KYWD);
|
|
+extern struct tm *__gnu_localtime_r(const time_t *_RESTRICT_KYWD,
|
|
+ struct tm *_RESTRICT_KYWD);
|
|
+#ifdef __PRAGMA_REDEFINE_EXTNAME
|
|
+#pragma redefine_extname gmtime_r __gnu_gmtime_r
|
|
+#pragma redefine_extname localtime_r __gnu_localtime_r
|
|
extern struct tm *gmtime_r(const time_t *_RESTRICT_KYWD,
|
|
struct tm *_RESTRICT_KYWD);
|
|
extern struct tm *localtime_r(const time_t *_RESTRICT_KYWD,
|
|
struct tm *_RESTRICT_KYWD);
|
|
+#else /* __PRAGMA_REDEFINE_EXTNAME */
|
|
+#define gmtime_r __gnu_gmtime_r
|
|
+#define localtime_r __gnu_localtime_r
|
|
+#endif /* __PRAGMA_REDEFINE_EXTNAME */
|
|
#endif
|
|
|
|
#if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
|
|
Index: libc/usr/src/lib/libc/port/gen/localtime.c
|
|
===================================================================
|
|
--- libc.orig/usr/src/lib/libc/port/gen/localtime.c
|
|
+++ libc/usr/src/lib/libc/port/gen/localtime.c
|
|
@@ -117,6 +117,9 @@
|
|
#include <sys/stat.h>
|
|
#include <sys/mman.h>
|
|
|
|
+#undef gmtime_r
|
|
+#undef localtime_r
|
|
+
|
|
/* JAN_01_1902 cast to (int) - negative number of seconds from 1970 */
|
|
#define JAN_01_1902 (int)0x8017E880
|
|
#define LEN_TZDIR (sizeof (TZDIR) - 1)
|
|
@@ -488,6 +491,14 @@ gmtime_r(const time_t *timep, struct tm
|
|
return (offtime_u((time_t)*timep, 0L, p_tm));
|
|
}
|
|
|
|
+struct tm *
|
|
+__gnu_gmtime_r(const time_t *timep, struct tm *p_tm)
|
|
+{
|
|
+ p_tm->tm_gmtoff = 0;
|
|
+ p_tm->tm_zone = _tz_gmt;
|
|
+ return (offtime_u((time_t)*timep, 0L, p_tm));
|
|
+}
|
|
+
|
|
/*
|
|
* Accepts a time_t, returns a tm struct based on it, with
|
|
* no local timezone adjustment.
|
|
@@ -507,7 +518,7 @@ gmtime(const time_t *timep)
|
|
|
|
if (p_tm == NULL) /* memory allocation failure */
|
|
p_tm = &tm; /* use static buffer and hope for the best */
|
|
- return (gmtime_r(timep, p_tm));
|
|
+ return (__gnu_gmtime_r(timep, p_tm));
|
|
}
|
|
|
|
/*
|
|
@@ -649,6 +660,34 @@ localtime_r(const time_t *timep, struct
|
|
return (rt);
|
|
}
|
|
|
|
+struct tm *
|
|
+__gnu_localtime_r(const time_t *timep, struct tm *p_tm)
|
|
+{
|
|
+ long offset;
|
|
+ struct tm *rt;
|
|
+ void *unused;
|
|
+ int my_is_in_dst;
|
|
+
|
|
+ lmutex_lock(&_time_lock);
|
|
+ unused = ltzset_u(*timep);
|
|
+ if (lclzonep == NULL) {
|
|
+ lmutex_unlock(&_time_lock);
|
|
+ if (unused != NULL)
|
|
+ free(unused);
|
|
+ return (offtime_u(*timep, 0L, p_tm));
|
|
+ }
|
|
+ my_is_in_dst = is_in_dst;
|
|
+ offset = (my_is_in_dst) ? -altzone : -timezone;
|
|
+ p_tm->tm_gmtoff = offset;
|
|
+ p_tm->tm_zone = tzname[0];
|
|
+ lmutex_unlock(&_time_lock);
|
|
+ if (unused != NULL)
|
|
+ free(unused);
|
|
+ rt = offtime_u(*timep, offset, p_tm);
|
|
+ p_tm->tm_isdst = my_is_in_dst;
|
|
+ return (rt);
|
|
+}
|
|
+
|
|
/*
|
|
* Accepts a time_t, returns a tm struct based on it, correcting
|
|
* for the local timezone. Produces documented side-effects to
|
|
@@ -673,7 +712,7 @@ localtime(const time_t *timep)
|
|
|
|
if (p_tm == NULL) /* memory allocation failure */
|
|
p_tm = &tm; /* use static buffer and hope for the best */
|
|
- return (localtime_r(timep, p_tm));
|
|
+ return (__gnu_localtime_r(timep, p_tm));
|
|
}
|
|
|
|
/*
|
|
Index: libc/usr/src/head/iso/wchar_iso.h
|
|
===================================================================
|
|
--- libc.orig/usr/src/head/iso/wchar_iso.h
|
|
+++ libc/usr/src/head/iso/wchar_iso.h
|
|
@@ -41,7 +41,7 @@
|
|
|
|
#pragma ident "%Z%%M% %I% %E% SMI"
|
|
|
|
-#include <sys/feature_tests.h>
|
|
+#include <features.h>
|
|
#include <stdio_tag.h>
|
|
#include <wchar_impl.h>
|
|
#include <iso/time_iso.h>
|
|
Index: libc/usr/src/lib/libc/port/mapfile-vers
|
|
===================================================================
|
|
--- libc.orig/usr/src/lib/libc/port/mapfile-vers
|
|
+++ libc/usr/src/lib/libc/port/mapfile-vers
|
|
@@ -120,6 +120,8 @@ SYMBOL_VERSION ILLUMOS_0.4 { # Illumos a
|
|
|
|
SYMBOL_VERSION DYSON_1 {
|
|
global:
|
|
+ __gnu_gmtime_r;
|
|
+ __gnu_localtime_r;
|
|
_so_accept4;
|
|
cfmakeraw;
|
|
error;
|
|
Index: libc/usr/src/lib/libc/port/gen/cftime.c
|
|
===================================================================
|
|
--- libc.orig/usr/src/lib/libc/port/gen/cftime.c
|
|
+++ libc/usr/src/lib/libc/port/gen/cftime.c
|
|
@@ -76,7 +76,7 @@ cftime(char *buf, char *format, const ti
|
|
struct tm res;
|
|
struct tm *p;
|
|
|
|
- p = localtime_r(t, &res);
|
|
+ p = __gnu_localtime_r(t, &res);
|
|
if (p == NULL) {
|
|
*buf = '\0';
|
|
return (0);
|
|
Index: libc/usr/src/lib/libc/port/gen/ctime_r.c
|
|
===================================================================
|
|
--- libc.orig/usr/src/lib/libc/port/gen/ctime_r.c
|
|
+++ libc/usr/src/lib/libc/port/gen/ctime_r.c
|
|
@@ -86,6 +86,8 @@
|
|
#include "libc.h"
|
|
|
|
|
|
+/* TODO: __gnu_localtime_r is not actually used here. */
|
|
+
|
|
/*
|
|
* POSIX.1c Draft-6 version of the function ctime_r.
|
|
* It was implemented by Solaris 2.3.
|
|
@@ -95,7 +97,7 @@ ctime_r(const time_t *t, char *buffer, i
|
|
{
|
|
struct tm res;
|
|
|
|
- if (localtime_r(t, &res) == NULL)
|
|
+ if (__gnu_localtime_r(t, &res) == NULL)
|
|
return (NULL);
|
|
|
|
if (asctime_r(&res, buffer, buflen) == NULL)
|
|
@@ -113,7 +115,7 @@ __posix_ctime_r(const time_t *t, char *b
|
|
{
|
|
struct tm res;
|
|
|
|
- if (localtime_r(t, &res) == NULL)
|
|
+ if (__gnu_localtime_r(t, &res) == NULL)
|
|
return (NULL);
|
|
|
|
if (__posix_asctime_r(&res, buffer) == NULL)
|
|
Index: libc/usr/src/lib/libc/port/locale/strptime.c
|
|
===================================================================
|
|
--- libc.orig/usr/src/lib/libc/port/locale/strptime.c
|
|
+++ libc/usr/src/lib/libc/port/locale/strptime.c
|
|
@@ -419,7 +419,7 @@ label:
|
|
}
|
|
errno = sverrno;
|
|
buf = cp;
|
|
- (void) gmtime_r(&t, tm);
|
|
+ (void) __gnu_gmtime_r(&t, tm);
|
|
*flagsp |= F_GMT;
|
|
}
|
|
break;
|
|
@@ -511,7 +511,7 @@ label:
|
|
if (!recurse) {
|
|
if (buf && (*flagsp & F_GMT)) {
|
|
time_t t = timegm(tm);
|
|
- (void) localtime_r(&t, tm);
|
|
+ (void) __gnu_localtime_r(&t, tm); /* TODO: not actually used here. */
|
|
}
|
|
}
|
|
|