Skip to content

Commit f1c4cdd

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 aa1e2c6 commit f1c4cdd

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
@@ -733,24 +733,6 @@ int mingw_chmod(const char *filename, int mode)
733733
return _wchmod(wfilename, mode);
734734
}
735735

736-
/*
737-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
738-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
739-
*/
740-
static inline long long filetime_to_hnsec(const FILETIME *ft)
741-
{
742-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
743-
/* Windows to Unix Epoch conversion */
744-
return winTime - 116444736000000000LL;
745-
}
746-
747-
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
748-
{
749-
long long hnsec = filetime_to_hnsec(ft);
750-
ts->tv_sec = (time_t)(hnsec / 10000000);
751-
ts->tv_nsec = (hnsec % 10000000) * 100;
752-
}
753-
754736
/**
755737
* Verifies that safe_create_leading_directories() would succeed.
756738
*/

compat/mingw.h

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

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

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

0 commit comments

Comments
 (0)