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>
14 int _stat(const char* path, struct stat* buffer)
16 WIN32_FILE_ATTRIBUTE_DATA fileAttributeData;
25 if (strchr(path, '*') || strchr(path, '?'))
31 if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fileAttributeData))
37 memset (buffer, 0, sizeof(struct stat));
39 buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL);
40 buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL);
41 buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL);
43 // statbuf->st_dev = fd;
44 buffer->st_size = fileAttributeData.nFileSizeLow;
45 buffer->st_mode = S_IREAD;
46 if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
47 buffer->st_mode |= S_IFDIR;
50 buffer->st_mode |= S_IFREG;
51 ext = strrchr(path, '.');
52 if (ext && (!_stricmp(ext, ".exe") ||
53 !_stricmp(ext, ".com") ||
54 !_stricmp(ext, ".bat") ||
55 !_stricmp(ext, ".cmd")))
56 buffer->st_mode |= S_IEXEC;
58 if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
59 buffer->st_mode |= S_IWRITE;
67 __int64 _stati64 (const char *path, struct _stati64 *buffer)
69 WIN32_FILE_ATTRIBUTE_DATA fileAttributeData;
78 if(strchr(path, '*') || strchr(path, '?'))
84 if (!GetFileAttributesExA(path, GetFileExInfoStandard, &fileAttributeData))
90 memset (buffer, 0, sizeof(struct _stati64));
92 buffer->st_ctime = FileTimeToUnixTime(&fileAttributeData.ftCreationTime,NULL);
93 buffer->st_atime = FileTimeToUnixTime(&fileAttributeData.ftLastAccessTime,NULL);
94 buffer->st_mtime = FileTimeToUnixTime(&fileAttributeData.ftLastWriteTime,NULL);
96 // statbuf->st_dev = fd;
97 buffer->st_size = ((((__int64)fileAttributeData.nFileSizeHigh) << 16) << 16) +
98 fileAttributeData.nFileSizeLow;
99 buffer->st_mode = S_IREAD;
100 if (fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
101 buffer->st_mode |= S_IFDIR;
104 buffer->st_mode |= S_IFREG;
105 ext = strrchr(path, '.');
106 if (ext && (!_stricmp(ext, ".exe") ||
107 !_stricmp(ext, ".com") ||
108 !_stricmp(ext, ".bat") ||
109 !_stricmp(ext, ".cmd")))
110 buffer->st_mode |= S_IEXEC;
112 if (!(fileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
113 buffer->st_mode |= S_IWRITE;