| ... | ... | @@ -23,6 +23,14 @@ |
| 23 | 23 | #define WIN32_LEAN_AND_MEAN |
| 24 | 24 | #endif |
| 25 | 25 | |
| 26 | #if !defined(_WIN32_WINNT) |
| 27 | #define _WIN32_WINNT 0x600 |
| 28 | #endif |
| 29 | |
| 30 | #if !defined(NTDDI_VERSION) |
| 31 | #define NTDDI_VERSION 0x06000000 |
| 32 | #endif |
| 33 | |
| 26 | 34 | #include <windows.h> |
| 27 | 35 | #include <shlobj.h> |
| 28 | 36 | #include <io.h> |
| ... | ... | @@ -1634,16 +1642,16 @@ static Optional<uint32_t> Utf16LeIterator_nextCodepoint(Utf16LeIterator *it) { |
| 1634 | 1642 | if (it->bytes[it->i] == 0 && it->bytes[it->i + 1] == 0) |
| 1635 | 1643 | return {}; |
| 1636 | 1644 | uint32_t c0 = ((uint32_t)it->bytes[it->i]) | (((uint32_t)it->bytes[it->i + 1]) << 8); |
| 1637 | | if (c0 & ~((uint32_t)0x03ff) == 0xd800) { |
| 1645 | if ((c0 & ~((uint32_t)0x03ff)) == 0xd800) { |
| 1638 | 1646 | // surrogate pair |
| 1639 | 1647 | it->i += 2; |
| 1640 | 1648 | assert(it->bytes[it->i] != 0 || it->bytes[it->i + 1] != 0); |
| 1641 | 1649 | uint32_t c1 = ((uint32_t)it->bytes[it->i]) | (((uint32_t)it->bytes[it->i + 1]) << 8); |
| 1642 | | assert(c1 & ~((uint32_t)0x03ff) == 0xdc00); |
| 1650 | assert((c1 & ~((uint32_t)0x03ff)) == 0xdc00); |
| 1643 | 1651 | it->i += 2; |
| 1644 | 1652 | return Optional<uint32_t>::some(0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff))); |
| 1645 | 1653 | } else { |
| 1646 | | assert(c0 & ~((uint32_t)0x03ff) != 0xdc00); |
| 1654 | assert((c0 & ~((uint32_t)0x03ff)) != 0xdc00); |
| 1647 | 1655 | it->i += 2; |
| 1648 | 1656 | return Optional<uint32_t>::some(c0); |
| 1649 | 1657 | } |
| ... | ... | @@ -1714,7 +1722,7 @@ static void utf16le_ptr_to_utf8(Buf *out, WCHAR *utf16le) { |
| 1714 | 1722 | // Ported from std.os.getAppDataDir |
| 1715 | 1723 | Error os_get_app_data_dir(Buf *out_path, const char *appname) { |
| 1716 | 1724 | #if defined(ZIG_OS_WINDOWS) |
| 1717 | | Error err; |
| 1725 | // Error err; |
| 1718 | 1726 | WCHAR *dir_path_ptr; |
| 1719 | 1727 | switch (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &dir_path_ptr)) { |
| 1720 | 1728 | case S_OK: |
| ... | ... | @@ -1928,7 +1936,8 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) { |
| 1928 | 1936 | FILETIME last_write_time; |
| 1929 | 1937 | if (!GetFileTime(file, nullptr, nullptr, &last_write_time)) |
| 1930 | 1938 | return ErrorUnexpected; |
| 1931 | | mtime->sec = last_write_time.dwLowDateTime | (last_write_time.dwHighDateTime << 32); |
| 1939 | // mtime->sec = last_write_time.dwLowDateTime | (last_write_time.dwHighDateTime << 32); |
| 1940 | mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; |
| 1932 | 1941 | mtime->nsec = 0; |
| 1933 | 1942 | return ErrorNone; |
| 1934 | 1943 | #elif defined(ZIG_OS_LINUX) |
| ... | ... | @@ -2007,11 +2016,12 @@ Error os_file_read_all(OsFile file, Buf *contents) { |
| 2007 | 2016 | |
| 2008 | 2017 | Error os_file_overwrite(OsFile file, Buf *contents) { |
| 2009 | 2018 | #if defined(ZIG_OS_WINDOWS) |
| 2019 | DWORD bytes_written; |
| 2010 | 2020 | if (SetFilePointer(file, 0, nullptr, FILE_BEGIN) == INVALID_SET_FILE_POINTER) |
| 2011 | 2021 | return ErrorFileSystem; |
| 2012 | 2022 | if (!SetEndOfFile(file)) |
| 2013 | 2023 | return ErrorFileSystem; |
| 2014 | | if (!WriteFile(file, buf_ptr(contents), buf_len(contents), nullptr, nullptr)) |
| 2024 | if (!WriteFile(file, buf_ptr(contents), buf_len(contents), &bytes_written, nullptr)) |
| 2015 | 2025 | return ErrorFileSystem; |
| 2016 | 2026 | return ErrorNone; |
| 2017 | 2027 | #else |