Skip to content

Commit 2571af7

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 615e0b3 commit 2571af7

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
@@ -788,24 +788,6 @@ int mingw_chmod(const char *filename, int mode)
788788
return _wchmod(wfilename, mode);
789789
}
790790

791-
/*
792-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
793-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
794-
*/
795-
static inline long long filetime_to_hnsec(const FILETIME *ft)
796-
{
797-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
798-
/* Windows to Unix Epoch conversion */
799-
return winTime - 116444736000000000LL;
800-
}
801-
802-
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
803-
{
804-
long long hnsec = filetime_to_hnsec(ft);
805-
ts->tv_sec = (time_t)(hnsec / 10000000);
806-
ts->tv_nsec = (hnsec % 10000000) * 100;
807-
}
808-
809791
/**
810792
* Verifies that safe_create_leading_directories() would succeed.
811793
*/

compat/mingw.h

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

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

386+
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
387+
{
388+
long long hnsec = filetime_to_hnsec(ft);
389+
ts->tv_sec = (time_t)(hnsec / 10000000);
390+
ts->tv_nsec = (hnsec % 10000000) * 100;
391+
}
392+
375393
struct mingw_stat {
376394
_dev_t st_dev;
377395
_ino_t st_ino;

0 commit comments

Comments
 (0)