Skip to content

Commit 7fba6c5

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 375b32d commit 7fba6c5

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
@@ -774,24 +774,6 @@ int mingw_chmod(const char *filename, int mode)
774774
return _wchmod(wfilename, mode);
775775
}
776776

777-
/*
778-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
779-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
780-
*/
781-
static inline long long filetime_to_hnsec(const FILETIME *ft)
782-
{
783-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
784-
/* Windows to Unix Epoch conversion */
785-
return winTime - 116444736000000000LL;
786-
}
787-
788-
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
789-
{
790-
long long hnsec = filetime_to_hnsec(ft);
791-
ts->tv_sec = (time_t)(hnsec / 10000000);
792-
ts->tv_nsec = (hnsec % 10000000) * 100;
793-
}
794-
795777
/**
796778
* Verifies that safe_create_leading_directories() would succeed.
797779
*/

compat/mingw.h

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

354+
/*
355+
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
356+
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
357+
*/
358+
static inline long long filetime_to_hnsec(const FILETIME *ft)
359+
{
360+
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
361+
/* Windows to Unix Epoch conversion */
362+
return winTime - 116444736000000000LL;
363+
}
364+
354365
/*
355366
* Use mingw specific stat()/lstat()/fstat() implementations on Windows,
356367
* including our own struct stat with 64 bit st_size and nanosecond-precision
@@ -367,6 +378,13 @@ struct timespec {
367378
#endif
368379
#endif
369380

381+
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
382+
{
383+
long long hnsec = filetime_to_hnsec(ft);
384+
ts->tv_sec = (time_t)(hnsec / 10000000);
385+
ts->tv_nsec = (hnsec % 10000000) * 100;
386+
}
387+
370388
struct mingw_stat {
371389
_dev_t st_dev;
372390
_ino_t st_ino;

0 commit comments

Comments
 (0)