diff options
author | Anatol Belski <ab@php.net> | 2018-04-30 12:02:47 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2018-04-30 12:02:47 +0200 |
commit | f603ab57fc7f7c645cda3db7cf498f48114b8b7c (patch) | |
tree | 0fc49c909596bd14d3b5f8d890eac879265308ec /ext/fileinfo/libmagic | |
parent | 26b0385df8ca32f31647b5c12ba1036b75508315 (diff) | |
download | php-git-f603ab57fc7f7c645cda3db7cf498f48114b8b7c.tar.gz |
Reuse the struct timespec based pieces in libmagic
Diffstat (limited to 'ext/fileinfo/libmagic')
-rw-r--r-- | ext/fileinfo/libmagic/cdf.h | 8 | ||||
-rw-r--r-- | ext/fileinfo/libmagic/cdf_time.c | 13 | ||||
-rw-r--r-- | ext/fileinfo/libmagic/print.c | 4 | ||||
-rw-r--r-- | ext/fileinfo/libmagic/readcdf.c | 9 |
4 files changed, 14 insertions, 20 deletions
diff --git a/ext/fileinfo/libmagic/cdf.h b/ext/fileinfo/libmagic/cdf.h index 82777a0919..c156d6e06a 100644 --- a/ext/fileinfo/libmagic/cdf.h +++ b/ext/fileinfo/libmagic/cdf.h @@ -37,8 +37,6 @@ #ifdef PHP_WIN32 #include <winsock2.h> -#define timespec timeval -#define tv_nsec tv_usec #define asctime_r php_asctime_r #define ctime_r php_ctime_r #endif @@ -283,9 +281,9 @@ typedef struct { cdf_catalog_entry_t cat_e[1]; } cdf_catalog_t; -struct timeval; -int cdf_timestamp_to_timespec(struct timeval *, cdf_timestamp_t); -int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timeval *); +struct timespec; +int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t); +int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timespec *); int cdf_read_header(const cdf_info_t *, cdf_header_t *); void cdf_swap_header(cdf_header_t *); void cdf_unpack_header(cdf_header_t *, char *); diff --git a/ext/fileinfo/libmagic/cdf_time.c b/ext/fileinfo/libmagic/cdf_time.c index 1ede68544e..795c843605 100644 --- a/ext/fileinfo/libmagic/cdf_time.c +++ b/ext/fileinfo/libmagic/cdf_time.c @@ -96,7 +96,7 @@ cdf_getmonth(int year, int days) } int -cdf_timestamp_to_timespec(struct timeval *ts, cdf_timestamp_t t) +cdf_timestamp_to_timespec(struct timespec *ts, cdf_timestamp_t t) { struct tm tm; #ifdef HAVE_STRUCT_TM_TM_ZONE @@ -104,9 +104,8 @@ cdf_timestamp_to_timespec(struct timeval *ts, cdf_timestamp_t t) #endif int rdays; - /* XXX 5.14 at least introdced 100 ns intervals, this is to do */ - /* Time interval, in microseconds */ - ts->tv_usec = (t % CDF_TIME_PREC) * CDF_TIME_PREC; + /* Unit is 100's of nanoseconds */ + ts->tv_nsec = (t % CDF_TIME_PREC) * 100; t /= CDF_TIME_PREC; tm.tm_sec = (int)(t % 60); @@ -145,7 +144,7 @@ cdf_timestamp_to_timespec(struct timeval *ts, cdf_timestamp_t t) int /*ARGSUSED*/ -cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timeval *ts) +cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timespec *ts) { #ifndef __lint__ (void)&t; @@ -157,7 +156,7 @@ cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timeval *ts) errno = EINVAL; return -1; } - *t = (ts->ts_usec / CDF_TIME_PREC) * CDF_TIME_PREC; + *t = (ts->ts_nsec / 100) * CDF_TIME_PREC; *t = tm.tm_sec; *t += tm.tm_min * 60; *t += tm.tm_hour * 60 * 60; @@ -182,7 +181,7 @@ cdf_ctime(const time_t *sec, char *buf) int main(int argc, char *argv[]) { - struct timeval ts; + struct timespec ts; char buf[25]; static const cdf_timestamp_t tst = 0x01A5E403C2D59C00ULL; static const char *ref = "Sat Apr 23 01:30:00 1977"; diff --git a/ext/fileinfo/libmagic/print.c b/ext/fileinfo/libmagic/print.c index 1c01518017..9d0121b908 100644 --- a/ext/fileinfo/libmagic/print.c +++ b/ext/fileinfo/libmagic/print.c @@ -244,8 +244,8 @@ file_fmttime(uint64_t v, int flags, char *buf) struct tm *tm = NULL; if (flags & FILE_T_WINDOWS) { - struct timeval ts; - cdf_timestamp_to_timespec(&ts, t); + struct timespec ts; + cdf_timestamp_to_timespec(&ts, CAST(cdf_timestamp_t, v)); t = ts.tv_sec; } else { // XXX: perhaps detect and print something if overflow diff --git a/ext/fileinfo/libmagic/readcdf.c b/ext/fileinfo/libmagic/readcdf.c index 5f67632f50..4a3ddc60ff 100644 --- a/ext/fileinfo/libmagic/readcdf.c +++ b/ext/fileinfo/libmagic/readcdf.c @@ -133,7 +133,7 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, { size_t i; cdf_timestamp_t tp; - struct timeval ts; + struct timespec ts; char buf[64]; const char *str = NULL; const char *s, *e; @@ -220,11 +220,8 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, return -1; } else { char *c, *ec; - const time_t sec = ts.tv_sec; - if (cdf_timestamp_to_timespec(&ts, tp) == -1) { - return -1; - } - c = cdf_ctime(&sec, tbuf); + cdf_timestamp_to_timespec(&ts, tp); + c = cdf_ctime(&ts.tv_sec, tbuf); if (c != NULL && (ec = strchr(c, '\n')) != NULL) *ec = '\0'; |