X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwin32_replacements.c;h=527d4345264484123afde97f7b8e1bbc6fc06ef9;hb=7dba3a8ea5918399518f350c3071f986cf1d050a;hp=d3757a3f35ed843039e8c9f085f28a90386a9f3d;hpb=2159b8808998d2a75380ef6339147e48a39e3bae;p=wimlib diff --git a/src/win32_replacements.c b/src/win32_replacements.c index d3757a3f..527d4345 100644 --- a/src/win32_replacements.c +++ b/src/win32_replacements.c @@ -37,6 +37,7 @@ #include "wimlib/file_io.h" #include "wimlib/glob.h" #include "wimlib/error.h" +#include "wimlib/wildcard.h" #include "wimlib/util.h" /* Replacement for POSIX fsync() */ @@ -57,7 +58,7 @@ err: return -1; } -/* Use the Win32 API to get the number of processors */ +/* Use the Win32 API to get the number of processors. */ unsigned win32_get_number_of_processors(void) { @@ -66,6 +67,17 @@ win32_get_number_of_processors(void) return sysinfo.dwNumberOfProcessors; } +/* Use the Win32 API to get the amount of available memory. */ +u64 +win32_get_avail_memory(void) +{ + MEMORYSTATUSEX status = { + .dwLength = sizeof(status), + }; + GlobalMemoryStatusEx(&status); + return status.ullTotalPhys; +} + /* Replacement for POSIX-2008 realpath(). Warning: partial functionality only * (resolved_path must be NULL). Also I highly doubt that GetFullPathName * really does the right thing under all circumstances. */ @@ -88,7 +100,7 @@ realpath(const wchar_t *path, wchar_t *resolved_path) ret = GetFullPathNameW(path, ret, resolved_path, NULL); if (!ret) { err = GetLastError(); - free(resolved_path); + FREE(resolved_path); resolved_path = NULL; goto fail_win32; } @@ -299,6 +311,7 @@ pwrite(int fd, const void *buf, size_t count, off_t offset) return do_pread_or_pwrite(fd, (void*)buf, count, offset, true); } +#if 0 /* Dumb Windows implementation of writev(). It writes the vectors one at a * time. */ ssize_t writev(int fd, const struct iovec *iov, int iovcnt) @@ -323,6 +336,7 @@ ssize_t writev(int fd, const struct iovec *iov, int iovcnt) } return total_bytes_written; } +#endif int win32_get_file_and_vol_ids(const wchar_t *path, u64 *ino_ret, u64 *dev_ret) @@ -366,6 +380,7 @@ win32_wglob(const wchar_t *pattern, int flags, HANDLE hFind; int ret; size_t nspaces; + int errno_save; const wchar_t *backslash, *end_slash; size_t prefix_len; @@ -395,9 +410,7 @@ win32_wglob(const wchar_t *pattern, int flags, errno = 0; return GLOB_NOMATCH; } else { - /* The other possible error codes for FindFirstFile() - * are undocumented. */ - errno = EIO; + set_errno_from_win32_error(err); return GLOB_ABORTED; } } @@ -431,22 +444,21 @@ win32_wglob(const wchar_t *pattern, int flags, } while (FindNextFileW(hFind, &dat)); err = GetLastError(); CloseHandle(hFind); - if (err == ERROR_NO_MORE_FILES) { - errno = 0; - return 0; - } else { - /* Other possible error codes for FindNextFile() are - * undocumented */ - errno = EIO; + if (err != ERROR_NO_MORE_FILES) { + set_errno_from_win32_error(err); ret = GLOB_ABORTED; goto fail_globfree; } + return 0; + oom: CloseHandle(hFind); errno = ENOMEM; ret = GLOB_NOSPACE; fail_globfree: + errno_save = errno; globfree(pglob); + errno = errno_save; return ret; } @@ -455,8 +467,8 @@ globfree(glob_t *pglob) { size_t i; for (i = 0; i < pglob->gl_pathc; i++) - free(pglob->gl_pathv[i]); - free(pglob->gl_pathv); + FREE(pglob->gl_pathv[i]); + FREE(pglob->gl_pathv); } #endif /* __WIN32__ */