Skip to content

Commit a7a948c

Browse files
committed
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 8eee421 commit a7a948c

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
@@ -606,24 +606,6 @@ int mingw_chmod(const char *filename, int mode)
606606
return _wchmod(wfilename, mode);
607607
}
608608

609-
/*
610-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
611-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
612-
*/
613-
static inline long long filetime_to_hnsec(const FILETIME *ft)
614-
{
615-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
616-
/* Windows to Unix Epoch conversion */
617-
return winTime - 116444736000000000LL;
618-
}
619-
620-
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
621-
{
622-
long long hnsec = filetime_to_hnsec(ft);
623-
ts->tv_sec = (time_t)(hnsec / 10000000);
624-
ts->tv_nsec = (hnsec % 10000000) * 100;
625-
}
626-
627609
/**
628610
* Verifies that safe_create_leading_directories() would succeed.
629611
*/

compat/mingw.h

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

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

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

0 commit comments

Comments
 (0)