summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-06-17 19:19:39 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-06-17 19:19:39 +0000
commit20d8808116d749b626c080b2891c968f163966e6 (patch)
tree844fad9fc34f16b7496356f11855ab5069d8e10c
parenta8041047f4c21c83341bfd1f7cc5c111dd76e0db (diff)
Optionally support the struct tm extension fields.
Add a few misc functions mentioned in time.h. Revert davidm's change regarding using a define for the "/etc/TZ" path, as this is eventually meant to be a configurable extension and not unconditionally supported.
-rw-r--r--include/paths.h1
-rw-r--r--include/time.h8
-rw-r--r--libc/misc/time/Makefile2
-rw-r--r--libc/misc/time/time.c50
4 files changed, 44 insertions, 17 deletions
diff --git a/include/paths.h b/include/paths.h
index 38102d55a..90edcf8fd 100644
--- a/include/paths.h
+++ b/include/paths.h
@@ -67,7 +67,6 @@
#define _PATH_SHADOW "/etc/shadow"
#define _PATH_PASSWD "/etc/passwd"
#define _PATH_GROUP "/etc/group"
-#define _PATH_TZ "/etc/TZ"
/* Provide trailing slash, since mostly used for building pathnames. */
#define _PATH_DEV "/dev/"
diff --git a/include/time.h b/include/time.h
index bd86b40ee..5611defbb 100644
--- a/include/time.h
+++ b/include/time.h
@@ -127,15 +127,15 @@ struct tm
int tm_yday; /* Days in year.[0-365] */
int tm_isdst; /* DST. [-1/0/1]*/
-#if 0
+#ifdef __UCLIBC_HAS_TM_EXTENSIONS__
# ifdef __USE_BSD
long int tm_gmtoff; /* Seconds east of UTC. */
- __const char *tm_zone; /* Timezone abbreviation. */
+ __const char tm_zone[8]; /* Timezone abbreviation. */
# else
long int __tm_gmtoff; /* Seconds east of UTC. */
- __const char *__tm_zone; /* Timezone abbreviation. */
+ __const char __tm_zone[8];/* Timezone abbreviation. */
# endif
-#endif
+#endif /* __UCLIBC_HAS_TM_EXTENSIONS__ */
};
diff --git a/libc/misc/time/Makefile b/libc/misc/time/Makefile
index b187e5555..b5714e511 100644
--- a/libc/misc/time/Makefile
+++ b/libc/misc/time/Makefile
@@ -27,7 +27,7 @@ include $(TOPDIR)Rules.mak
MSRC= time.c
MOBJ= asctime.o asctime_r.o clock.o ctime.o ctime_r.o gmtime.o gmtime_r.o \
localtime.o localtime_r.o mktime.o strftime.o strptime.o tzset.o \
- _time_t2tm.o __time_tm.o _time_mktime.o
+ _time_t2tm.o __time_tm.o _time_mktime.o dysize.o timegm.o
ifeq ($(UCLIBC_HAS_FLOATS),y)
MOBJ += difftime.o
diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c
index ad5abe6a2..8d3cbc3b4 100644
--- a/libc/misc/time/time.c
+++ b/libc/misc/time/time.c
@@ -401,9 +401,9 @@ char *ctime(const time_t *clock)
char *ctime_r(const time_t *clock, char *buf)
{
- struct tm xtms;
+ struct tm xtm;
- return asctime_r(localtime_r(clock, &xtms), buf);
+ return asctime_r(localtime_r(clock, &xtm), buf);
}
#endif
@@ -589,13 +589,12 @@ struct tm *localtime_r(register const time_t *__restrict timer,
*x = *timer + offset;
_time_t2tm(x, days, result);
-
- if (dst) {
- result->tm_isdst = dst;
- break;
- }
- ++dst;
- } while ((result->tm_isdst = tm_isdst(result)) != 0);
+ result->tm_isdst = dst;
+#ifdef __UCLIBC_HAS_TM_EXTENSIONS__
+ result->tm_gmtoff = - _time_tzinfo[dst].gmt_offset;
+ strcpy( (char *)(result->tm_zone), _time_tzinfo[dst].tzname);
+#endif /* __UCLIBC_HAS_TM_EXTENSIONS__ */
+ } while ((++dst < 2) && (result->tm_isdst = tm_isdst(result)) != 0);
TZUNLOCK;
@@ -606,11 +605,16 @@ struct tm *localtime_r(register const time_t *__restrict timer,
/**********************************************************************/
#ifdef L_mktime
+/* Another name for `mktime'. */
+/* time_t timelocal(struct tm *tp) */
+weak_alias(mktime,timelocal);
+
time_t mktime(struct tm *timeptr)
{
return _time_mktime(timeptr, 1);
}
+
#endif
/**********************************************************************/
#ifdef L_strftime
@@ -1538,7 +1542,7 @@ static char *read_TZ_file(char *buf)
size_t todo;
char *p = NULL;
- if ((fd = open(_PATH_TZ, O_RDONLY)) >= 0) {
+ if ((fd = open("/etc/TZ", O_RDONLY)) >= 0) {
todo = TZ_BUFLEN;
p = buf;
do {
@@ -1612,7 +1616,7 @@ void tzset(void)
) || !*e) { /* or set to empty string. */
ILLEGAL: /* TODO: Clean up the following... */
#ifdef __TIME_TZ_OPT_SPEED
- *oldval = 0; /* Set oldval tonnn empty string. */
+ *oldval = 0; /* Set oldval to an empty string. */
#endif /* __TIME_TZ_OPT_SPEED */
s = _time_tzinfo[0].tzname;
*s = 'U';
@@ -1932,6 +1936,16 @@ struct tm *_time_t2tm(const time_t *__restrict timer,
}
/* TODO -- should this be 0? */
p[4] = 0; /* result[8] .. tm_isdst */
+#ifdef __UCLIBC_HAS_TM_EXTENSIONS__
+ result->tm_gmtoff = 0;
+ {
+ register char *s = (char *) result->tm_zone;
+ *s = 'U';
+ *++s = 'T';
+ *++s = 'C';
+ *++s = 0;
+ }
+#endif /* __UCLIBC_HAS_TM_EXTENSIONS__ */
return result;
}
@@ -2041,3 +2055,17 @@ time_t _time_mktime(struct tm *timeptr, int store_on_success)
#endif
/**********************************************************************/
+#ifdef L_dysize
+/* Return the number of days in YEAR. */
+
+int dysize(int year)
+{
+ return __isleap(year) ? 366 : 365;
+}
+
+#endif
+/**********************************************************************/
+/* Like `mktime', but for TP represents Universal Time, not local time. */
+/* time_t timegm(struct tm *tp) */
+
+