/win32/shellext/Winstat.cpp
C++ | 42 lines | 19 code | 9 blank | 14 comment | 3 complexity | e0d23e5ebcf513c68f139e92dbc6bd01 MD5 | raw file
Possible License(s): GPL-2.0
1
2// Copyright (C) 2009 Benjamin Pollack
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 2 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17#include "stdafx.h"
18
19#include "Winstat.h"
20
21
22int Winstat::lstat(const char* file)
23{
24 const __int64 days_between_epochs = 134774L; /* days between 1.1.1601 and 1.1.1970 */
25 const __int64 secs_between_epochs = (__int64)days_between_epochs * 86400L;
26 const __int64 divisor = 10000000L;
27
28 WIN32_FIND_DATAA data;
29 HANDLE hfind;
30
31 hfind = FindFirstFileA(file, &data);
32 if (hfind == INVALID_HANDLE_VALUE)
33 return -1;
34 FindClose(hfind);
35
36 this->mtime = (((__int64)data.ftLastWriteTime.dwHighDateTime << 32) +
37 data.ftLastWriteTime.dwLowDateTime) / divisor - secs_between_epochs;
38 this->size = ((__int64)data.nFileSizeHigh << 32) + data.nFileSizeLow;
39 this->isdir = (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
40
41 return 0;
42}