From 35439f5997c41d0c50d58997c2167ee93aad6c30 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Feb 2016 12:24:21 -0800 Subject: [PATCH] win32: introduce p_timeval that isn't stupid Windows defines `timeval` with `long`, which we cannot sanely cope with. Instead, use a custom timeval struct. --- src/unix/posix.h | 4 +++- src/win32/posix.h | 5 +++-- src/win32/posix_w32.c | 4 ++-- src/win32/w32_util.h | 2 +- src/win32/win32-compat.h | 7 +++++++ tests/checkout/checkout_helpers.c | 2 +- tests/core/posix.c | 2 +- tests/diff/workdir.c | 4 ++-- tests/index/racy.c | 2 +- tests/merge/workdir/dirty.c | 2 +- 10 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/unix/posix.h b/src/unix/posix.h index 6633689bc..83edf2b7e 100644 --- a/src/unix/posix.h +++ b/src/unix/posix.h @@ -52,8 +52,10 @@ extern char *p_realpath(const char *, char *); #define p_localtime_r(c, r) localtime_r(c, r) #define p_gmtime_r(c, r) gmtime_r(c, r) +#define p_timeval timeval + #ifdef HAVE_FUTIMENS -GIT_INLINE(int) p_futimes(int f, const struct timeval t[2]) +GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2]) { struct timespec s[2]; s[0].tv_sec = t[0].tv_sec; diff --git a/src/win32/posix.h b/src/win32/posix.h index ac98fd864..732128bb0 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -9,6 +9,7 @@ #include "common.h" #include "../posix.h" +#include "win32-compat.h" #include "path_w32.h" #include "utf-conv.h" #include "dir.h" @@ -20,8 +21,8 @@ typedef SOCKET GIT_SOCKET; extern int p_lstat(const char *file_name, struct stat *buf); extern int p_stat(const char* path, struct stat* buf); -extern int p_utimes(const char *filename, const struct timeval times[2]); -extern int p_futimes(int fd, const struct timeval times[2]); +extern int p_utimes(const char *filename, const struct p_timeval times[2]); +extern int p_futimes(int fd, const struct p_timeval times[2]); extern int p_readlink(const char *path, char *buf, size_t bufsiz); extern int p_symlink(const char *old, const char *new); diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 414cb4701..d743e8fc8 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -210,7 +210,7 @@ int p_lstat_posixly(const char *filename, struct stat *buf) return do_lstat(filename, buf, true); } -int p_utimes(const char *filename, const struct timeval times[2]) +int p_utimes(const char *filename, const struct p_timeval times[2]) { int fd, error; @@ -223,7 +223,7 @@ int p_utimes(const char *filename, const struct timeval times[2]) return error; } -int p_futimes(int fd, const struct timeval times[2]) +int p_futimes(int fd, const struct p_timeval times[2]) { HANDLE handle; FILETIME atime = {0}, mtime = {0}; diff --git a/src/win32/w32_util.h b/src/win32/w32_util.h index 727ed1cef..b095939a1 100644 --- a/src/win32/w32_util.h +++ b/src/win32/w32_util.h @@ -96,7 +96,7 @@ GIT_INLINE(void) git_win32__filetime_to_timespec( } GIT_INLINE(void) git_win32__timeval_to_filetime( - FILETIME *ft, const struct timeval tv) + FILETIME *ft, const struct p_timeval tv) { long long ticks = (tv.tv_sec * 10000000LL) + (tv.tv_usec * 10LL) + 116444736000000000LL; diff --git a/src/win32/win32-compat.h b/src/win32/win32-compat.h index d3a5b68a3..dff1f45be 100644 --- a/src/win32/win32-compat.h +++ b/src/win32/win32-compat.h @@ -13,6 +13,13 @@ #include #include +typedef long suseconds_t; + +struct p_timeval { + time_t tv_sec; + suseconds_t tv_usec; +}; + struct p_timespec { time_t tv_sec; long tv_nsec; diff --git a/tests/checkout/checkout_helpers.c b/tests/checkout/checkout_helpers.c index fb2f415e7..d7d24f33f 100644 --- a/tests/checkout/checkout_helpers.c +++ b/tests/checkout/checkout_helpers.c @@ -133,7 +133,7 @@ int checkout_count_callback( void tick_index(git_index *index) { struct timespec ts; - struct timeval times[2]; + struct p_timeval times[2]; cl_assert(index->on_disk); cl_assert(git_index_path(index)); diff --git a/tests/core/posix.c b/tests/core/posix.c index 5a9e24899..34a67bf47 100644 --- a/tests/core/posix.c +++ b/tests/core/posix.c @@ -100,7 +100,7 @@ void test_core_posix__inet_pton(void) void test_core_posix__utimes(void) { - struct timeval times[2]; + struct p_timeval times[2]; struct stat st; time_t curtime; int fd; diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c index 4c782339d..892c7b72d 100644 --- a/tests/diff/workdir.c +++ b/tests/diff/workdir.c @@ -1755,7 +1755,7 @@ void test_diff_workdir__with_stale_index(void) static int touch_file(void *payload, git_buf *path) { struct stat st; - struct timeval times[2]; + struct p_timeval times[2]; GIT_UNUSED(payload); if (git_path_isdir(path->ptr)) @@ -2006,7 +2006,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void) git_oid initial, first, second; git_buf path = GIT_BUF_INIT; struct stat st; - struct timeval times[2]; + struct p_timeval times[2]; opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_UPDATE_INDEX; diff --git a/tests/index/racy.c b/tests/index/racy.c index e2275ea14..ace84d585 100644 --- a/tests/index/racy.c +++ b/tests/index/racy.c @@ -54,7 +54,7 @@ void test_index_racy__write_index_just_after_file(void) git_index *index; git_diff *diff; git_buf path = GIT_BUF_INIT; - struct timeval times[2]; + struct p_timeval times[2]; /* Make sure we do have a timestamp */ cl_git_pass(git_repository_index(&index, g_repo)); diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c index 994a1d813..99e33e0cd 100644 --- a/tests/merge/workdir/dirty.c +++ b/tests/merge/workdir/dirty.c @@ -133,7 +133,7 @@ static void hack_index(char *files[]) struct stat statbuf; git_buf path = GIT_BUF_INIT; git_index_entry *entry; - struct timeval times[2]; + struct p_timeval times[2]; time_t now; size_t i;