- Moved the common DateStamp to time_t conversion code into a shared

function.

- The fall-back function for converting time into a string in strftime()
  now calls itself for the "%x" and "%X" format specifiers.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14809 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-01-24 10:25:46 +00:00
parent e1476c15b3
commit d1aaa84bcc
13 changed files with 63 additions and 131 deletions
+2 -1
View File
@@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.68k,v 1.20 2005-01-14 09:07:16 obarthel Exp $
# $Id: GNUmakefile.68k,v 1.21 2005-01-24 10:25:46 obarthel Exp $
#
# :ts=8
#
@@ -363,6 +363,7 @@ C_LIB = \
time_asctime_r.o \
time_clock.o \
time_converttime.o \
time_convert_datestamp.o \
time_ctime.o \
time_ctime_r.o \
time_data.o \
+2 -1
View File
@@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.os4,v 1.20 2005-01-10 00:56:15 theantony Exp $
# $Id: GNUmakefile.os4,v 1.21 2005-01-24 10:25:46 obarthel Exp $
#
# :ts=8
#
@@ -365,6 +365,7 @@ C_LIB = \
time_asctime_r.o \
time_clock.o \
time_converttime.o \
time_convert_datestamp.o \
time_ctime.o \
time_ctime_r.o \
time_data.o \
+6
View File
@@ -3,6 +3,12 @@
happen and is a side-effect of the new stdio initialization code which
checks if the stdio streams are in non-blocking mode. Fixed.
- Moved the common DateStamp to time_t conversion code into a shared
function.
- The fall-back function for converting time into a string in strftime()
now calls itself for the "%x" and "%X" format specifiers.
c.lib 1.186 (14.1.2005)
+4 -1
View File
@@ -1,5 +1,5 @@
/*
* $Id: macros.h,v 1.5 2005-01-12 09:15:50 obarthel Exp $
* $Id: macros.h,v 1.6 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -60,6 +60,9 @@
/****************************************************************************/
/* This is the difference (in seconds) between the Unix epoch (which began
on January 1st, 1970) and the AmigaOS epoch (which began eight years
later on January 1st 1978). */
#define UNIX_TIME_OFFSET 252460800
/****************************************************************************/
+2 -1
View File
@@ -1,5 +1,5 @@
#
# $Id: smakefile,v 1.15 2004-12-26 10:28:56 obarthel Exp $
# $Id: smakefile,v 1.16 2005-01-24 10:25:46 obarthel Exp $
#
# :ts=8
#
@@ -471,6 +471,7 @@ TIME_OBJ = \
time_asctime_r.o \
time_clock.o \
time_converttime.o \
time_convert_datestamp.o \
time_ctime.o \
time_ctime_r.o \
time_data.o \
+6 -4
View File
@@ -1,5 +1,5 @@
/*
* $Id: stat_convertfileinfo.c,v 1.4 2005-01-02 09:07:08 obarthel Exp $
* $Id: stat_convertfileinfo.c,v 1.5 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -39,6 +39,10 @@
#include "locale_headers.h"
#endif /* _LOCALE_HEADERS_H */
#ifndef _TIME_HEADERS_H
#include "time_headers.h"
#endif /* _TIME_HEADERS_H */
/****************************************************************************/
void
@@ -109,9 +113,7 @@ __convert_file_info_to_stat(
if(FLAG_IS_SET(flags,FIBF_OTR_EXECUTE))
SET_FLAG(mode,S_IXOTH);
mtime = UNIX_TIME_OFFSET + fib->fib_Date.ds_Days * 24*60*60 + fib->fib_Date.ds_Minute * 60 + (fib->fib_Date.ds_Tick / TICKS_PER_SECOND);
if(__default_locale != NULL)
mtime += 60 * __default_locale->loc_GMTOffset;
mtime = __convert_datestamp_to_time(&fib->fib_Date);
if(fib->fib_DirEntryType < 0)
{
+6 -4
View File
@@ -1,5 +1,5 @@
/*
* $Id: stat_stat.c,v 1.3 2005-01-02 09:07:08 obarthel Exp $
* $Id: stat_stat.c,v 1.4 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -45,6 +45,10 @@
#include "locale_headers.h"
#endif /* _LOCALE_HEADERS_H */
#ifndef _TIME_HEADERS_H
#include "time_headers.h"
#endif /* _TIME_HEADERS_H */
/****************************************************************************/
/* The following is not part of the ISO 'C' (1994) standard. */
@@ -108,9 +112,7 @@ stat(const char * path_name, struct stat * st)
DateStamp(&ds);
PROFILE_ON();
mtime = UNIX_TIME_OFFSET + ds.ds_Days * 24*60*60 + ds.ds_Minute * 60 + (ds.ds_Tick / TICKS_PER_SECOND);
if(__default_locale != NULL)
mtime += 60 * __default_locale->loc_GMTOffset;
mtime = __convert_datestamp_to_time(&ds);
st->st_mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
st->st_mtime = mtime;
+9 -1
View File
@@ -1,5 +1,5 @@
/*
* $Id: time_gettimeofday.c,v 1.4 2005-01-08 10:21:25 obarthel Exp $
* $Id: time_gettimeofday.c,v 1.5 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -70,11 +70,17 @@ gettimeofday(struct timeval *tp, struct timezone *tzp)
ENTER();
/* Obtain the current system time. */
GetSysTime(&tv);
/* Convert the number of seconds so that they match the Unix epoch, which
starts (January 1st, 1970) eight years before the AmigaOS epoch. */
seconds = tv.tv_sec + UNIX_TIME_OFFSET;
microseconds = tv.tv_usec;
/* If possible, adjust for the local time zone. We do this because the
AmigaOS system time is returned in local time and we want to return
it in UTC. */
if(__default_locale != NULL)
seconds += 60 * __default_locale->loc_GMTOffset;
@@ -94,6 +100,8 @@ gettimeofday(struct timeval *tp, struct timezone *tzp)
else
tzp->tz_minuteswest = 0;
/* The -1 means "we do not know if the time given is in
daylight savings time". */
tzp->tz_dsttime = -1;
SHOWVALUE(tzp->tz_minuteswest);
+2 -1
View File
@@ -1,5 +1,5 @@
/*
* $Id: time_headers.h,v 1.5 2005-01-02 09:07:19 obarthel Exp $
* $Id: time_headers.h,v 1.6 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -94,6 +94,7 @@ extern const char * const NOCOMMON __month_names[12];
extern char * __asctime_r(const struct tm *tm,char * buffer,size_t buffer_size);
extern char * __number_to_string(unsigned int number,char * string,size_t max_len,size_t min_len);
extern struct tm * __convert_time(ULONG seconds, LONG gmt_offset, struct tm * tm);
extern time_t __convert_datestamp_to_time(const struct DateStamp * ds);
/****************************************************************************/
+7 -8
View File
@@ -1,5 +1,5 @@
/*
* $Id: time_mktime.c,v 1.2 2005-01-02 09:07:19 obarthel Exp $
* $Id: time_mktime.c,v 1.3 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -100,14 +100,12 @@ mktime(struct tm *tm)
int year;
/* We need to have the full year number for the
* leap year calculation below.
*/
leap year calculation below. */
year = tm->tm_year + 1900;
/* Now for the famous leap year calculation rules... We
* need to find out if the number of days in the month
* of February are appropriate for the data given.
*/
need to find out if the number of days in the month
of February are appropriate for the data given. */
if((year % 4) != 0)
max_month_days = 28;
else if ((year % 400) == 0)
@@ -177,8 +175,7 @@ mktime(struct tm *tm)
seconds = Date2Amiga(&clock_data);
/* The AmigaOS "epoch" starts with January 1st, 1978, which was
* a Sunday.
*/
a Sunday. */
tm->tm_wday = (seconds / (24 * 60 * 60)) % 7;
clock_data.mday = 1;
@@ -188,6 +185,8 @@ mktime(struct tm *tm)
tm->tm_yday = (seconds - delta) / (24 * 60 * 60);
/* Finally, adjust for the difference between the Unix and the
AmigaOS epochs, which differ by 8 years. */
result = seconds + UNIX_TIME_OFFSET;
error = 0;
+4 -97
View File
@@ -1,5 +1,5 @@
/*
* $Id: time_strftime.c,v 1.2 2005-01-02 09:07:19 obarthel Exp $
* $Id: time_strftime.c,v 1.3 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -207,55 +207,7 @@ format_date(const char *format,const struct tm *tm,time_t time_value,struct Hook
/* Locale specific date and time ("%a %b %d %H:%M:%S %Y"). */
case 'c':
assert( 0 <= tm->tm_wday && tm->tm_wday <= 6 );
if(0 <= tm->tm_wday && tm->tm_wday <= 6)
str = __abbreviated_week_day_names[tm->tm_wday];
else
str = "-";
store_string_via_hook(str,-1,hook);
store_string_via_hook(" ",1,hook);
assert( 0 <= tm->tm_mon && tm->tm_mon <= 11 );
if(0 <= tm->tm_mon && tm->tm_mon <= 11)
str = __abbreviated_month_names[tm->tm_mon];
else
str = "-";
store_string_via_hook(str,-1,hook);
store_string_via_hook(" ",1,hook);
assert( 1 <= tm->tm_mday && tm->tm_mday <= 31 );
__number_to_string((unsigned int)tm->tm_mday,buffer,sizeof(buffer),2);
store_string_via_hook(buffer,2,hook);
store_string_via_hook(" ",1,hook);
assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 );
__number_to_string((unsigned int)tm->tm_hour,buffer,sizeof(buffer),2);
store_string_via_hook(buffer,2,hook);
store_string_via_hook(":",1,hook);
assert( 0 <= tm->tm_min && tm->tm_min <= 59 );
__number_to_string((unsigned int)tm->tm_min,buffer,sizeof(buffer),2);
store_string_via_hook(buffer,2,hook);
store_string_via_hook(":",1,hook);
assert( 0 <= tm->tm_sec && tm->tm_sec <= 59 );
__number_to_string((unsigned int)tm->tm_sec,buffer,sizeof(buffer),2);
store_string_via_hook(buffer,2,hook);
store_string_via_hook(" ",1,hook);
assert( 0 <= tm->tm_year );
__number_to_string((unsigned int)1900 + tm->tm_year,buffer,sizeof(buffer),0);
store_string_via_hook(buffer,-1,hook);
format_date("%a %b %d %H:%M:%S %Y",tm,time_value,hook);
break;
/* Day of the month ("01"-"31"). */
@@ -414,58 +366,13 @@ format_date(const char *format,const struct tm *tm,time_t time_value,struct Hook
/* Locale-specific date ("%a %b %d, %Y"). */
case 'x':
assert( 0 <= tm->tm_wday && tm->tm_wday <= 6 );
if(0 <= tm->tm_wday && tm->tm_wday <= 6)
str = __abbreviated_week_day_names[tm->tm_wday];
else
str = "-";
store_string_via_hook(str,-1,hook);
store_string_via_hook(" ",1,hook);
assert( 0 <= tm->tm_mon && tm->tm_mon <= 11 );
if(0 <= tm->tm_mon && tm->tm_mon <= 11)
str = __abbreviated_month_names[tm->tm_mon];
else
str = "-";
store_string_via_hook(str,-1,hook);
store_string_via_hook(" ",1,hook);
assert( 1 <= tm->tm_mday && tm->tm_mday <= 31 );
__number_to_string((unsigned int)tm->tm_mday,buffer,sizeof(buffer),2);
store_string_via_hook(buffer,2,hook);
store_string_via_hook(", ",2,hook);
assert( 0 <= tm->tm_year );
__number_to_string((unsigned int)1900 + tm->tm_year,buffer,sizeof(buffer),0);
store_string_via_hook(buffer,-1,hook);
format_date("%a %b %d, %Y",tm,time_value,hook);
break;
/* Locale-specific time ("%H:%M:%S"). */
case 'X':
assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 );
__number_to_string((unsigned int)tm->tm_hour,buffer,sizeof(buffer),2);
store_string_via_hook(buffer,2,hook);
store_string_via_hook(":",1,hook);
assert( 0 <= tm->tm_min && tm->tm_min <= 59 );
__number_to_string((unsigned int)tm->tm_min,buffer,sizeof(buffer),2);
store_string_via_hook(buffer,2,hook);
store_string_via_hook(":",1,hook);
assert( 0 <= tm->tm_sec && tm->tm_sec <= 59 );
__number_to_string((unsigned int)tm->tm_sec,buffer,sizeof(buffer),2);
store_string_via_hook(buffer,2,hook);
format_date("%H:%M:%S",tm,time_value,hook);
break;
/* Year without century ("00"-"99"). */
+4 -11
View File
@@ -1,5 +1,5 @@
/*
* $Id: time_time.c,v 1.2 2005-01-02 09:07:19 obarthel Exp $
* $Id: time_time.c,v 1.3 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -45,22 +45,15 @@ time_t
time(time_t * tptr)
{
struct DateStamp ds;
ULONG seconds;
time_t result;
PROFILE_OFF();
DateStamp(&ds);
PROFILE_ON();
seconds = 60 * ((ULONG)ds.ds_Minute + 24 * 60 * (ULONG)ds.ds_Days) + (ds.ds_Tick / TICKS_PER_SECOND);
/* time() should try to return the current time in UTC form. Thus,
* we have to take the local time zone into account.
*/
if(__default_locale != NULL)
result = UNIX_TIME_OFFSET + seconds + 60 * __default_locale->loc_GMTOffset;
else
result = UNIX_TIME_OFFSET + seconds;
/* This converts the DateStamp contents into the number of
seconds elapsed since January 1st 1970. */
result = __convert_datestamp_to_time(&ds);
if(tptr != NULL)
(*tptr) = result;
+9 -1
View File
@@ -1,5 +1,5 @@
/*
* $Id: utime_utime.c,v 1.3 2005-01-02 09:07:19 obarthel Exp $
* $Id: utime_utime.c,v 1.4 2005-01-24 10:25:46 obarthel Exp $
*
* :ts=4
*
@@ -76,20 +76,26 @@ utime(const char * path_name,const struct utimbuf * times)
if(__check_abort_enabled)
__check_abort();
/* If a modification time is provided, convert it into the local
DateStamp format, as used by the SetFileDate() function. */
if(times != NULL)
{
time_t seconds;
seconds = times->modtime;
/* The modification time has to lie within the AmigaOS epoch. */
if(seconds < UNIX_TIME_OFFSET)
{
errno = EINVAL;
goto out;
}
/* Adjust the modification time to the AmigaOS epoch. */
seconds -= UNIX_TIME_OFFSET;
/* If possible, adjust the modification time to match the
local time zone settings. */
if(__default_locale != NULL)
seconds -= 60 * __default_locale->loc_GMTOffset;
@@ -99,6 +105,8 @@ utime(const char * path_name,const struct utimbuf * times)
}
else
{
/* No special modification time provided; use the current
time instead. */
DateStamp(&ds);
}