diff options
author | mturk <mturk@13f79535-47bb-0310-9956-ffa450edef68> | 2021-12-02 22:03:51 +0000 |
---|---|---|
committer | mturk <mturk@13f79535-47bb-0310-9956-ffa450edef68> | 2021-12-02 22:03:51 +0000 |
commit | dc4038deee82573cf1d33ae1b07d81a68ff9c833 (patch) | |
tree | 01385a10f35737e7cba3aa46bbf1f47b7227ae9b /file_io/win32 | |
parent | 6e0ddafc35dba220f7e7c5b134b44b14f7c5974c (diff) | |
download | libapr-dc4038deee82573cf1d33ae1b07d81a68ff9c833.tar.gz |
Stage 2 in cleaning win95 code ... cleanup filesys
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1895510 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/win32')
-rw-r--r-- | file_io/win32/filestat.c | 237 | ||||
-rw-r--r-- | file_io/win32/filesys.c | 165 | ||||
-rw-r--r-- | file_io/win32/open.c | 293 | ||||
-rw-r--r-- | file_io/win32/pipe.c | 10 |
4 files changed, 208 insertions, 497 deletions
diff --git a/file_io/win32/filestat.c b/file_io/win32/filestat.c index 38fb2dc4f..3f2a391d1 100644 --- a/file_io/win32/filestat.c +++ b/file_io/win32/filestat.c @@ -229,47 +229,26 @@ static int reparse_point_is_link(WIN32_FILE_ATTRIBUTE_DATA *wininfo, } else { + apr_wchar_t wfname[APR_PATH_MAX]; + HANDLE hFind; + WIN32_FIND_DATAW fd; + if (test_safe_name(fname) != APR_SUCCESS) { return 0; } -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wfname[APR_PATH_MAX]; - HANDLE hFind; - WIN32_FIND_DATAW fd; - - if (utf8_to_unicode_path(wfname, APR_PATH_MAX, fname) != APR_SUCCESS) { - return 0; - } - - hFind = FindFirstFileW(wfname, &fd); - if (hFind == INVALID_HANDLE_VALUE) { - return 0; - } - - FindClose(hFind); + if (utf8_to_unicode_path(wfname, APR_PATH_MAX, fname) != APR_SUCCESS) { + return 0; + } - tag = fd.dwReserved0; - } -#endif -#if APR_HAS_ANSI_FS || 1 - ELSE_WIN_OS_IS_ANSI - { - HANDLE hFind; - WIN32_FIND_DATAA fd; + hFind = FindFirstFileW(wfname, &fd); + if (hFind == INVALID_HANDLE_VALUE) { + return 0; + } - hFind = FindFirstFileA(fname, &fd); - if (hFind == INVALID_HANDLE_VALUE) { - return 0; - } + FindClose(hFind); - FindClose(hFind); - - tag = fd.dwReserved0; - } -#endif + tag = fd.dwReserved0; } // Test "Name surrogate bit" to detect any kind of symbolic link @@ -571,10 +550,7 @@ APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname, int isroot = 0; apr_status_t ident_rv = 0; apr_status_t rv; -#if APR_HAS_UNICODE_FS apr_wchar_t wfname[APR_PATH_MAX]; - -#endif char *filename = NULL; /* These all share a common subset of this structure */ union { @@ -592,123 +568,59 @@ APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname, return APR_ENAMETOOLONG; } -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - if ((wanted & (APR_FINFO_IDENT | APR_FINFO_NLINK)) - || (~wanted & APR_FINFO_LINK)) { - /* FindFirstFile and GetFileAttributesEx can't figure the inode, - * device or number of links, so we need to resolve with an open - * file handle. If the user has asked for these fields, fall over - * to the get file info by handle method. If we fail, or the user - * also asks for the file name, continue by our usual means. - * - * We also must use this method for a 'true' stat, that resolves - * a symlink (NTFS Junction) target. This is because all fileinfo - * on a Junction always returns the junction, opening the target - * is the only way to resolve the target's attributes. - */ - if ((ident_rv = resolve_ident(finfo, fname, wanted, pool)) - == APR_SUCCESS) - return ident_rv; - else if (ident_rv == APR_INCOMPLETE) - wanted &= ~finfo->valid; - } - - if ((rv = utf8_to_unicode_path(wfname, sizeof(wfname) - / sizeof(apr_wchar_t), fname))) - return rv; - if (!(wanted & (APR_FINFO_NAME | APR_FINFO_LINK))) { - if (!GetFileAttributesExW(wfname, GetFileExInfoStandard, - &FileInfo.i)) - return apr_get_os_error(); - } - else { - /* Guard against bogus wildcards and retrieve by name - * since we want the true name, and set aside a long - * enough string to handle the longest file name. - */ - HANDLE hFind; - if ((rv = test_safe_name(fname)) != APR_SUCCESS) { - return rv; - } - hFind = FindFirstFileW(wfname, &FileInfo.w); - if (hFind == INVALID_HANDLE_VALUE) - return apr_get_os_error(); - FindClose(hFind); - finddata = 1; - - if (wanted & APR_FINFO_NAME) - { - char tmpname[APR_FILE_MAX * 3 + 1]; - if (unicode_to_utf8_path(tmpname, sizeof(tmpname), - FileInfo.w.cFileName)) { - return APR_ENAMETOOLONG; - } - filename = apr_pstrdup(pool, tmpname); - } - } - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - const char *root = NULL; - const char *test = fname; - rv = apr_filepath_root(&root, &test, APR_FILEPATH_NATIVE, pool); - isroot = (root && *root && !(*test)); - - if ((apr_os_level >= APR_WIN_98) && (!(wanted & (APR_FINFO_NAME | APR_FINFO_LINK)) || isroot)) - { - /* cannot use FindFile on a Win98 root, it returns \* - * GetFileAttributesExA is not available on Win95 - */ - if (!GetFileAttributesExA(fname, GetFileExInfoStandard, - &FileInfo.i)) { - return apr_get_os_error(); - } - } - else if (isroot) { - /* This is Win95 and we are trying to stat a root. Lie. - */ - if (GetDriveType(fname) != DRIVE_UNKNOWN) - { - finfo->pool = pool; - finfo->filetype = 0; - finfo->mtime = apr_time_now(); - finfo->protection |= APR_FPROT_WREAD | APR_FPROT_WEXECUTE | APR_FPROT_WWRITE; - finfo->protection |= (finfo->protection << prot_scope_group) - | (finfo->protection << prot_scope_user); - finfo->valid |= APR_FINFO_TYPE | APR_FINFO_PROT - | APR_FINFO_MTIME - | (wanted & APR_FINFO_LINK); - return (wanted &= ~finfo->valid) ? APR_INCOMPLETE - : APR_SUCCESS; - } - else - return APR_FROM_OS_ERROR(ERROR_PATH_NOT_FOUND); - } - else { - /* Guard against bogus wildcards and retrieve by name - * since we want the true name, or are stuck in Win95, - * or are looking for the root of a Win98 drive. - */ - HANDLE hFind; - if ((rv = test_safe_name(fname)) != APR_SUCCESS) { - return rv; - } - hFind = FindFirstFileA(fname, &FileInfo.n); - if (hFind == INVALID_HANDLE_VALUE) { - return apr_get_os_error(); - } - FindClose(hFind); - finddata = 1; - if (wanted & APR_FINFO_NAME) { - filename = apr_pstrdup(pool, FileInfo.n.cFileName); - } - } - } -#endif + if ((wanted & (APR_FINFO_IDENT | APR_FINFO_NLINK)) + || (~wanted & APR_FINFO_LINK)) { + /* FindFirstFile and GetFileAttributesEx can't figure the inode, + * device or number of links, so we need to resolve with an open + * file handle. If the user has asked for these fields, fall over + * to the get file info by handle method. If we fail, or the user + * also asks for the file name, continue by our usual means. + * + * We also must use this method for a 'true' stat, that resolves + * a symlink (NTFS Junction) target. This is because all fileinfo + * on a Junction always returns the junction, opening the target + * is the only way to resolve the target's attributes. + */ + if ((ident_rv = resolve_ident(finfo, fname, wanted, pool)) + == APR_SUCCESS) + return ident_rv; + else if (ident_rv == APR_INCOMPLETE) + wanted &= ~finfo->valid; + } + + if ((rv = utf8_to_unicode_path(wfname, sizeof(wfname) + / sizeof(apr_wchar_t), fname))) + return rv; + if (!(wanted & (APR_FINFO_NAME | APR_FINFO_LINK))) { + if (!GetFileAttributesExW(wfname, GetFileExInfoStandard, + &FileInfo.i)) + return apr_get_os_error(); + } + else { + /* Guard against bogus wildcards and retrieve by name + * since we want the true name, and set aside a long + * enough string to handle the longest file name. + */ + HANDLE hFind; + if ((rv = test_safe_name(fname)) != APR_SUCCESS) { + return rv; + } + hFind = FindFirstFileW(wfname, &FileInfo.w); + if (hFind == INVALID_HANDLE_VALUE) + return apr_get_os_error(); + FindClose(hFind); + finddata = 1; + + if (wanted & APR_FINFO_NAME) + { + char tmpname[APR_FILE_MAX * 3 + 1]; + if (unicode_to_utf8_path(tmpname, sizeof(tmpname), + FileInfo.w.cFileName)) { + return APR_ENAMETOOLONG; + } + filename = apr_pstrdup(pool, tmpname); + } + } if (ident_rv != APR_INCOMPLETE) { if (fillin_fileinfo(finfo, (WIN32_FILE_ATTRIBUTE_DATA *) &FileInfo, @@ -720,23 +632,12 @@ APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname, */ if (apr_os_level >= APR_WIN_NT) { -#if APR_HAS_UNICODE_FS apr_wchar_t tmpname[APR_FILE_MAX]; apr_wchar_t *tmpoff = NULL; if (GetFullPathNameW(wfname, sizeof(tmpname) / sizeof(apr_wchar_t), tmpname, &tmpoff)) { if (!wcsncmp(tmpname, L"\\\\.\\", 4)) { -#else - /* Same initial logic as above, but - * only for WinNT/non-UTF-8 builds of APR: - */ - char tmpname[APR_FILE_MAX]; - char *tmpoff; - if (GetFullPathName(fname, sizeof(tmpname), tmpname, &tmpoff)) - { - if (!strncmp(tmpname, "\\\\.\\", 4)) { -#endif if (tmpoff == tmpname + 4) { finfo->filetype = APR_CHR; } @@ -780,11 +681,7 @@ APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname, if (wanted &= ~finfo->valid) { /* Caller wants more than APR_FINFO_MIN | APR_FINFO_NAME */ -#if APR_HAS_UNICODE_FS - if (apr_os_level >= APR_WIN_NT) - return more_finfo(finfo, wfname, wanted, MORE_OF_WFSPEC); -#endif - return more_finfo(finfo, fname, wanted, MORE_OF_FSPEC); + return more_finfo(finfo, wfname, wanted, MORE_OF_WFSPEC); } return APR_SUCCESS; diff --git a/file_io/win32/filesys.c b/file_io/win32/filesys.c index e81213955..2a23c8f68 100644 --- a/file_io/win32/filesys.c +++ b/file_io/win32/filesys.c @@ -66,18 +66,12 @@ const char apr_c_is_fnchar[256] = apr_status_t filepath_root_test(char *path, apr_pool_t *p) { apr_status_t rv; -#if APR_HAS_UNICODE_FS - if (apr_os_level >= APR_WIN_NT) - { - apr_wchar_t wpath[APR_PATH_MAX]; - if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) - / sizeof(apr_wchar_t), path))) - return rv; - rv = GetDriveTypeW(wpath); - } - else -#endif - rv = GetDriveType(path); + apr_wchar_t wpath[APR_PATH_MAX]; + + if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) + / sizeof(apr_wchar_t), path))) + return rv; + rv = GetDriveTypeW(wpath); if (rv == DRIVE_UNKNOWN || rv == DRIVE_NO_ROOT_DIR) return APR_EBADPATH; @@ -89,37 +83,19 @@ apr_status_t filepath_drive_get(char **rootpath, char drive, apr_int32_t flags, apr_pool_t *p) { char path[APR_PATH_MAX]; -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t *ignored; - apr_wchar_t wdrive[8]; - apr_wchar_t wpath[APR_PATH_MAX]; - apr_status_t rv; - /* ???: This needs review, apparently "\\?\d:." returns "\\?\d:" - * as if that is useful for anything. - */ - wcscpy(wdrive, L"D:."); - wdrive[0] = (apr_wchar_t)(unsigned char)drive; - if (!GetFullPathNameW(wdrive, sizeof(wpath) / sizeof(apr_wchar_t), wpath, &ignored)) - return apr_get_os_error(); - if ((rv = unicode_to_utf8_path(path, sizeof(path), wpath))) - return rv; - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - char *ignored; - char drivestr[4]; - drivestr[0] = drive; - drivestr[1] = ':'; - drivestr[2] = '.';; - drivestr[3] = '\0'; - if (!GetFullPathName(drivestr, sizeof(path), path, &ignored)) - return apr_get_os_error(); - } -#endif + apr_wchar_t *ignored; + apr_wchar_t wdrive[8]; + apr_wchar_t wpath[APR_PATH_MAX]; + apr_status_t rv; + /* ???: This needs review, apparently "\\?\d:." returns "\\?\d:" + * as if that is useful for anything. + */ + wcscpy(wdrive, L"D:."); + wdrive[0] = (apr_wchar_t)(unsigned char)drive; + if (!GetFullPathNameW(wdrive, sizeof(wpath) / sizeof(apr_wchar_t), wpath, &ignored)) + return apr_get_os_error(); + if ((rv = unicode_to_utf8_path(path, sizeof(path), wpath))) + return rv; if (!(flags & APR_FILEPATH_NATIVE)) { for (*rootpath = path; **rootpath; ++*rootpath) { if (**rootpath == '\\') @@ -133,39 +109,24 @@ apr_status_t filepath_drive_get(char **rootpath, char drive, apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p) { -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t *ignored; - apr_wchar_t wpath[APR_PATH_MAX]; - apr_status_t rv; - apr_wchar_t wroot[APR_PATH_MAX]; - /* ???: This needs review, apparently "\\?\d:." returns "\\?\d:" - * as if that is useful for anything. - */ - if ((rv = utf8_to_unicode_path(wroot, sizeof(wroot) - / sizeof(apr_wchar_t), root))) - return rv; - if (!GetFullPathNameW(wroot, sizeof(wpath) / sizeof(apr_wchar_t), wpath, &ignored)) - return apr_get_os_error(); - - /* Borrow wroot as a char buffer (twice as big as necessary) - */ - if ((rv = unicode_to_utf8_path((char*)wroot, sizeof(wroot), wpath))) - return rv; - *rootpath = apr_pstrdup(p, (char*)wroot); - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - char path[APR_PATH_MAX]; - char *ignored; - if (!GetFullPathName(root, sizeof(path), path, &ignored)) - return apr_get_os_error(); - *rootpath = apr_pstrdup(p, path); - } -#endif + apr_wchar_t *ignored; + apr_wchar_t wpath[APR_PATH_MAX]; + apr_status_t rv; + apr_wchar_t wroot[APR_PATH_MAX]; + /* ???: This needs review, apparently "\\?\d:." returns "\\?\d:" + * as if that is useful for anything. + */ + if ((rv = utf8_to_unicode_path(wroot, sizeof(wroot) + / sizeof(apr_wchar_t), root))) + return rv; + if (!GetFullPathNameW(wroot, sizeof(wpath) / sizeof(apr_wchar_t), wpath, &ignored)) + return apr_get_os_error(); + + /* Borrow wroot as a char buffer (twice as big as necessary) + */ + if ((rv = unicode_to_utf8_path((char*)wroot, sizeof(wroot), wpath))) + return rv; + *rootpath = apr_pstrdup(p, (char*)wroot); return APR_SUCCESS; } @@ -174,24 +135,13 @@ APR_DECLARE(apr_status_t) apr_filepath_get(char **rootpath, apr_int32_t flags, apr_pool_t *p) { char path[APR_PATH_MAX]; -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wpath[APR_PATH_MAX]; - apr_status_t rv; - if (!GetCurrentDirectoryW(sizeof(wpath) / sizeof(apr_wchar_t), wpath)) - return apr_get_os_error(); - if ((rv = unicode_to_utf8_path(path, sizeof(path), wpath))) - return rv; - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - if (!GetCurrentDirectory(sizeof(path), path)) - return apr_get_os_error(); - } -#endif + apr_wchar_t wpath[APR_PATH_MAX]; + apr_status_t rv; + + if (!GetCurrentDirectoryW(sizeof(wpath) / sizeof(apr_wchar_t), wpath)) + return apr_get_os_error(); + if ((rv = unicode_to_utf8_path(path, sizeof(path), wpath))) + return rv; if (!(flags & APR_FILEPATH_NATIVE)) { for (*rootpath = path; **rootpath; ++*rootpath) { if (**rootpath == '\\') @@ -206,24 +156,13 @@ APR_DECLARE(apr_status_t) apr_filepath_get(char **rootpath, apr_int32_t flags, APR_DECLARE(apr_status_t) apr_filepath_set(const char *rootpath, apr_pool_t *p) { -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wpath[APR_PATH_MAX]; - apr_status_t rv; - if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) - / sizeof(apr_wchar_t), rootpath))) - return rv; - if (!SetCurrentDirectoryW(wpath)) - return apr_get_os_error(); - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - if (!SetCurrentDirectory(rootpath)) - return apr_get_os_error(); - } -#endif + apr_wchar_t wpath[APR_PATH_MAX]; + apr_status_t rv; + + if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) + / sizeof(apr_wchar_t), rootpath))) + return rv; + if (!SetCurrentDirectoryW(wpath)) + return apr_get_os_error(); return APR_SUCCESS; } diff --git a/file_io/win32/open.c b/file_io/win32/open.c index 864af587c..5530591eb 100644 --- a/file_io/win32/open.c +++ b/file_io/win32/open.c @@ -34,7 +34,6 @@ #include <io.h> #include <winioctl.h> -#if APR_HAS_UNICODE_FS apr_status_t utf8_to_unicode_path(apr_wchar_t* retstr, apr_size_t retlen, const char* srcstr) { @@ -135,94 +134,45 @@ apr_status_t unicode_to_utf8_path(char* retstr, apr_size_t retlen, } return APR_SUCCESS; } -#endif void *res_name_from_filename(const char *file, int global, apr_pool_t *pool) { -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t *wpre, *wfile, *ch; - apr_size_t n = strlen(file) + 1; - apr_size_t r, d; - - if (apr_os_level >= APR_WIN_2000) { - if (global) - wpre = L"Global\\"; - else - wpre = L"Local\\"; - } - else - wpre = L""; - r = wcslen(wpre); - - if (n > 256 - r) { - file += n - 256 - r; - n = 256; - /* skip utf8 continuation bytes */ - while ((*file & 0xC0) == 0x80) { - ++file; - --n; - } - } - wfile = apr_palloc(pool, (r + n) * sizeof(apr_wchar_t)); - wcscpy(wfile, wpre); - d = n; - if (apr_conv_utf8_to_utf16(file, &n, wfile + r, &d)) { - return NULL; - } - for (ch = wfile + r; *ch; ++ch) { - if (*ch == ':' || *ch == '/' || *ch == '\\') - *ch = '_'; - } - return wfile; - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - char *nfile, *ch; - apr_size_t n = strlen(file) + 1; - -#if !APR_HAS_UNICODE_FS - apr_size_t r, d; - char *pre; - - if (apr_os_level >= APR_WIN_2000) { - if (global) - pre = "Global\\"; - else - pre = "Local\\"; - } - else - pre = ""; - r = strlen(pre); - - if (n > 256 - r) { - file += n - 256 - r; - n = 256; - } - nfile = apr_palloc(pool, (r + n) * sizeof(apr_wchar_t)); - memcpy(nfile, pre, r); - memcpy(nfile + r, file, n); -#else - const apr_size_t r = 0; - if (n > 256) { - file += n - 256; - n = 256; - } - nfile = apr_pmemdup(pool, file, n); -#endif - for (ch = nfile + r; *ch; ++ch) { - if (*ch == ':' || *ch == '/' || *ch == '\\') - *ch = '_'; - } - return nfile; - } -#endif + apr_wchar_t *wpre, *wfile, *ch; + apr_size_t n = strlen(file) + 1; + apr_size_t r, d; + + if (apr_os_level >= APR_WIN_2000) { + if (global) + wpre = L"Global\\"; + else + wpre = L"Local\\"; + } + else + wpre = L""; + r = wcslen(wpre); + + if (n > 256 - r) { + file += n - 256 - r; + n = 256; + /* skip utf8 continuation bytes */ + while ((*file & 0xC0) == 0x80) { + ++file; + --n; + } + } + wfile = apr_palloc(pool, (r + n) * sizeof(apr_wchar_t)); + wcscpy(wfile, wpre); + d = n; + if (apr_conv_utf8_to_utf16(file, &n, wfile + r, &d)) { + return NULL; + } + for (ch = wfile + r; *ch; ++ch) { + if (*ch == ':' || *ch == '/' || *ch == '\\') + *ch = '_'; + } + return wfile; } -#if APR_HAS_UNICODE_FS static apr_status_t make_sparse_file(apr_file_t *file) { BY_HANDLE_FILE_INFORMATION info; @@ -269,7 +219,6 @@ static apr_status_t make_sparse_file(apr_file_t *file) } return rv; } -#endif apr_status_t file_cleanup(void *thefile) { @@ -325,6 +274,8 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, DWORD attributes = 0; DWORD sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE; apr_status_t rv; + apr_wchar_t wfname[APR_PATH_MAX]; + if (flag & APR_FOPEN_NONBLOCK) { return APR_ENOTIMPL; @@ -400,34 +351,19 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, attributes |= FILE_FLAG_OVERLAPPED; } -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wfname[APR_PATH_MAX]; - - if (flag & APR_FOPEN_SENDFILE_ENABLED) { - /* This feature is required to enable sendfile operations - * against the file on Win32. Also implies APR_FOPEN_XTHREAD. - */ - flag |= APR_FOPEN_XTHREAD; - attributes |= FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED; - } + if (flag & APR_FOPEN_SENDFILE_ENABLED) { + /* This feature is required to enable sendfile operations + * against the file on Win32. Also implies APR_FOPEN_XTHREAD. + */ + flag |= APR_FOPEN_XTHREAD; + attributes |= FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED; + } - if ((rv = utf8_to_unicode_path(wfname, sizeof(wfname) - / sizeof(apr_wchar_t), fname))) - return rv; - handle = CreateFileW(wfname, oflags, sharemode, - NULL, createflags, attributes, 0); - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI { - handle = CreateFileA(fname, oflags, sharemode, - NULL, createflags, attributes, 0); - /* This feature is not supported on this platform. */ - flag &= ~APR_FOPEN_SENDFILE_ENABLED; - } -#endif + if ((rv = utf8_to_unicode_path(wfname, sizeof(wfname) + / sizeof(apr_wchar_t), fname))) + return rv; + handle = CreateFileW(wfname, oflags, sharemode, + NULL, createflags, attributes, 0); if (handle == INVALID_HANDLE_VALUE) { return apr_get_os_error(); } @@ -460,8 +396,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, } } -#if APR_HAS_UNICODE_FS - if ((apr_os_level >= APR_WIN_2000) && ((*new)->flags & APR_FOPEN_SPARSE)) { + if ((*new)->flags & APR_FOPEN_SPARSE) { if ((rv = make_sparse_file(*new)) != APR_SUCCESS) /* The great mystery; do we close the file and return an error? * Do we add a new APR_INCOMPLETE style error saying opened, but @@ -470,7 +405,6 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, (*new)->flags &= ~APR_FOPEN_SPARSE; } else -#endif /* This feature is not supported on this platform. */ (*new)->flags &= ~APR_FOPEN_SPARSE; @@ -503,24 +437,15 @@ APR_DECLARE(apr_status_t) apr_file_close(apr_file_t *file) APR_DECLARE(apr_status_t) apr_file_remove(const char *path, apr_pool_t *pool) { -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wpath[APR_PATH_MAX]; - apr_status_t rv; - if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) - / sizeof(apr_wchar_t), path))) { - return rv; - } - if (DeleteFileW(wpath)) - return APR_SUCCESS; - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - if (DeleteFile(path)) - return APR_SUCCESS; -#endif + apr_wchar_t wpath[APR_PATH_MAX]; + apr_status_t rv; + + if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) + / sizeof(apr_wchar_t), path))) { + return rv; + } + if (DeleteFileW(wpath)) + return APR_SUCCESS; return apr_get_os_error(); } @@ -528,52 +453,22 @@ APR_DECLARE(apr_status_t) apr_file_rename(const char *frompath, const char *topath, apr_pool_t *pool) { - IF_WIN_OS_IS_UNICODE - { -#if APR_HAS_UNICODE_FS - apr_wchar_t wfrompath[APR_PATH_MAX], wtopath[APR_PATH_MAX]; - apr_status_t rv; - if ((rv = utf8_to_unicode_path(wfrompath, - sizeof(wfrompath) / sizeof(apr_wchar_t), - frompath))) { - return rv; - } - if ((rv = utf8_to_unicode_path(wtopath, - sizeof(wtopath) / sizeof(apr_wchar_t), - topath))) { - return rv; - } - if (MoveFileExW(wfrompath, wtopath, MOVEFILE_REPLACE_EXISTING | - MOVEFILE_COPY_ALLOWED)) - return APR_SUCCESS; -#else - if (MoveFileEx(frompath, topath, MOVEFILE_REPLACE_EXISTING | - MOVEFILE_COPY_ALLOWED)) - return APR_SUCCESS; -#endif - } -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - { - /* Windows 95 and 98 do not support MoveFileEx, so we'll use - * the old MoveFile function. However, MoveFile requires that - * the new file not already exist...so we have to delete that - * file if it does. Perhaps we should back up the to-be-deleted - * file in case something happens? - */ - HANDLE handle = INVALID_HANDLE_VALUE; - - if ((handle = CreateFile(topath, GENERIC_WRITE, 0, 0, - OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE ) - { - CloseHandle(handle); - if (!DeleteFile(topath)) - return apr_get_os_error(); - } - if (MoveFile(frompath, topath)) - return APR_SUCCESS; - } -#endif + apr_wchar_t wfrompath[APR_PATH_MAX], wtopath[APR_PATH_MAX]; + apr_status_t rv; + + if ((rv = utf8_to_unicode_path(wfrompath, + sizeof(wfrompath) / sizeof(apr_wchar_t), + frompath))) { + return rv; + } + if ((rv = utf8_to_unicode_path(wtopath, + sizeof(wtopath) / sizeof(apr_wchar_t), + topath))) { + return rv; + } + if (MoveFileExW(wfrompath, wtopath, MOVEFILE_REPLACE_EXISTING | + MOVEFILE_COPY_ALLOWED)) + return APR_SUCCESS; return apr_get_os_error(); } @@ -581,32 +476,20 @@ APR_DECLARE(apr_status_t) apr_file_link(const char *from_path, const char *to_path) { apr_status_t rv = APR_SUCCESS; - -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - { - apr_wchar_t wfrom_path[APR_PATH_MAX]; - apr_wchar_t wto_path[APR_PATH_MAX]; - - if ((rv = utf8_to_unicode_path(wfrom_path, - sizeof(wfrom_path) / sizeof(apr_wchar_t), - from_path))) - return rv; - if ((rv = utf8_to_unicode_path(wto_path, - sizeof(wto_path) / sizeof(apr_wchar_t), - to_path))) - return rv; - - if (!CreateHardLinkW(wto_path, wfrom_path, NULL)) - return apr_get_os_error(); - } -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI { - if (!CreateHardLinkA(to_path, from_path, NULL)) - return apr_get_os_error(); - } -#endif + apr_wchar_t wfrom_path[APR_PATH_MAX]; + apr_wchar_t wto_path[APR_PATH_MAX]; + + if ((rv = utf8_to_unicode_path(wfrom_path, + sizeof(wfrom_path) / sizeof(apr_wchar_t), + from_path))) + return rv; + if ((rv = utf8_to_unicode_path(wto_path, + sizeof(wto_path) / sizeof(apr_wchar_t), + to_path))) + return rv; + + if (!CreateHardLinkW(wto_path, wfrom_path, NULL)) + return apr_get_os_error(); return rv; } diff --git a/file_io/win32/pipe.c b/file_io/win32/pipe.c index 46dd74924..22d186687 100644 --- a/file_io/win32/pipe.c +++ b/file_io/win32/pipe.c @@ -75,15 +75,7 @@ static apr_status_t file_pipe_create(apr_file_t **in, DWORD dwOpenMode; sa.nLength = sizeof(sa); - -#if APR_HAS_UNICODE_FS - IF_WIN_OS_IS_UNICODE - sa.bInheritHandle = FALSE; -#endif -#if APR_HAS_ANSI_FS - ELSE_WIN_OS_IS_ANSI - sa.bInheritHandle = TRUE; -#endif + sa.bInheritHandle = FALSE; sa.lpSecurityDescriptor = NULL; (*in) = (apr_file_t *)apr_pcalloc(pool_in, sizeof(apr_file_t)); |