2 #include <msvcrt/sys/types.h>
3 #include <msvcrt/sys/stat.h>
4 #include <msvcrt/fcntl.h>
6 #include <msvcrt/errno.h>
7 #include <msvcrt/string.h>
8 #include <msvcrt/internal/file.h>
11 int _stat(const char* path, struct stat* buffer)
14 WIN32_FIND_DATAA findData;
23 if (strchr(path, '*') || strchr(path, '?'))
29 findHandle = FindFirstFileA(path, &findData);
30 if (findHandle == INVALID_HANDLE_VALUE)
36 FindClose(findHandle);
38 memset (buffer, 0, sizeof(struct stat));
40 buffer->st_ctime = FileTimeToUnixTime(&findData.ftCreationTime,NULL);
41 buffer->st_atime = FileTimeToUnixTime(&findData.ftLastAccessTime,NULL);
42 buffer->st_mtime = FileTimeToUnixTime(&findData.ftLastWriteTime,NULL);
44 // statbuf->st_dev = fd;
45 buffer->st_size = findData.nFileSizeLow;
46 buffer->st_mode = S_IREAD;
47 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
48 buffer->st_mode |= S_IFDIR;
51 buffer->st_mode |= S_IFREG;
52 ext = strrchr(path, '.');
53 if (ext && (!stricmp(ext, ".exe") ||
54 !stricmp(ext, ".com") ||
55 !stricmp(ext, ".bat") ||
56 !stricmp(ext, ".cmd")))
57 buffer->st_mode |= S_IEXEC;
59 if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
60 buffer->st_mode |= S_IWRITE;