mirror of
https://github.com/php/php-src.git
synced 2025-08-19 17:04:47 +02:00
Reuse the struct timespec based pieces in libmagic
This commit is contained in:
parent
26b0385df8
commit
f603ab57fc
4 changed files with 14 additions and 20 deletions
|
@ -37,8 +37,6 @@
|
||||||
|
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#define timespec timeval
|
|
||||||
#define tv_nsec tv_usec
|
|
||||||
#define asctime_r php_asctime_r
|
#define asctime_r php_asctime_r
|
||||||
#define ctime_r php_ctime_r
|
#define ctime_r php_ctime_r
|
||||||
#endif
|
#endif
|
||||||
|
@ -283,9 +281,9 @@ typedef struct {
|
||||||
cdf_catalog_entry_t cat_e[1];
|
cdf_catalog_entry_t cat_e[1];
|
||||||
} cdf_catalog_t;
|
} cdf_catalog_t;
|
||||||
|
|
||||||
struct timeval;
|
struct timespec;
|
||||||
int cdf_timestamp_to_timespec(struct timeval *, cdf_timestamp_t);
|
int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t);
|
||||||
int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timeval *);
|
int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timespec *);
|
||||||
int cdf_read_header(const cdf_info_t *, cdf_header_t *);
|
int cdf_read_header(const cdf_info_t *, cdf_header_t *);
|
||||||
void cdf_swap_header(cdf_header_t *);
|
void cdf_swap_header(cdf_header_t *);
|
||||||
void cdf_unpack_header(cdf_header_t *, char *);
|
void cdf_unpack_header(cdf_header_t *, char *);
|
||||||
|
|
|
@ -96,7 +96,7 @@ cdf_getmonth(int year, int days)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
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;
|
struct tm tm;
|
||||||
#ifdef HAVE_STRUCT_TM_TM_ZONE
|
#ifdef HAVE_STRUCT_TM_TM_ZONE
|
||||||
|
@ -104,9 +104,8 @@ cdf_timestamp_to_timespec(struct timeval *ts, cdf_timestamp_t t)
|
||||||
#endif
|
#endif
|
||||||
int rdays;
|
int rdays;
|
||||||
|
|
||||||
/* XXX 5.14 at least introdced 100 ns intervals, this is to do */
|
/* Unit is 100's of nanoseconds */
|
||||||
/* Time interval, in microseconds */
|
ts->tv_nsec = (t % CDF_TIME_PREC) * 100;
|
||||||
ts->tv_usec = (t % CDF_TIME_PREC) * CDF_TIME_PREC;
|
|
||||||
|
|
||||||
t /= CDF_TIME_PREC;
|
t /= CDF_TIME_PREC;
|
||||||
tm.tm_sec = (int)(t % 60);
|
tm.tm_sec = (int)(t % 60);
|
||||||
|
@ -145,7 +144,7 @@ cdf_timestamp_to_timespec(struct timeval *ts, cdf_timestamp_t t)
|
||||||
|
|
||||||
int
|
int
|
||||||
/*ARGSUSED*/
|
/*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__
|
#ifndef __lint__
|
||||||
(void)&t;
|
(void)&t;
|
||||||
|
@ -157,7 +156,7 @@ cdf_timespec_to_timestamp(cdf_timestamp_t *t, const struct timeval *ts)
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
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_sec;
|
||||||
*t += tm.tm_min * 60;
|
*t += tm.tm_min * 60;
|
||||||
*t += tm.tm_hour * 60 * 60;
|
*t += tm.tm_hour * 60 * 60;
|
||||||
|
@ -182,7 +181,7 @@ cdf_ctime(const time_t *sec, char *buf)
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct timeval ts;
|
struct timespec ts;
|
||||||
char buf[25];
|
char buf[25];
|
||||||
static const cdf_timestamp_t tst = 0x01A5E403C2D59C00ULL;
|
static const cdf_timestamp_t tst = 0x01A5E403C2D59C00ULL;
|
||||||
static const char *ref = "Sat Apr 23 01:30:00 1977";
|
static const char *ref = "Sat Apr 23 01:30:00 1977";
|
||||||
|
|
|
@ -244,8 +244,8 @@ file_fmttime(uint64_t v, int flags, char *buf)
|
||||||
struct tm *tm = NULL;
|
struct tm *tm = NULL;
|
||||||
|
|
||||||
if (flags & FILE_T_WINDOWS) {
|
if (flags & FILE_T_WINDOWS) {
|
||||||
struct timeval ts;
|
struct timespec ts;
|
||||||
cdf_timestamp_to_timespec(&ts, t);
|
cdf_timestamp_to_timespec(&ts, CAST(cdf_timestamp_t, v));
|
||||||
t = ts.tv_sec;
|
t = ts.tv_sec;
|
||||||
} else {
|
} else {
|
||||||
// XXX: perhaps detect and print something if overflow
|
// XXX: perhaps detect and print something if overflow
|
||||||
|
|
|
@ -133,7 +133,7 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
cdf_timestamp_t tp;
|
cdf_timestamp_t tp;
|
||||||
struct timeval ts;
|
struct timespec ts;
|
||||||
char buf[64];
|
char buf[64];
|
||||||
const char *str = NULL;
|
const char *str = NULL;
|
||||||
const char *s, *e;
|
const char *s, *e;
|
||||||
|
@ -220,11 +220,8 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
char *c, *ec;
|
char *c, *ec;
|
||||||
const time_t sec = ts.tv_sec;
|
cdf_timestamp_to_timespec(&ts, tp);
|
||||||
if (cdf_timestamp_to_timespec(&ts, tp) == -1) {
|
c = cdf_ctime(&ts.tv_sec, tbuf);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
c = cdf_ctime(&sec, tbuf);
|
|
||||||
if (c != NULL &&
|
if (c != NULL &&
|
||||||
(ec = strchr(c, '\n')) != NULL)
|
(ec = strchr(c, '\n')) != NULL)
|
||||||
*ec = '\0';
|
*ec = '\0';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue