Skip to content

Commit 979f8bd

Browse files
kbleesdscho
authored andcommitted
Win32: make FILETIME conversion functions public
We will use them in the upcoming "FSCache" patches (to accelerate sequential lstat() calls). Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent cb123d2 commit 979f8bd

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

compat/mingw.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -651,24 +651,6 @@ int mingw_chmod(const char *filename, int mode)
651651
return _wchmod(wfilename, mode);
652652
}
653653

654-
/*
655-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
656-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
657-
*/
658-
static inline long long filetime_to_hnsec(const FILETIME *ft)
659-
{
660-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
661-
/* Windows to Unix Epoch conversion */
662-
return winTime - 116444736000000000LL;
663-
}
664-
665-
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
666-
{
667-
long long hnsec = filetime_to_hnsec(ft);
668-
ts->tv_sec = (time_t)(hnsec / 10000000);
669-
ts->tv_nsec = (hnsec % 10000000) * 100;
670-
}
671-
672654
/**
673655
* Verifies that safe_create_leading_directories() would succeed.
674656
*/

compat/mingw.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
344344
return 0;
345345
}
346346

347+
/*
348+
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
349+
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
350+
*/
351+
static inline long long filetime_to_hnsec(const FILETIME *ft)
352+
{
353+
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
354+
/* Windows to Unix Epoch conversion */
355+
return winTime - 116444736000000000LL;
356+
}
357+
347358
/*
348359
* Use mingw specific stat()/lstat()/fstat() implementations on Windows,
349360
* including our own struct stat with 64 bit st_size and nanosecond-precision
@@ -360,6 +371,13 @@ struct timespec {
360371
#endif
361372
#endif
362373

374+
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
375+
{
376+
long long hnsec = filetime_to_hnsec(ft);
377+
ts->tv_sec = (time_t)(hnsec / 10000000);
378+
ts->tv_nsec = (hnsec % 10000000) * 100;
379+
}
380+
363381
struct mingw_stat {
364382
_dev_t st_dev;
365383
_ino_t st_ino;

0 commit comments

Comments
 (0)