Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35439f5

Browse files
author
Edward Thomson
committed
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.
1 parent 263e674 commit 35439f5

File tree

10 files changed

+22
-12
lines changed

10 files changed

+22
-12
lines changed

src/unix/posix.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ extern char *p_realpath(const char *, char *);
5252
#define p_localtime_r(c, r) localtime_r(c, r)
5353
#define p_gmtime_r(c, r) gmtime_r(c, r)
5454

55+
#define p_timeval timeval
56+
5557
#ifdef HAVE_FUTIMENS
56-
GIT_INLINE(int) p_futimes(int f, const struct timeval t[2])
58+
GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2])
5759
{
5860
struct timespec s[2];
5961
s[0].tv_sec = t[0].tv_sec;

src/win32/posix.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "common.h"
1111
#include "../posix.h"
12+
#include "win32-compat.h"
1213
#include "path_w32.h"
1314
#include "utf-conv.h"
1415
#include "dir.h"
@@ -20,8 +21,8 @@ typedef SOCKET GIT_SOCKET;
2021
extern int p_lstat(const char *file_name, struct stat *buf);
2122
extern int p_stat(const char* path, struct stat* buf);
2223

23-
extern int p_utimes(const char *filename, const struct timeval times[2]);
24-
extern int p_futimes(int fd, const struct timeval times[2]);
24+
extern int p_utimes(const char *filename, const struct p_timeval times[2]);
25+
extern int p_futimes(int fd, const struct p_timeval times[2]);
2526

2627
extern int p_readlink(const char *path, char *buf, size_t bufsiz);
2728
extern int p_symlink(const char *old, const char *new);

src/win32/posix_w32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int p_lstat_posixly(const char *filename, struct stat *buf)
210210
return do_lstat(filename, buf, true);
211211
}
212212

213-
int p_utimes(const char *filename, const struct timeval times[2])
213+
int p_utimes(const char *filename, const struct p_timeval times[2])
214214
{
215215
int fd, error;
216216

@@ -223,7 +223,7 @@ int p_utimes(const char *filename, const struct timeval times[2])
223223
return error;
224224
}
225225

226-
int p_futimes(int fd, const struct timeval times[2])
226+
int p_futimes(int fd, const struct p_timeval times[2])
227227
{
228228
HANDLE handle;
229229
FILETIME atime = {0}, mtime = {0};

src/win32/w32_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ GIT_INLINE(void) git_win32__filetime_to_timespec(
9696
}
9797

9898
GIT_INLINE(void) git_win32__timeval_to_filetime(
99-
FILETIME *ft, const struct timeval tv)
99+
FILETIME *ft, const struct p_timeval tv)
100100
{
101101
long long ticks = (tv.tv_sec * 10000000LL) +
102102
(tv.tv_usec * 10LL) + 116444736000000000LL;

src/win32/win32-compat.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
#include <sys/stat.h>
1414
#include <sys/types.h>
1515

16+
typedef long suseconds_t;
17+
18+
struct p_timeval {
19+
time_t tv_sec;
20+
suseconds_t tv_usec;
21+
};
22+
1623
struct p_timespec {
1724
time_t tv_sec;
1825
long tv_nsec;

tests/checkout/checkout_helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int checkout_count_callback(
133133
void tick_index(git_index *index)
134134
{
135135
struct timespec ts;
136-
struct timeval times[2];
136+
struct p_timeval times[2];
137137

138138
cl_assert(index->on_disk);
139139
cl_assert(git_index_path(index));

tests/core/posix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void test_core_posix__inet_pton(void)
100100

101101
void test_core_posix__utimes(void)
102102
{
103-
struct timeval times[2];
103+
struct p_timeval times[2];
104104
struct stat st;
105105
time_t curtime;
106106
int fd;

tests/diff/workdir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ void test_diff_workdir__with_stale_index(void)
17551755
static int touch_file(void *payload, git_buf *path)
17561756
{
17571757
struct stat st;
1758-
struct timeval times[2];
1758+
struct p_timeval times[2];
17591759

17601760
GIT_UNUSED(payload);
17611761
if (git_path_isdir(path->ptr))
@@ -2006,7 +2006,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void)
20062006
git_oid initial, first, second;
20072007
git_buf path = GIT_BUF_INIT;
20082008
struct stat st;
2009-
struct timeval times[2];
2009+
struct p_timeval times[2];
20102010

20112011
opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_UPDATE_INDEX;
20122012

tests/index/racy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void test_index_racy__write_index_just_after_file(void)
5454
git_index *index;
5555
git_diff *diff;
5656
git_buf path = GIT_BUF_INIT;
57-
struct timeval times[2];
57+
struct p_timeval times[2];
5858

5959
/* Make sure we do have a timestamp */
6060
cl_git_pass(git_repository_index(&index, g_repo));

tests/merge/workdir/dirty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void hack_index(char *files[])
133133
struct stat statbuf;
134134
git_buf path = GIT_BUF_INIT;
135135
git_index_entry *entry;
136-
struct timeval times[2];
136+
struct p_timeval times[2];
137137
time_t now;
138138
size_t i;
139139

0 commit comments

Comments
 (0)