Skip to content

Commit df0d8ea

Browse files
kbleesGit for Windows Build Agent
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 c9f7aad commit df0d8ea

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

compat/mingw-posix.h

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

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

372+
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
373+
{
374+
long long hnsec = filetime_to_hnsec(ft);
375+
ts->tv_sec = (time_t)(hnsec / 10000000);
376+
ts->tv_nsec = (hnsec % 10000000) * 100;
377+
}
378+
361379
struct mingw_stat {
362380
_dev_t st_dev;
363381
_ino_t st_ino;

compat/mingw.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -881,24 +881,6 @@ int mingw_chmod(const char *filename, int mode)
881881
return _wchmod(wfilename, mode);
882882
}
883883

884-
/*
885-
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
886-
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
887-
*/
888-
static inline long long filetime_to_hnsec(const FILETIME *ft)
889-
{
890-
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
891-
/* Windows to Unix Epoch conversion */
892-
return winTime - 116444736000000000LL;
893-
}
894-
895-
static inline void filetime_to_timespec(const FILETIME *ft, struct timespec *ts)
896-
{
897-
long long hnsec = filetime_to_hnsec(ft);
898-
ts->tv_sec = (time_t)(hnsec / 10000000);
899-
ts->tv_nsec = (hnsec % 10000000) * 100;
900-
}
901-
902884
/**
903885
* Verifies that safe_create_leading_directories() would succeed.
904886
*/

0 commit comments

Comments
 (0)