| ... | ... | @@ -1808,7 +1808,7 @@ Error os_self_exe_shared_libs(ZigList<Buf *> &paths) { |
| 1808 | 1808 | #endif |
| 1809 | 1809 | } |
| 1810 | 1810 | |
| 1811 | | Error os_file_open_r(Buf *full_path, OsFile *out_file) { |
| 1811 | Error os_file_open_r(Buf *full_path, OsFile *out_file, OsTimeStamp *mtime) { |
| 1812 | 1812 | #if defined(ZIG_OS_WINDOWS) |
| 1813 | 1813 | // TODO use CreateFileW |
| 1814 | 1814 | HANDLE result = CreateFileA(buf_ptr(full_path), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); |
| ... | ... | @@ -1834,8 +1834,18 @@ Error os_file_open_r(Buf *full_path, OsFile *out_file) { |
| 1834 | 1834 | return ErrorUnexpected; |
| 1835 | 1835 | } |
| 1836 | 1836 | } |
| 1837 | | |
| 1838 | 1837 | *out_file = result; |
| 1838 | |
| 1839 | if (mtime != nullptr) { |
| 1840 | FILETIME last_write_time; |
| 1841 | if (!GetFileTime(file, nullptr, nullptr, &last_write_time)) { |
| 1842 | CloseHandle(result); |
| 1843 | return ErrorUnexpected; |
| 1844 | } |
| 1845 | mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; |
| 1846 | mtime->nsec = 0; |
| 1847 | } |
| 1848 | |
| 1839 | 1849 | return ErrorNone; |
| 1840 | 1850 | #else |
| 1841 | 1851 | for (;;) { |
| ... | ... | @@ -1858,7 +1868,26 @@ Error os_file_open_r(Buf *full_path, OsFile *out_file) { |
| 1858 | 1868 | return ErrorFileSystem; |
| 1859 | 1869 | } |
| 1860 | 1870 | } |
| 1871 | struct stat statbuf; |
| 1872 | if (fstat(fd, &statbuf) == -1) { |
| 1873 | close(fd); |
| 1874 | return ErrorFileSystem; |
| 1875 | } |
| 1876 | if (S_ISDIR(statbuf.st_mode)) { |
| 1877 | close(fd); |
| 1878 | return ErrorIsDir; |
| 1879 | } |
| 1861 | 1880 | *out_file = fd; |
| 1881 | |
| 1882 | if (mtime != nullptr) { |
| 1883 | #if defined(ZIG_OS_DARWIN) |
| 1884 | mtime->sec = statbuf.st_mtimespec.tv_sec; |
| 1885 | mtime->nsec = statbuf.st_mtimespec.tv_nsec; |
| 1886 | #else |
| 1887 | mtime->sec = statbuf.st_mtim.tv_sec; |
| 1888 | mtime->nsec = statbuf.st_mtim.tv_nsec; |
| 1889 | #endif |
| 1890 | } |
| 1862 | 1891 | return ErrorNone; |
| 1863 | 1892 | } |
| 1864 | 1893 | #endif |
| ... | ... | @@ -1948,35 +1977,6 @@ Error os_file_open_lock_rw(Buf *full_path, OsFile *out_file) { |
| 1948 | 1977 | #endif |
| 1949 | 1978 | } |
| 1950 | 1979 | |
| 1951 | | Error os_file_mtime(OsFile file, OsTimeStamp *mtime) { |
| 1952 | | #if defined(ZIG_OS_WINDOWS) |
| 1953 | | FILETIME last_write_time; |
| 1954 | | if (!GetFileTime(file, nullptr, nullptr, &last_write_time)) |
| 1955 | | return ErrorUnexpected; |
| 1956 | | mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; |
| 1957 | | mtime->nsec = 0; |
| 1958 | | return ErrorNone; |
| 1959 | | #elif defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 1960 | | struct stat statbuf; |
| 1961 | | if (fstat(file, &statbuf) == -1) |
| 1962 | | return ErrorFileSystem; |
| 1963 | | |
| 1964 | | mtime->sec = statbuf.st_mtim.tv_sec; |
| 1965 | | mtime->nsec = statbuf.st_mtim.tv_nsec; |
| 1966 | | return ErrorNone; |
| 1967 | | #elif defined(ZIG_OS_DARWIN) |
| 1968 | | struct stat statbuf; |
| 1969 | | if (fstat(file, &statbuf) == -1) |
| 1970 | | return ErrorFileSystem; |
| 1971 | | |
| 1972 | | mtime->sec = statbuf.st_mtimespec.tv_sec; |
| 1973 | | mtime->nsec = statbuf.st_mtimespec.tv_nsec; |
| 1974 | | return ErrorNone; |
| 1975 | | #else |
| 1976 | | #error unimplemented |
| 1977 | | #endif |
| 1978 | | } |
| 1979 | | |
| 1980 | 1980 | Error os_file_read(OsFile file, void *ptr, size_t *len) { |
| 1981 | 1981 | #if defined(ZIG_OS_WINDOWS) |
| 1982 | 1982 | DWORD amt_read; |