Skip to content

Commit eb39552

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 8db2111 commit eb39552

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
@@ -364,6 +364,17 @@ static inline int getrlimit(int resource, struct rlimit *rlp)
364364
return 0;
365365
}
366366

367+
/*
368+
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
369+
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
370+
*/
371+
static inline long long filetime_to_hnsec(const FILETIME *ft)
372+
{
373+
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
374+
/* Windows to Unix Epoch conversion */
375+
return winTime - 116444736000000000LL;
376+
}
377+
367378
/*
368379
* Use mingw specific stat()/lstat()/fstat() implementations on Windows,
369380
* including our own struct stat with 64 bit st_size and nanosecond-precision
@@ -380,6 +391,13 @@ struct timespec {
380391
#endif
381392
#endif
382393

394+
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
395+
{
396+
long long hnsec = filetime_to_hnsec(ft);
397+
ts->tv_sec = (time_t)(hnsec / 10000000);
398+
ts->tv_nsec = (hnsec % 10000000) * 100;
399+
}
400+
383401
struct mingw_stat {
384402
_dev_t st_dev;
385403
_ino_t st_ino;

0 commit comments

Comments
 (0)