bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: futimens() for WIN32/MinGW


From: Bruno Haible
Subject: Re: futimens() for WIN32/MinGW
Date: Wed, 5 Apr 2017 03:48:32 +0200 (CEST)

Hi Tim,

> gnulib has no support for WIN32 futimens resp. the gnulib implementation
> returns a 'not implemented' error.
> 
> So today I wrote a surrogate for it, which works for me on MinGW.
> 
> Since I am not sure where to add it (futimens.c or utimens.c) and if
> there are caveats, I ask you to add it where appropriate.
> 
> #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

This is a good start, indeed.

When integrating such a code in gnulib, one needs to check also
whether the existing tests (of this module and related modules)
or can be adapted. So the next practical step is to run
  ./gnulib-tool --create-testdir --with-tests --single-configure utimens 
futimens ...

You will then notice:
- There is a link error due to --single-configure and strerror_r.
- The logic in nap.h is buggy: it calls nanosleep with a negative
  delay argument. And it expects Unix behaviour that is not met
  by Windows.
- Not only utimens.c needs to be adjusted, but also utimecmp.c.
- st_mtime come out 2 hours higher than expected (for me). Obviously
  some timezone issue.
- And probably more...

I'm trying to get these sorted out, one by one.

Bruno



reply via email to

[Prev in Thread] Current Thread [Next in Thread]