Skip to content

Commit

Permalink
Add futimens() implementation for _WIN32
Browse files Browse the repository at this point in the history
* src/wget.c: Add futimens() if _WIN32 is defined

Reported-by: Gisle Vanem
Fixes: #167
  • Loading branch information
rockdaboot committed Apr 4, 2017
1 parent 4378516 commit aaf5aad
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/wget.c
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,33 @@ static time_t G_GNUC_WGET_NONNULL_ALL get_file_mtime(const char *fname)
return 0;
}

#ifdef _WIN32
#include <windows.h>

int futimens(int fd, const struct timespec times[2])
{
FILETIME mt, at;
LONGLONG ll;

// convert time_t to FILETIME
ll = Int32x32To64(times[0].tv_sec, 10000000) + 116444736000000000;
at.dwLowDateTime = (DWORD) ll;
at.dwHighDateTime = ll >> 32;

ll = Int32x32To64(times[1].tv_sec, 10000000) + 116444736000000000;
mt.dwLowDateTime = (DWORD) ll;
mt.dwHighDateTime = ll >> 32;

BOOL success = SetFileTime(
(HANDLE) _get_osfhandle (fd),
&mt, // creation
&at, // last access
&mt); // last modification

return success ? 0 : -1;
}
#endif

static void set_file_mtime(int fd, time_t modified)
{
struct timespec timespecs[2]; // [0]=last access [1]=last modified
Expand Down

0 comments on commit aaf5aad

Please sign in to comment.