Commit d3e8f957 authored by Stefan Weil's avatar Stefan Weil Committed by Blue Swirl
Browse files

w32: Add implementation of gmtime_r, localtime_r



Those functions are missing in MinGW.

Some versions of MinGW-w64 include defines for gmtime_r and localtime_r.
Older versions of these macros are buggy (they return a pointer to a
static variable), therefore we don't want them. Newer versions are
similar to the code used here, but without the memset.

The implementation which is used here is not strictly reentrant,
but sufficiently good for QEMU on w32 or w64.

Signed-off-by: default avatarStefan Weil <sw@weilnetz.de>
[blauwirbel@gmail.com: added comment about locking]
Signed-off-by: default avatarBlue Swirl <blauwirbel@gmail.com>
parent 93b65997
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -74,6 +74,30 @@ void qemu_vfree(void *ptr)
    VirtualFree(ptr, 0, MEM_RELEASE);
}

/* FIXME: add proper locking */
struct tm *gmtime_r(const time_t *timep, struct tm *result)
{
    struct tm *p = gmtime(timep);
    memset(result, 0, sizeof(*result));
    if (p) {
        *result = *p;
        p = result;
    }
    return p;
}

/* FIXME: add proper locking */
struct tm *localtime_r(const time_t *timep, struct tm *result)
{
    struct tm *p = localtime(timep);
    memset(result, 0, sizeof(*result));
    if (p) {
        *result = *p;
        p = result;
    }
    return p;
}

void socket_set_block(int fd)
{
    unsigned long opt = 0;
+6 −0
Original line number Diff line number Diff line
@@ -68,6 +68,12 @@
/* Declaration of ffs() is missing in MinGW's strings.h. */
int ffs(int i);

/* Missing POSIX functions. Don't use MinGW-w64 macros. */
#undef gmtime_r
struct tm *gmtime_r(const time_t *timep, struct tm *result);
#undef localtime_r
struct tm *localtime_r(const time_t *timep, struct tm *result);

static inline void os_setup_signal_handling(void) {}
static inline void os_daemonize(void) {}
static inline void os_setup_post(void) {}