Fix Win32 ARM target
PATCH 1/1 Fix Win32 ARM target
Hi,
Windows doesn't implement localtime_r() and gmtime_r() functions, which lead to ARM target breakage.
I added a very simple implementation of them (however not thread-safe), which leads to fix ARM target and to simplification of code in a few other files.
Bonus is that it also fixes a problem with GMT vs local time in m48t59.c :)
Hervé
block-vvfat.c +0 -4
@@ -522,13 +522,9 @@/* if return_time==0, this returns the fat_date, else the fat_time */ static uint16_t fat_datetime (time_t time,int return_time) {struct tm * t; -#ifdef _WIN32 - t=localtime (&time);/* this is not thread safe */ -#else struct tm t1; t=&t1;localtime_r (&time,t); -#endif if (return_time)return cpu_to_le16 ((t->tm_sec/2 )|(t->tm_min<<5 )|(t->tm_hour<<11 ));return cpu_to_le16 ((t->tm_mday)|((t->tm_mon+1 )<<5 )|((t->tm_year-80 )<<9 ));
block.c +0 -10
@@ -1044,11 +1044,7 @@char *bdrv_snapshot_dump (char *buf,int buf_size,QEMUSnapshotInfo *sn) {char buf1[128 ], date_buf[128 ], clock_buf[128 ]; -#ifdef _WIN32 -struct tm *ptm; -#else struct tm tm; -#endif time_t ti;int64_t secs;
@@ -1058,15 +1054,9 @@ "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK"); }else { ti = sn->date_sec; -#ifdef _WIN32 - ptm =localtime (&ti); -strftime (date_buf,sizeof (date_buf), -"%Y-%m-%d %H:%M:%S" , ptm); -#else localtime_r (&ti, &tm);strftime (date_buf,sizeof (date_buf),"%Y-%m-%d %H:%M:%S" , &tm); -#endif secs = sn->vm_clock_nsec /1000000000 ; snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d:%02d.%03d",
hw/m48t59.c +0 -8
@@ -80,14 +80,10 @@time_t t; t =time (NULL ) +NVRAM ->time_offset; -#ifdef _WIN32 -memcpy (tm,localtime (&t),sizeof (*tm)); -#else if (rtc_utc)gmtime_r (&t, tm);else localtime_r (&t, tm) ; -#endif }static void set_time (m48t59_t *NVRAM ,struct tm *tm)
@@ -149,14 +145,10 @@static void get_alarm (m48t59_t *NVRAM ,struct tm *tm) { -#ifdef _WIN32 -memcpy (tm,localtime (&NVRAM ->alarm),sizeof (*tm)); -#else if (rtc_utc)gmtime_r (&NVRAM ->alarm, tm);else localtime_r (&NVRAM ->alarm, tm); -#endif }static void set_alarm (m48t59_t *NVRAM ,struct tm *tm)
qemu-common.h +18 -0
@@ -43,6 +43,24 @@return resolved_path; } +static inline struct tm *localtime_r (const time_t *clock,struct tm *result) +{ +/* this is not thread safe */ +struct tm *ptm =localtime (clock); +if (!ptm)return NULL ; +memcpy (result, ptm,sizeof (*ptm)); +return result; +} + +static inline struct tm *gmtime_r (const time_t *clock,struct tm *result) +{ +/* this is not thread safe */ +struct tm *ptm =gmtime (clock); +if (!ptm)return NULL ; +memcpy (result, ptm,sizeof (*ptm)); +return result; +} +#define PRId64 "I64d"#define PRIx64 "I64x"#define PRIu64 "I64u"