Hi,

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


Regards, Tim

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to