diff options
Diffstat (limited to 'srclib/apr/file_io/win32')
-rw-r--r-- | srclib/apr/file_io/win32/dir.c | 24 | ||||
-rw-r--r-- | srclib/apr/file_io/win32/filedup.c | 3 | ||||
-rw-r--r-- | srclib/apr/file_io/win32/filepath.c | 26 | ||||
-rw-r--r-- | srclib/apr/file_io/win32/filestat.c | 20 | ||||
-rw-r--r-- | srclib/apr/file_io/win32/filesys.c | 12 | ||||
-rw-r--r-- | srclib/apr/file_io/win32/open.c | 82 | ||||
-rw-r--r-- | srclib/apr/file_io/win32/pipe.c | 67 | ||||
-rw-r--r-- | srclib/apr/file_io/win32/readwrite.c | 8 | ||||
-rw-r--r-- | srclib/apr/file_io/win32/seek.c | 8 |
9 files changed, 152 insertions, 98 deletions
diff --git a/srclib/apr/file_io/win32/dir.c b/srclib/apr/file_io/win32/dir.c index 9e16bc19..574e7270 100644 --- a/srclib/apr/file_io/win32/dir.c +++ b/srclib/apr/file_io/win32/dir.c @@ -76,8 +76,8 @@ APR_DECLARE(apr_status_t) apr_dir_open(apr_dir_t **new, const char *dirname, ELSE_WIN_OS_IS_ANSI { /* Note that we won't open a directory that is greater than MAX_PATH, - * including the trailing /* wildcard suffix. If a * won't fit, then - * neither will any other file name within the directory. + * counting the additional '/' '*' wildcard suffix. If a * won't fit + * then neither will any other file name within the directory. * The length not including the trailing '*' is stored as rootlen, to * skip over all paths which are too long. */ @@ -128,9 +128,9 @@ APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted, if (thedir->dirhand == INVALID_HANDLE_VALUE) { apr_status_t rv; - if (rv = utf8_to_unicode_path(wdirname, sizeof(wdirname) - / sizeof(apr_wchar_t), - thedir->dirname)) { + if ((rv = utf8_to_unicode_path(wdirname, sizeof(wdirname) + / sizeof(apr_wchar_t), + thedir->dirname))) { return rv; } eos = wcschr(wdirname, '\0'); @@ -162,8 +162,8 @@ APR_DECLARE(apr_status_t) apr_dir_read(apr_finfo_t *finfo, apr_int32_t wanted, return apr_get_os_error(); } } - if (rv = unicode_to_utf8_path(thedir->name, APR_FILE_MAX * 3 + 1, - thedir->w.entry->cFileName)) + if ((rv = unicode_to_utf8_path(thedir->name, APR_FILE_MAX * 3 + 1, + thedir->w.entry->cFileName))) return rv; fname = thedir->name; } @@ -280,8 +280,9 @@ APR_DECLARE(apr_status_t) apr_dir_make(const char *path, apr_fileperms_t perm, { 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)) { + if ((rv = utf8_to_unicode_path(wpath, + sizeof(wpath) / sizeof(apr_wchar_t), + path))) { return rv; } if (!CreateDirectoryW(wpath, NULL)) { @@ -357,8 +358,9 @@ APR_DECLARE(apr_status_t) apr_dir_remove(const char *path, apr_pool_t *pool) { 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)) { + if ((rv = utf8_to_unicode_path(wpath, + sizeof(wpath) / sizeof(apr_wchar_t), + path))) { return rv; } if (!RemoveDirectoryW(wpath)) { diff --git a/srclib/apr/file_io/win32/filedup.c b/srclib/apr/file_io/win32/filedup.c index e96ef2bc..b44b2561 100644 --- a/srclib/apr/file_io/win32/filedup.c +++ b/srclib/apr/file_io/win32/filedup.c @@ -71,7 +71,6 @@ APR_DECLARE(apr_status_t) apr_file_dup2(apr_file_t *new_file, #ifdef _WIN32_WCE return APR_ENOTIMPL; #else - DWORD stdhandle = 0; HANDLE hproc = GetCurrentProcess(); HANDLE newhand = NULL; apr_int32_t newflags; @@ -208,7 +207,7 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, if (old_file->fname) { (*new_file)->fname = apr_pstrdup(p, old_file->fname); } - if (!(old_file->flags & APR_FILE_NOCLEANUP)) { + if (!(old_file->flags & APR_FOPEN_NOCLEANUP)) { apr_pool_cleanup_register(p, (void *)(*new_file), file_cleanup, file_cleanup); diff --git a/srclib/apr/file_io/win32/filepath.c b/srclib/apr/file_io/win32/filepath.c index 766e35f8..559d1b28 100644 --- a/srclib/apr/file_io/win32/filepath.c +++ b/srclib/apr/file_io/win32/filepath.c @@ -327,6 +327,27 @@ APR_DECLARE(apr_status_t) apr_filepath_root(const char **rootpath, #endif /* ndef(NETWARE) */ } +#if !defined(NETWARE) +static int same_drive(const char *path1, const char *path2) +{ + char drive1 = path1[0]; + char drive2 = path2[0]; + + if (!drive1 || !drive2 || path1[1] != ':' || path2[1] != ':') + return FALSE; + + if (drive1 == drive2) + return TRUE; + + if (drive1 >= 'a' && drive1 <= 'z') + drive1 += 'A' - 'a'; + + if (drive2 >= 'a' && drive2 <= 'z') + drive2 += 'A' - 'a'; + + return (drive1 == drive2); +} +#endif APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath, const char *basepath, @@ -540,7 +561,7 @@ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath, * use the basepath _if_ it matches this drive letter! * Otherwise we must discard the basepath. */ - if (addroot[0] == baseroot[0] && baseroot[1] == ':') { + if (same_drive(addroot, baseroot)) { #endif /* Base the result path on the basepath */ @@ -949,8 +970,7 @@ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath, } } - *newpath = apr_pmemdup(p, path, pathlen + 1); - (*newpath)[pathlen] = '\0'; + *newpath = apr_pstrmemdup(p, path, pathlen); return APR_SUCCESS; } diff --git a/srclib/apr/file_io/win32/filestat.c b/srclib/apr/file_io/win32/filestat.c index f409fc24..0d2225a9 100644 --- a/srclib/apr/file_io/win32/filestat.c +++ b/srclib/apr/file_io/win32/filestat.c @@ -97,7 +97,7 @@ static void resolve_prot(apr_finfo_t *finfo, apr_int32_t wanted, PACL dacl) * there is no reason for os_level testing here. */ if ((wanted & APR_FINFO_WPROT) && !worldid) { - SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_WORLD_SID_AUTHORITY; + SID_IDENTIFIER_AUTHORITY SIDAuth = {SECURITY_WORLD_SID_AUTHORITY}; if (AllocateAndInitializeSid(&SIDAuth, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &worldid)) atexit(free_world); @@ -268,7 +268,7 @@ apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile, ((wanted & APR_FINFO_PROT) ? &dacl : NULL), NULL, &pdesc); else - return APR_INCOMPLETE; + return APR_INCOMPLETE; /* should not occur */ if (rv == ERROR_SUCCESS) apr_pool_cleanup_register(finfo->pool, pdesc, free_localheap, apr_pool_cleanup_null); @@ -319,6 +319,8 @@ apr_status_t more_finfo(apr_finfo_t *finfo, const void *ufile, sizelo = GetCompressedFileSizeW((apr_wchar_t*)ufile, &sizehi); else if (whatfile == MORE_OF_FSPEC) sizelo = GetCompressedFileSizeA((char*)ufile, &sizehi); + else + return APR_EGENERAL; /* should not occur */ if (sizelo != INVALID_FILE_SIZE || GetLastError() == NO_ERROR) { #if APR_HAS_LARGE_FILES @@ -439,7 +441,7 @@ APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, apr_int32_t want * don't need to take chances while the handle is already open. */ DWORD FileType; - if (FileType = GetFileType(thefile->filehand)) { + if ((FileType = GetFileType(thefile->filehand))) { if (FileType == FILE_TYPE_CHAR) { finfo->filetype = APR_CHR; } @@ -532,8 +534,8 @@ APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, const char *fname, wanted &= ~finfo->valid; } - if (rv = utf8_to_unicode_path(wfname, sizeof(wfname) - / sizeof(apr_wchar_t), fname)) + if ((rv = utf8_to_unicode_path(wfname, sizeof(wfname) + / sizeof(apr_wchar_t), fname))) return rv; if (!(wanted & APR_FINFO_NAME)) { if (!GetFileAttributesExW(wfname, GetFileExInfoStandard, @@ -718,9 +720,9 @@ APR_DECLARE(apr_status_t) apr_file_attrs_set(const char *fname, #if APR_HAS_UNICODE_FS IF_WIN_OS_IS_UNICODE { - if (rv = utf8_to_unicode_path(wfname, - sizeof(wfname) / sizeof(wfname[0]), - fname)) + if ((rv = utf8_to_unicode_path(wfname, + sizeof(wfname) / sizeof(wfname[0]), + fname))) return rv; flags = GetFileAttributesW(wfname); } @@ -779,7 +781,7 @@ APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname, apr_status_t rv; rv = apr_file_open(&thefile, fname, - APR_READ | APR_WRITEATTRS, + APR_FOPEN_READ | APR_WRITEATTRS, APR_OS_DEFAULT, pool); if (!rv) { diff --git a/srclib/apr/file_io/win32/filesys.c b/srclib/apr/file_io/win32/filesys.c index ad31e338..e8121395 100644 --- a/srclib/apr/file_io/win32/filesys.c +++ b/srclib/apr/file_io/win32/filesys.c @@ -70,8 +70,8 @@ apr_status_t filepath_root_test(char *path, apr_pool_t *p) 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)) + if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) + / sizeof(apr_wchar_t), path))) return rv; rv = GetDriveTypeW(wpath); } @@ -143,8 +143,8 @@ apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p) /* ???: 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)) + 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(); @@ -211,8 +211,8 @@ APR_DECLARE(apr_status_t) apr_filepath_set(const char *rootpath, { 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)) + if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) + / sizeof(apr_wchar_t), rootpath))) return rv; if (!SetCurrentDirectoryW(wpath)) return apr_get_os_error(); diff --git a/srclib/apr/file_io/win32/open.c b/srclib/apr/file_io/win32/open.c index 1ea9b75a..cb438750 100644 --- a/srclib/apr/file_io/win32/open.c +++ b/srclib/apr/file_io/win32/open.c @@ -86,7 +86,7 @@ apr_status_t utf8_to_unicode_path(apr_wchar_t* retstr, apr_size_t retlen, } } - if (rv = apr_conv_utf8_to_ucs2(srcstr, &srcremains, t, &retlen)) { + if ((rv = apr_conv_utf8_to_ucs2(srcstr, &srcremains, t, &retlen))) { return (rv == APR_INCOMPLETE) ? APR_EINVAL : rv; } if (srcremains) { @@ -127,7 +127,7 @@ apr_status_t unicode_to_utf8_path(char* retstr, apr_size_t retlen, } } - if (rv = apr_conv_ucs2_to_utf8(srcstr, &srcremains, t, &retlen)) { + if ((rv = apr_conv_ucs2_to_utf8(srcstr, &srcremains, t, &retlen))) { return rv; } if (srcremains) { @@ -169,7 +169,7 @@ void *res_name_from_filename(const char *file, int global, apr_pool_t *pool) wfile = apr_palloc(pool, (r + n) * sizeof(apr_wchar_t)); wcscpy(wfile, wpre); d = n; - if (rv = apr_conv_utf8_to_ucs2(file, &n, wfile + r, &d)) { + if ((rv = apr_conv_utf8_to_ucs2(file, &n, wfile + r, &d))) { return NULL; } for (ch = wfile + r; *ch; ++ch) { @@ -331,10 +331,10 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, DWORD sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE; apr_status_t rv; - if (flag & APR_READ) { + if (flag & APR_FOPEN_READ) { oflags |= GENERIC_READ; } - if (flag & APR_WRITE) { + if (flag & APR_FOPEN_WRITE) { oflags |= GENERIC_WRITE; } if (flag & APR_WRITEATTRS) { @@ -344,18 +344,18 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, if (apr_os_level >= APR_WIN_NT) sharemode |= FILE_SHARE_DELETE; - if (flag & APR_CREATE) { - if (flag & APR_EXCL) { + if (flag & APR_FOPEN_CREATE) { + if (flag & APR_FOPEN_EXCL) { /* only create new if file does not already exist */ createflags = CREATE_NEW; - } else if (flag & APR_TRUNCATE) { + } else if (flag & APR_FOPEN_TRUNCATE) { /* truncate existing file or create new */ createflags = CREATE_ALWAYS; } else { /* open existing but create if necessary */ createflags = OPEN_ALWAYS; } - } else if (flag & APR_TRUNCATE) { + } else if (flag & APR_FOPEN_TRUNCATE) { /* only truncate if file already exists */ createflags = TRUNCATE_EXISTING; } else { @@ -363,11 +363,11 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, createflags = OPEN_EXISTING; } - if ((flag & APR_EXCL) && !(flag & APR_CREATE)) { + if ((flag & APR_FOPEN_EXCL) && !(flag & APR_FOPEN_CREATE)) { return APR_EACCES; } - if (flag & APR_DELONCLOSE) { + if (flag & APR_FOPEN_DELONCLOSE) { attributes |= FILE_FLAG_DELETE_ON_CLOSE; } @@ -382,7 +382,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, * FILE_FLAG_BACKUP_SEMANTICS to allow us to open directories. * See the static resolve_ident() fn in file_io/win32/filestat.c */ - if (!(flag & (APR_READ | APR_WRITE))) { + if (!(flag & (APR_FOPEN_READ | APR_FOPEN_WRITE))) { if (flag & APR_OPENINFO) { if (apr_os_level >= APR_WIN_NT) { attributes |= FILE_FLAG_BACKUP_SEMANTICS; @@ -395,7 +395,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, oflags |= READ_CONTROL; } - if (flag & APR_XTHREAD) { + if (flag & APR_FOPEN_XTHREAD) { /* This win32 specific feature is required * to allow multiple threads to work with the file. */ @@ -407,16 +407,16 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, { apr_wchar_t wfname[APR_PATH_MAX]; - if (flag & APR_SENDFILE_ENABLED) { + if (flag & APR_FOPEN_SENDFILE_ENABLED) { /* This feature is required to enable sendfile operations - * against the file on Win32. Also implies APR_XTHREAD. + * against the file on Win32. Also implies APR_FOPEN_XTHREAD. */ - flag |= APR_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)) + 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); @@ -427,7 +427,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, handle = CreateFileA(fname, oflags, sharemode, NULL, createflags, attributes, 0); /* This feature is not supported on this platform. */ - flag &= ~APR_SENDFILE_ENABLED; + flag &= ~APR_FOPEN_SENDFILE_ENABLED; } #endif if (handle == INVALID_HANDLE_VALUE) { @@ -442,11 +442,11 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, (*new)->timeout = -1; (*new)->ungetchar = -1; - if (flag & APR_APPEND) { + if (flag & APR_FOPEN_APPEND) { (*new)->append = 1; SetFilePointer((*new)->filehand, 0, NULL, FILE_END); } - if (flag & APR_BUFFERED) { + if (flag & APR_FOPEN_BUFFERED) { (*new)->buffered = 1; (*new)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); (*new)->bufsize = APR_FILE_DEFAULT_BUFSIZE; @@ -481,7 +481,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, /* ### check return codes */ (void) apr_pollset_create(&(*new)->pollset, 1, pool, 0); - if (!(flag & APR_FILE_NOCLEANUP)) { + if (!(flag & APR_FOPEN_NOCLEANUP)) { apr_pool_cleanup_register((*new)->pool, (void *)(*new), file_cleanup, apr_pool_cleanup_null); } @@ -510,8 +510,8 @@ APR_DECLARE(apr_status_t) apr_file_remove(const char *path, apr_pool_t *pool) { 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)) { + if ((rv = utf8_to_unicode_path(wpath, sizeof(wpath) + / sizeof(apr_wchar_t), path))) { return rv; } if (DeleteFileW(wpath)) @@ -535,12 +535,14 @@ APR_DECLARE(apr_status_t) apr_file_rename(const char *frompath, #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)) { + 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)) { + if ((rv = utf8_to_unicode_path(wtopath, + sizeof(wtopath) / sizeof(apr_wchar_t), + topath))) { return rv; } #ifndef _WIN32_WCE @@ -592,11 +594,13 @@ APR_DECLARE(apr_status_t) apr_file_link(const char *from_path, 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)) + 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)) + 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)) @@ -605,8 +609,8 @@ APR_DECLARE(apr_status_t) apr_file_link(const char *from_path, #endif #if APR_HAS_ANSI_FS ELSE_WIN_OS_IS_ANSI { - if (!CreateHardLinkA(wto_path, wfrom_path)) - return apr_get_os_error() + if (!CreateHardLinkA(to_path, from_path, NULL)) + return apr_get_os_error(); } #endif return rv; @@ -631,10 +635,10 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, (*file)->timeout = -1; (*file)->flags = flags; - if (flags & APR_APPEND) { + if (flags & APR_FOPEN_APPEND) { (*file)->append = 1; } - if (flags & APR_BUFFERED) { + if (flags & APR_FOPEN_BUFFERED) { (*file)->buffered = 1; (*file)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); (*file)->bufsize = APR_FILE_DEFAULT_BUFSIZE; @@ -687,7 +691,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stderr(apr_file_t **thefile, file_handle = INVALID_HANDLE_VALUE; return apr_os_file_put(thefile, &file_handle, - flags | APR_WRITE | APR_STDERR_FLAG, pool); + flags | APR_FOPEN_WRITE | APR_STDERR_FLAG, pool); #endif } @@ -706,7 +710,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stdout(apr_file_t **thefile, file_handle = INVALID_HANDLE_VALUE; return apr_os_file_put(thefile, &file_handle, - flags | APR_WRITE | APR_STDOUT_FLAG, pool); + flags | APR_FOPEN_WRITE | APR_STDOUT_FLAG, pool); #endif } @@ -725,7 +729,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stdin(apr_file_t **thefile, file_handle = INVALID_HANDLE_VALUE; return apr_os_file_put(thefile, &file_handle, - flags | APR_READ | APR_STDIN_FLAG, pool); + flags | APR_FOPEN_READ | APR_STDIN_FLAG, pool); #endif } diff --git a/srclib/apr/file_io/win32/pipe.c b/srclib/apr/file_io/win32/pipe.c index 4ee629d9..9344c7ae 100644 --- a/srclib/apr/file_io/win32/pipe.c +++ b/srclib/apr/file_io/win32/pipe.c @@ -29,6 +29,9 @@ #if APR_HAVE_SYS_STAT_H #include <sys/stat.h> #endif +#if APR_HAVE_PROCESS_H +#include <process.h> /* for getpid() on Win32 */ +#endif #include "apr_arch_misc.h" APR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe, @@ -43,8 +46,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_timeout_set(apr_file_t *thepipe, return APR_ENOTIMPL; } if (timeout && !(thepipe->pOverlapped)) { - /* Cannot be nonzero if a pipe was opened blocking - */ + /* Cannot be nonzero if a pipe was opened blocking */ return APR_EINVAL; } thepipe->timeout = timeout; @@ -82,7 +84,7 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create_ex(apr_file_t **in, char name[50]; sa.nLength = sizeof(sa); - + #if APR_HAS_UNICODE_FS IF_WIN_OS_IS_UNICODE sa.bInheritHandle = FALSE; @@ -139,10 +141,10 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create_ex(apr_file_t **in, (*in)->filehand = CreateNamedPipe(name, dwOpenMode, dwPipeMode, - 1, //nMaxInstances, - 0, //nOutBufferSize, - 65536, //nInBufferSize, - 1, //nDefaultTimeOut, + 1, /* nMaxInstances, */ + 0, /* nOutBufferSize, */ + 65536, /* nInBufferSize, */ + 1, /* nDefaultTimeOut, */ &sa); /* Create the write end of the pipe */ @@ -154,14 +156,14 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create_ex(apr_file_t **in, (*out)->pOverlapped->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); (*out)->timeout = 0; } - + (*out)->filehand = CreateFile(name, - GENERIC_WRITE, // access mode - 0, // share mode - &sa, // Security attributes - OPEN_EXISTING, // dwCreationDisposition - dwOpenMode, // Pipe attributes - NULL); // handle to template file + GENERIC_WRITE, /* access mode */ + 0, /* share mode */ + &sa, /* Security attributes */ + OPEN_EXISTING, /* dwCreationDisposition */ + dwOpenMode, /* Pipe attributes */ + NULL); /* handle to template file */ } else { /* Pipes on Win9* are blocking. Live with it. */ @@ -229,8 +231,9 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file, static apr_status_t create_socket_pipe(SOCKET *rd, SOCKET *wr) { static int id = 0; - + FD_SET rs; SOCKET ls; + struct timeval socktm; struct sockaddr_in pa; struct sockaddr_in la; struct sockaddr_in ca; @@ -238,7 +241,7 @@ static apr_status_t create_socket_pipe(SOCKET *rd, SOCKET *wr) apr_status_t rv = APR_SUCCESS; int ll = sizeof(la); int lc = sizeof(ca); - int bm = 1; + unsigned long bm = 1; int uid[2]; int iid[2]; @@ -290,17 +293,41 @@ static apr_status_t create_socket_pipe(SOCKET *rd, SOCKET *wr) goto cleanup; } for (;;) { + int ns; + int nc = 0; /* Listening socket is nonblocking by now. - * The accept must create the socket - * immediatelly because we connected already. + * The accept should create the socket + * immediatelly because we are connected already. + * However on buys systems this can take a while + * until winsock gets a chance to handle the events. */ + FD_ZERO(&rs); + FD_SET(ls, &rs); + + socktm.tv_sec = 1; + socktm.tv_usec = 0; + if ((ns = select(0, &rs, NULL, NULL, &socktm)) == SOCKET_ERROR) { + /* Accept still not signaled */ + Sleep(100); + continue; + } + if (ns == 0) { + /* No connections in the last second */ + continue; + } if ((*rd = accept(ls, (SOCKADDR *)&ca, &lc)) == INVALID_SOCKET) { rv = apr_get_netos_error(); goto cleanup; } /* Verify the connection by reading the send identification. */ - nrd = recv(*rd, (char *)iid, sizeof(iid), 0); + do { + if (nc++) + Sleep(1); + nrd = recv(*rd, (char *)iid, sizeof(iid), 0); + rv = nrd == SOCKET_ERROR ? apr_get_netos_error() : APR_SUCCESS; + } while (APR_STATUS_IS_EAGAIN(rv)); + if (nrd == sizeof(iid)) { if (memcmp(uid, iid, sizeof(uid)) == 0) { /* Wow, we recived what we send. @@ -316,7 +343,6 @@ static apr_status_t create_socket_pipe(SOCKET *rd, SOCKET *wr) } } else if (nrd == SOCKET_ERROR) { - rv = apr_get_netos_error(); goto cleanup; } closesocket(*rd); @@ -412,3 +438,4 @@ apr_status_t apr_file_socket_pipe_close(apr_file_t *file) } return stat; } + diff --git a/srclib/apr/file_io/win32/readwrite.c b/srclib/apr/file_io/win32/readwrite.c index ecbe7dda..1d0014d5 100644 --- a/srclib/apr/file_io/win32/readwrite.c +++ b/srclib/apr/file_io/win32/readwrite.c @@ -154,7 +154,7 @@ APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size * initialize the overlapped and io completion event (hEvent). * Threads should NOT share an apr_file_t or its hEvent. */ - if ((thefile->flags & APR_XTHREAD) && !thefile->pOverlapped ) { + if ((thefile->flags & APR_FOPEN_XTHREAD) && !thefile->pOverlapped ) { thefile->pOverlapped = (OVERLAPPED*) apr_pcalloc(thefile->pool, sizeof(OVERLAPPED)); thefile->pOverlapped->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -245,7 +245,7 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a * initialize the overlapped and io completion event (hEvent). * Threads should NOT share an apr_file_t or its hEvent. */ - if ((thefile->flags & APR_XTHREAD) && !thefile->pOverlapped ) { + if ((thefile->flags & APR_FOPEN_XTHREAD) && !thefile->pOverlapped ) { thefile->pOverlapped = (OVERLAPPED*) apr_pcalloc(thefile->pool, sizeof(OVERLAPPED)); thefile->pOverlapped->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -263,10 +263,10 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a apr_thread_mutex_lock(thefile->mutex); if (thefile->direction == 0) { - // Position file pointer for writing at the offset we are logically reading from + /* Position file pointer for writing at the offset we are logically reading from */ apr_off_t offset = thefile->filePtr - thefile->dataRead + thefile->bufpos; DWORD offlo = (DWORD)offset; - DWORD offhi = (DWORD)(offset >> 32); + LONG offhi = (LONG)(offset >> 32); if (offset != thefile->filePtr) SetFilePointer(thefile->filehand, offlo, &offhi, FILE_BEGIN); thefile->bufpos = thefile->dataRead = 0; diff --git a/srclib/apr/file_io/win32/seek.c b/srclib/apr/file_io/win32/seek.c index 53e53dd7..b412fd4c 100644 --- a/srclib/apr/file_io/win32/seek.c +++ b/srclib/apr/file_io/win32/seek.c @@ -44,7 +44,7 @@ static apr_status_t setptr(apr_file_t *thefile, apr_off_t pos ) rv = APR_SUCCESS; } else { DWORD offlo = (DWORD)pos; - DWORD offhi = (DWORD)(pos >> 32); + LONG offhi = (LONG)(pos >> 32); rc = SetFilePointer(thefile->filehand, offlo, &offhi, FILE_BEGIN); if (rc == (DWORD)-1) @@ -100,10 +100,10 @@ APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t wh *offset = thefile->filePtr - thefile->dataRead + thefile->bufpos; return rc; } - /* A file opened with APR_XTHREAD has been opened for overlapped i/o. + /* A file opened with APR_FOPEN_XTHREAD has been opened for overlapped i/o. * APR must explicitly track the file pointer in this case. */ - else if (thefile->pOverlapped || thefile->flags & APR_XTHREAD) { + else if (thefile->pOverlapped || thefile->flags & APR_FOPEN_XTHREAD) { switch(where) { case APR_SET: thefile->filePtr = *offset; @@ -158,7 +158,7 @@ APR_DECLARE(apr_status_t) apr_file_trunc(apr_file_t *thefile, apr_off_t offset) { apr_status_t rv; DWORD offlo = (DWORD)offset; - DWORD offhi = (DWORD)(offset >> 32); + LONG offhi = (LONG)(offset >> 32); DWORD rc; rc = SetFilePointer(thefile->filehand, offlo, &offhi, FILE_BEGIN); |