Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
windows: get rid of overly complicated uv_filetime_to_time_t helper
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jun 21, 2012
1 parent d169ba1 commit ea3e2cd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
9 changes: 6 additions & 3 deletions src/win/fs.c
Expand Up @@ -91,6 +91,9 @@
return; \
}

#define FILETIME_TO_TIME_T(filetime) \
((*((uint64_t*) &(filetime)) - 116444736000000000ULL) / 10000000ULL);

#define IS_SLASH(c) ((c) == L'\\' || (c) == L'/')
#define IS_LETTER(c) (((c) >= L'a' && (c) <= L'z') || \
((c) >= L'A' && (c) <= L'Z'))
Expand Down Expand Up @@ -630,9 +633,9 @@ static void fs__stat(uv_fs_t* req, const wchar_t* path, int link) {
(int64_t) info.nFileSizeLow;
}

uv_filetime_to_time_t(&info.ftLastWriteTime, &(req->stat.st_mtime));
uv_filetime_to_time_t(&info.ftLastAccessTime, &(req->stat.st_atime));
uv_filetime_to_time_t(&info.ftCreationTime, &(req->stat.st_ctime));
req->stat.st_mtime = FILETIME_TO_TIME_T(info.ftLastWriteTime);
req->stat.st_atime = FILETIME_TO_TIME_T(info.ftLastAccessTime);
req->stat.st_ctime = FILETIME_TO_TIME_T(info.ftCreationTime);

req->stat.st_nlink = (info.nNumberOfLinks <= SHRT_MAX) ?
(short) info.nNumberOfLinks : SHRT_MAX;
Expand Down
1 change: 0 additions & 1 deletion src/win/internal.h
Expand Up @@ -280,7 +280,6 @@ void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle);
void uv__util_init();

int uv_parent_pid();
void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time);
void uv_fatal_error(const int errorno, const char* syscall);
uv_err_code uv_translate_sys_error(int sys_errno);

Expand Down
23 changes: 0 additions & 23 deletions src/win/util.c
Expand Up @@ -862,26 +862,3 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,

free(addresses);
}


void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time) {
FILETIME local_time;
SYSTEMTIME system_time;
struct tm time;

if ((file_time->dwLowDateTime || file_time->dwHighDateTime) &&
FileTimeToLocalFileTime(file_time, &local_time) &&
FileTimeToSystemTime(&local_time, &system_time)) {
time.tm_year = system_time.wYear - 1900;
time.tm_mon = system_time.wMonth - 1;
time.tm_mday = system_time.wDay;
time.tm_hour = system_time.wHour;
time.tm_min = system_time.wMinute;
time.tm_sec = system_time.wSecond;
time.tm_isdst = -1;

*stat_time = mktime(&time);
} else {
*stat_time = 0;
}
}

0 comments on commit ea3e2cd

Please sign in to comment.