X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwin32_replacements.c;h=17861ef72d02be5349254b55f375b08c9049191c;hb=0e8ba68f2bd5e3f844611b93b6335e0a24f5c327;hp=36cc8a357e884a177c41b89eb9eee7c2493c7b02;hpb=e8c3ca2d1d0cac3d64985b45a9f654d2029a7518;p=wimlib diff --git a/src/win32_replacements.c b/src/win32_replacements.c index 36cc8a35..17861ef7 100644 --- a/src/win32_replacements.c +++ b/src/win32_replacements.c @@ -92,7 +92,7 @@ realpath(const wchar_t *path, wchar_t *resolved_path) } goto out; fail_win32: - errno = win32_error_to_errno(err); + set_errno_from_win32_error(err); out: return resolved_path; } @@ -146,7 +146,7 @@ fail_close_handle: fail: if (err == NO_ERROR) err = GetLastError(); - errno = win32_error_to_errno(err); + set_errno_from_win32_error(err); return -1; } @@ -177,12 +177,15 @@ do_pread_or_pwrite(int fd, void *buf, size_t count, off_t offset, OVERLAPPED overlapped; BOOL bret; - wimlib_assert(count <= 0xffffffff); - h = (HANDLE)_get_osfhandle(fd); if (h == INVALID_HANDLE_VALUE) goto err; + if (GetFileType(h) == FILE_TYPE_PIPE) { + errno = ESPIPE; + goto err; + } + /* Get original position */ relative_offset.QuadPart = 0; if (!SetFilePointerEx(h, relative_offset, &orig_offset, FILE_CURRENT)) @@ -257,26 +260,18 @@ ssize_t writev(int fd, const struct iovec *iov, int iovcnt) int win32_get_file_and_vol_ids(const wchar_t *path, u64 *ino_ret, u64 *dev_ret) { - HANDLE hFile; - DWORD err; + HANDLE h; BY_HANDLE_FILE_INFORMATION file_info; int ret; + DWORD err; - hFile = win32_open_existing_file(path, FILE_READ_ATTRIBUTES); - if (hFile == INVALID_HANDLE_VALUE) { - err = GetLastError(); - if (err != ERROR_FILE_NOT_FOUND) { - WARNING("Failed to open \"%ls\" to get file " - "and volume IDs", path); - win32_error(err); - } - return WIMLIB_ERR_OPEN; + h = win32_open_existing_file(path, FILE_READ_ATTRIBUTES); + if (h == INVALID_HANDLE_VALUE) { + ret = WIMLIB_ERR_OPEN; + goto out; } - if (!GetFileInformationByHandle(hFile, &file_info)) { - err = GetLastError(); - ERROR("Failed to get file information for \"%ls\"", path); - win32_error(err); + if (!GetFileInformationByHandle(h, &file_info)) { ret = WIMLIB_ERR_STAT; } else { *ino_ret = ((u64)file_info.nFileIndexHigh << 32) | @@ -284,7 +279,11 @@ win32_get_file_and_vol_ids(const wchar_t *path, u64 *ino_ret, u64 *dev_ret) *dev_ret = file_info.dwVolumeSerialNumber; ret = 0; } - CloseHandle(hFile); + err = GetLastError(); + CloseHandle(h); + SetLastError(err); +out: + set_errno_from_GetLastError(); return ret; }