diff options
author | stoddard <stoddard@13f79535-47bb-0310-9956-ffa450edef68> | 2000-01-17 04:42:27 +0000 |
---|---|---|
committer | stoddard <stoddard@13f79535-47bb-0310-9956-ffa450edef68> | 2000-01-17 04:42:27 +0000 |
commit | 579df71756c2f6bc5b42adb6932fa5ea84f39c7e (patch) | |
tree | 939f8663e9314c7dca40f965c763259a87ee11cc | |
parent | 281a8b2e787caee23a8c6984f77610a587826ac2 (diff) | |
download | libapr-579df71756c2f6bc5b42adb6932fa5ea84f39c7e.tar.gz |
Reimplement Win32 time functions to the new spec.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@59600 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | aprlib.def | 71 | ||||
-rw-r--r-- | libapr.def | 71 | ||||
-rw-r--r-- | time/win32/time.c | 185 |
3 files changed, 205 insertions, 122 deletions
diff --git a/aprlib.def b/aprlib.def index dc3ea2d6b..0506711ef 100644 --- a/aprlib.def +++ b/aprlib.def @@ -15,11 +15,12 @@ EXPORTS ap_dir_entry_mtime @8 ap_dir_entry_ftype @9 ap_get_dir_filename @10 - ap_get_filename @11 - ap_get_filesize @12 - ap_get_fileatime @13 - ap_get_filectime @14 - ap_get_filemtime @15 +; ap_get_filename @11 + ap_stat @11 +; ap_get_filesize @12 +; ap_get_fileatime @13 +; ap_get_filectime @14 +; ap_get_filemtime @15 ap_dupfile @16 ap_getfileinfo @17 ap_open @18 @@ -41,7 +42,7 @@ EXPORTS ap_flush @34 ap_fprintf @35 ap_eof @36 - ap_get_filetype @37 +; ap_get_filetype @37 ap_writev @38 ; locks ap_create_lock @39 @@ -132,29 +133,41 @@ EXPORTS ap_optopt @124 DATA ap_optreset @125 DATA ap_optarg @126 DATA - ap_make_time @127 - ap_current_time @128 - ap_explode_time @129 - ap_implode_time @130 - ap_get_curtime @131 - ap_get_sec @132 - ap_get_min @133 - ap_get_hour @134 - ap_get_mday @135 - ap_get_mon @136 - ap_get_year @137 - ap_get_wday @138 - ap_set_sec @139 - ap_set_min @140 - ap_set_hour @141 - ap_set_mday @142 - ap_set_mon @143 - ap_set_year @144 - ap_set_wday @145 - ap_get_timedata @146 - ap_set_timedata @147 - ap_get_os_time @148 - ap_timediff @149 +; ap_make_time @127 + ap_ansi_time_to_ap_time @127 +; ap_current_time @128 + ap_now @128 +; ap_explode_time @129 + ap_explode_gmt @129 +; ap_implode_time @130 + ap_explode_localtime @130 +; ap_get_curtime @131 + ap_implode_time @131 +; ap_get_sec @132 + ap_get_os_imp_time @132 +; ap_get_min @133 + ap_get_os_exp_time @133 +; ap_get_hour @134 + ap_put_os_imp_time @134 +; ap_get_mday @135 + ap_put_os_exp_time @135 +; ap_get_mon @136 + ap_ctime @136 +; ap_get_year @137 + ap_rfc822_date @137 +; ap_get_wday @138 + ap_strftime @138 +; ap_set_sec @139 +; ap_set_min @140 +; ap_set_hour @141 +; ap_set_mday @142 +; ap_set_mon @143 +; ap_set_year @144 +; ap_set_wday @145 +; ap_get_timedata @146 +; ap_set_timedata @147 +; ap_get_os_time @148 +; ap_timediff @149 ap_MD5Final @150 ap_MD5Init @151 ap_MD5Update @152 diff --git a/libapr.def b/libapr.def index dc3ea2d6b..0506711ef 100644 --- a/libapr.def +++ b/libapr.def @@ -15,11 +15,12 @@ EXPORTS ap_dir_entry_mtime @8 ap_dir_entry_ftype @9 ap_get_dir_filename @10 - ap_get_filename @11 - ap_get_filesize @12 - ap_get_fileatime @13 - ap_get_filectime @14 - ap_get_filemtime @15 +; ap_get_filename @11 + ap_stat @11 +; ap_get_filesize @12 +; ap_get_fileatime @13 +; ap_get_filectime @14 +; ap_get_filemtime @15 ap_dupfile @16 ap_getfileinfo @17 ap_open @18 @@ -41,7 +42,7 @@ EXPORTS ap_flush @34 ap_fprintf @35 ap_eof @36 - ap_get_filetype @37 +; ap_get_filetype @37 ap_writev @38 ; locks ap_create_lock @39 @@ -132,29 +133,41 @@ EXPORTS ap_optopt @124 DATA ap_optreset @125 DATA ap_optarg @126 DATA - ap_make_time @127 - ap_current_time @128 - ap_explode_time @129 - ap_implode_time @130 - ap_get_curtime @131 - ap_get_sec @132 - ap_get_min @133 - ap_get_hour @134 - ap_get_mday @135 - ap_get_mon @136 - ap_get_year @137 - ap_get_wday @138 - ap_set_sec @139 - ap_set_min @140 - ap_set_hour @141 - ap_set_mday @142 - ap_set_mon @143 - ap_set_year @144 - ap_set_wday @145 - ap_get_timedata @146 - ap_set_timedata @147 - ap_get_os_time @148 - ap_timediff @149 +; ap_make_time @127 + ap_ansi_time_to_ap_time @127 +; ap_current_time @128 + ap_now @128 +; ap_explode_time @129 + ap_explode_gmt @129 +; ap_implode_time @130 + ap_explode_localtime @130 +; ap_get_curtime @131 + ap_implode_time @131 +; ap_get_sec @132 + ap_get_os_imp_time @132 +; ap_get_min @133 + ap_get_os_exp_time @133 +; ap_get_hour @134 + ap_put_os_imp_time @134 +; ap_get_mday @135 + ap_put_os_exp_time @135 +; ap_get_mon @136 + ap_ctime @136 +; ap_get_year @137 + ap_rfc822_date @137 +; ap_get_wday @138 + ap_strftime @138 +; ap_set_sec @139 +; ap_set_min @140 +; ap_set_hour @141 +; ap_set_mday @142 +; ap_set_mon @143 +; ap_set_year @144 +; ap_set_wday @145 +; ap_get_timedata @146 +; ap_set_timedata @147 +; ap_get_os_time @148 +; ap_timediff @149 ap_MD5Final @150 ap_MD5Init @151 ap_MD5Update @152 diff --git a/time/win32/time.c b/time/win32/time.c index 571774a0e..e2ad9c18e 100644 --- a/time/win32/time.c +++ b/time/win32/time.c @@ -60,98 +60,155 @@ #include <time.h> #include <errno.h> #include <string.h> +#include <winbase.h> -ap_status_t ap_make_time(struct atime_t **new, ap_context_t *cont) +/* Number of micro-seconds between the beginning of the Windows epoch + * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970) + */ +#define AP_DELTA_EPOCH_IN_USEC 11644473600000000; + +static void FileTimeToAprTime(ap_time_t *result, FILETIME *input) { - (*new) = (struct atime_t *)ap_palloc(cont, sizeof(struct atime_t)); + /* Convert FILETIME one 64 bit number so we can work with it. */ + *result = input->dwHighDateTime; + *result = (*result) << 32; + *result |= input->dwLowDateTime; + *result /= 10; /* Convert from 100 nano-sec periods to micro-seconds. */ + *result -= AP_DELTA_EPOCH_IN_USEC; /* Convert from Windows epoch to Unix epoch */ + //printf("FileTimeToAprTime: aprtime - %I64d\n", *result); + return; +} +static void AprTimeToFileTime(LPFILETIME pft, ap_time_t t) +{ + LONGLONG ll; + //printf("AprTimeToFileTime: aprtime - %I64d\n", t); + t += AP_DELTA_EPOCH_IN_USEC; + ll = t * 10; + pft->dwLowDateTime = (DWORD)ll; + pft->dwHighDateTime = (DWORD) (ll >> 32); + return; +} - if ((*new) == NULL) { - return APR_ENOMEM; - } +static void SystemTimeToAprExpTime(ap_exploded_time_t *xt, SYSTEMTIME *tm) +{ + xt->tm_usec = tm->wMilliseconds * 1000; + xt->tm_sec = tm->wSecond; + xt->tm_min = tm->wMinute; + xt->tm_hour = tm->wHour; + xt->tm_mday = tm->wDay; + xt->tm_mon = tm->wMonth - 1; + xt->tm_year = tm->wYear - 1900; + xt->tm_wday = tm->wDayOfWeek; + xt->tm_yday = 0; /* ToDo: need to compute this */ + xt->tm_isdst = 0; /* ToDo: need to compute this */ + xt->tm_gmtoff = 0; /* ToDo: maybe the caller should set this explicitly */ + return; +} - (*new)->cntxt = cont; - (*new)->currtime = -1; - (*new)->explodedtime = NULL; +ap_status_t ap_ansi_time_to_ap_time(ap_time_t *result, time_t input) +{ + *result = (ap_time_t) input * AP_USEC_PER_SEC; return APR_SUCCESS; } -ap_status_t ap_current_time(struct atime_t *new) +/* Return micro-seconds since the Unix epoch (jan. 1, 1970) */ +ap_time_t ap_now(void) { - if (!new) { - return APR_ENOTIME; - } - if (new->explodedtime == NULL) { - new->explodedtime = (SYSTEMTIME *)ap_palloc(new->cntxt, sizeof(SYSTEMTIME)); - } - GetSystemTime(new->explodedtime); - return APR_SUCCESS; -} + ULONGLONG aprtime = 0; + FILETIME time; + GetSystemTimeAsFileTime(&time); + FileTimeToAprTime(&aprtime, &time); + return aprtime; +} -ap_status_t ap_explode_time(struct atime_t *atime, ap_timetype_e type) +ap_status_t ap_explode_gmt(ap_exploded_time_t *result, ap_time_t input) { - if (!atime || !atime->explodedtime) { - return APR_ENOTIME; - } + FILETIME ft; + SYSTEMTIME st; + AprTimeToFileTime(&ft, input); + FileTimeToSystemTime(&ft, &st); + SystemTimeToAprExpTime(result, &st); + result->tm_gmtoff = 0; return APR_SUCCESS; } -ap_status_t ap_implode_time(struct atime_t *atime) +ap_status_t ap_explode_localtime(ap_exploded_time_t *result, ap_time_t input) { - FILETIME temp; - - if (!atime || !atime->explodedtime) { - return APR_ENOTIME; - } + SYSTEMTIME st; + FILETIME ft, localft; - if (SystemTimeToFileTime(atime->explodedtime, &temp) == 0) { - return APR_EEXIST; - } - atime->currtime = WinTimeToUnixTime(&temp); + AprTimeToFileTime(&ft, input); + FileTimeToLocalFileTime(&ft, &localft); + FileTimeToSystemTime(&localft, &st); + SystemTimeToAprExpTime(result, &st); return APR_SUCCESS; } -ap_status_t ap_get_os_time(ap_os_time_t **atime, struct atime_t *thetime) +ap_status_t ap_implode_time(ap_time_t *t, ap_exploded_time_t *xt) { - if (thetime == NULL) { - return APR_ENOTIME; + int year; + time_t days; + static const int dayoffset[12] = + {306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275}; + + year = xt->tm_year; + + if (year < 70 || ((sizeof(time_t) <= 4) && (year >= 138))) { + return APR_EBADDATE; } - if (thetime->explodedtime == NULL) { - ap_explode_time(thetime, APR_LOCALTIME); + + /* shift new year to 1st March in order to make leap year calc easy */ + + if (xt->tm_mon < 2) + year--; + + /* Find number of days since 1st March 1900 (in the Gregorian calendar). */ + + days = year * 365 + year / 4 - year / 100 + (year / 100 + 3) / 4; + days += dayoffset[xt->tm_mon] + xt->tm_mday - 1; + days -= 25508; /* 1 jan 1970 is 25508 days since 1 mar 1900 */ + + days = ((days * 24 + xt->tm_hour) * 60 + xt->tm_min) * 60 + xt->tm_sec; + + if (days < 0) { + return APR_EBADDATE; } - *atime = thetime->explodedtime; + days -= xt->tm_gmtoff; + *t = days * AP_USEC_PER_SEC + xt->tm_usec; return APR_SUCCESS; } -ap_status_t ap_put_os_time(struct atime_t **thetime, ap_os_time_t *atime, - ap_context_t *cont) +ap_status_t ap_get_os_imp_time(ap_os_imp_time_t **ostime, ap_time_t *aprtime) { - if (cont == NULL) { - return APR_ENOCONT; - } - if (thetime == NULL) { - (*thetime) = (struct atime_t *)ap_palloc(cont, sizeof(struct atime_t)); - (*thetime)->cntxt = cont; - } - (*thetime)->explodedtime = atime; + /* TODO: Consider not passing in pointer to ap_time_t (e.g., call by value) */ + AprTimeToFileTime(*ostime, *aprtime); + return APR_SUCCESS; +} + +ap_status_t ap_get_os_exp_time(ap_os_exp_time_t **ostime, ap_exploded_time_t *aprexptime) +{ + (*ostime)->wYear = aprexptime->tm_year + 1900; + (*ostime)->wMonth = aprexptime->tm_mon + 1; + (*ostime)->wDayOfWeek = aprexptime->tm_wday; + (*ostime)->wDay = aprexptime->tm_mday; + (*ostime)->wHour = aprexptime->tm_hour; + (*ostime)->wMinute = aprexptime->tm_min; + (*ostime)->wSecond = aprexptime->tm_sec; + (*ostime)->wMilliseconds = aprexptime->tm_usec / 1000; + return APR_SUCCESS; +} + +ap_status_t ap_put_os_imp_time(ap_time_t *aprtime, ap_os_imp_time_t **ostime, + ap_context_t *cont) +{ + FileTimeToAprTime(aprtime, *ostime); return APR_SUCCESS; } -ap_status_t ap_timediff(struct atime_t *a, struct atime_t *b, ap_int32_t *rv) +ap_status_t ap_put_os_exp_time(ap_exploded_time_t *aprtime, + ap_os_exp_time_t **ostime, ap_context_t *cont) { - FILETIME fa, fb; - LONGLONG ia = 0, ib = 0; - - SystemTimeToFileTime(a->explodedtime, &fa); - SystemTimeToFileTime(b->explodedtime, &fb); - - ia = fa.dwHighDateTime; - ia = ia << 32; - ia |= fa.dwLowDateTime; - - ib = fb.dwHighDateTime; - ib = ib << 32; - ib |= fb.dwLowDateTime; - - *rv = (int)((ia - ib) / 10000); + SystemTimeToAprExpTime(aprtime, *ostime); return APR_SUCCESS; } + |