diff options
Diffstat (limited to 'srclib/apr/file_io')
-rw-r--r-- | srclib/apr/file_io/netware/mktemp.c | 8 | ||||
-rw-r--r-- | srclib/apr/file_io/netware/pipe.c | 2 | ||||
-rw-r--r-- | srclib/apr/file_io/os2/filedup.c | 2 | ||||
-rw-r--r-- | srclib/apr/file_io/os2/open.c | 30 | ||||
-rw-r--r-- | srclib/apr/file_io/os2/readwrite.c | 6 | ||||
-rw-r--r-- | srclib/apr/file_io/unix/copy.c | 6 | ||||
-rw-r--r-- | srclib/apr/file_io/unix/filedup.c | 10 | ||||
-rw-r--r-- | srclib/apr/file_io/unix/mktemp.c | 6 | ||||
-rw-r--r-- | srclib/apr/file_io/unix/open.c | 58 | ||||
-rw-r--r-- | srclib/apr/file_io/unix/pipe.c | 2 | ||||
-rw-r--r-- | srclib/apr/file_io/unix/readwrite.c | 12 | ||||
-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 |
20 files changed, 226 insertions, 166 deletions
diff --git a/srclib/apr/file_io/netware/mktemp.c b/srclib/apr/file_io/netware/mktemp.c index c86954ff..4f78226e 100644 --- a/srclib/apr/file_io/netware/mktemp.c +++ b/srclib/apr/file_io/netware/mktemp.c @@ -28,8 +28,8 @@ APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_i int fd; apr_status_t rv; - flags = (!flags) ? APR_CREATE | APR_READ | APR_WRITE | - APR_DELONCLOSE : flags & ~APR_EXCL; + flags = (!flags) ? APR_FOPEN_CREATE | APR_FOPEN_READ | APR_FOPEN_WRITE | + APR_FOPEN_DELONCLOSE : flags & ~APR_FOPEN_EXCL; fd = mkstemp(template); if (fd == -1) { @@ -39,11 +39,11 @@ APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_i * Otherwise file locking will not allow the file to be shared. */ close(fd); - if ((rv = apr_file_open(fp, template, flags|APR_FILE_NOCLEANUP, + if ((rv = apr_file_open(fp, template, flags|APR_FOPEN_NOCLEANUP, APR_UREAD | APR_UWRITE, p)) == APR_SUCCESS) { - if (!(flags & APR_FILE_NOCLEANUP)) { + if (!(flags & APR_FOPEN_NOCLEANUP)) { int flags; if ((flags = fcntl((*fp)->filedes, F_GETFD)) == -1) diff --git a/srclib/apr/file_io/netware/pipe.c b/srclib/apr/file_io/netware/pipe.c index 1abf4140..3e8f5593 100644 --- a/srclib/apr/file_io/netware/pipe.c +++ b/srclib/apr/file_io/netware/pipe.c @@ -114,7 +114,7 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file, (*file)->ungetchar = -1; /* no char avail */ (*file)->filedes = *dafile; if (!register_cleanup) { - (*file)->flags = APR_FILE_NOCLEANUP; + (*file)->flags = APR_FOPEN_NOCLEANUP; } (*file)->buffered = 0; #if APR_HAS_THREADS diff --git a/srclib/apr/file_io/os2/filedup.c b/srclib/apr/file_io/os2/filedup.c index a9d0421e..b1063f57 100644 --- a/srclib/apr/file_io/os2/filedup.c +++ b/srclib/apr/file_io/os2/filedup.c @@ -112,7 +112,7 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, (*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), apr_file_cleanup, apr_file_cleanup); diff --git a/srclib/apr/file_io/os2/open.c b/srclib/apr/file_io/os2/open.c index 386bd073..a1a55202 100644 --- a/srclib/apr/file_io/os2/open.c +++ b/srclib/apr/file_io/os2/open.c @@ -45,18 +45,18 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr dafile->flags = flag; dafile->blocking = BLK_ON; - if ((flag & APR_READ) && (flag & APR_WRITE)) { + if ((flag & APR_FOPEN_READ) && (flag & APR_FOPEN_WRITE)) { mflags |= OPEN_ACCESS_READWRITE; - } else if (flag & APR_READ) { + } else if (flag & APR_FOPEN_READ) { mflags |= OPEN_ACCESS_READONLY; - } else if (flag & APR_WRITE) { + } else if (flag & APR_FOPEN_WRITE) { mflags |= OPEN_ACCESS_WRITEONLY; } else { dafile->filedes = -1; return APR_EACCES; } - dafile->buffered = (flag & APR_BUFFERED) > 0; + dafile->buffered = (flag & APR_FOPEN_BUFFERED) > 0; if (dafile->buffered) { dafile->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); @@ -67,18 +67,18 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr return rv; } - if (flag & APR_CREATE) { + if (flag & APR_FOPEN_CREATE) { oflags |= OPEN_ACTION_CREATE_IF_NEW; - if (!(flag & APR_EXCL) && !(flag & APR_TRUNCATE)) { + if (!(flag & APR_FOPEN_EXCL) && !(flag & APR_FOPEN_TRUNCATE)) { oflags |= OPEN_ACTION_OPEN_IF_EXISTS; } } - if ((flag & APR_EXCL) && !(flag & APR_CREATE)) + if ((flag & APR_FOPEN_EXCL) && !(flag & APR_FOPEN_CREATE)) return APR_EACCES; - if (flag & APR_TRUNCATE) { + if (flag & APR_FOPEN_TRUNCATE) { oflags |= OPEN_ACTION_REPLACE_IF_EXISTS; } else if ((oflags & 0xFF) == 0) { oflags |= OPEN_ACTION_OPEN_IF_EXISTS; @@ -86,7 +86,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr rv = DosOpen(fname, &(dafile->filedes), &action, 0, 0, oflags, mflags, NULL); - if (rv == 0 && (flag & APR_APPEND)) { + if (rv == 0 && (flag & APR_FOPEN_APPEND)) { ULONG newptr; rv = DosSetFilePtr(dafile->filedes, 0, FILE_END, &newptr ); @@ -105,7 +105,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, apr dafile->direction = 0; dafile->pipe = FALSE; - if (!(flag & APR_FILE_NOCLEANUP)) { + if (!(flag & APR_FOPEN_NOCLEANUP)) { apr_pool_cleanup_register(dafile->pool, dafile, apr_file_cleanup, apr_file_cleanup); } @@ -128,7 +128,7 @@ APR_DECLARE(apr_status_t) apr_file_close(apr_file_t *file) if (rc == 0) { file->isopen = FALSE; - if (file->flags & APR_DELONCLOSE) { + if (file->flags & APR_FOPEN_DELONCLOSE) { status = APR_FROM_OS_ERROR(DosDelete(file->fname)); } /* else we return the status of the flush attempt @@ -192,7 +192,7 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, apr_os_file_t *thef (*file)->eof_hit = FALSE; (*file)->flags = flags; (*file)->pipe = FALSE; - (*file)->buffered = (flags & APR_BUFFERED) > 0; + (*file)->buffered = (flags & APR_FOPEN_BUFFERED) > 0; if ((*file)->buffered) { apr_status_t rv; @@ -224,7 +224,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stderr(apr_file_t **thefile, { apr_os_file_t fd = 2; - return apr_os_file_put(thefile, &fd, flags | APR_WRITE, pool); + return apr_os_file_put(thefile, &fd, flags | APR_FOPEN_WRITE, pool); } @@ -234,7 +234,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stdout(apr_file_t **thefile, { apr_os_file_t fd = 1; - return apr_os_file_put(thefile, &fd, flags | APR_WRITE, pool); + return apr_os_file_put(thefile, &fd, flags | APR_FOPEN_WRITE, pool); } @@ -244,7 +244,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stdin(apr_file_t **thefile, { apr_os_file_t fd = 0; - return apr_os_file_put(thefile, &fd, flags | APR_READ, pool); + return apr_os_file_put(thefile, &fd, flags | APR_FOPEN_READ, pool); } diff --git a/srclib/apr/file_io/os2/readwrite.c b/srclib/apr/file_io/os2/readwrite.c index a7b591b3..d00591d7 100644 --- a/srclib/apr/file_io/os2/readwrite.c +++ b/srclib/apr/file_io/os2/readwrite.c @@ -140,7 +140,7 @@ 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 */ ULONG offset = thefile->filePtr - thefile->dataRead + thefile->bufpos; if (offset != thefile->filePtr) DosSetFilePtr(thefile->filedes, offset, FILE_BEGIN, &thefile->filePtr ); @@ -149,7 +149,7 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a } while (rc == 0 && size > 0) { - if (thefile->bufpos == thefile->bufsize) // write buffer is full + if (thefile->bufpos == thefile->bufsize) /* write buffer is full */ /* XXX bug; - rc is double-transformed os->apr below */ rc = apr_file_flush(thefile); @@ -163,7 +163,7 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a apr_thread_mutex_unlock(thefile->mutex); return APR_FROM_OS_ERROR(rc); } else { - if (thefile->flags & APR_APPEND) { + if (thefile->flags & APR_FOPEN_APPEND) { FILELOCK all = { 0, 0x7fffffff }; ULONG newpos; rc = DosSetFileLocks(thefile->filedes, NULL, &all, -1, 0); diff --git a/srclib/apr/file_io/unix/copy.c b/srclib/apr/file_io/unix/copy.c index 3a1c59a6..df3a49c8 100644 --- a/srclib/apr/file_io/unix/copy.c +++ b/srclib/apr/file_io/unix/copy.c @@ -29,7 +29,7 @@ static apr_status_t apr_file_transfer_contents(const char *from_path, apr_fileperms_t perms; /* Open source file. */ - status = apr_file_open(&s, from_path, APR_READ, APR_OS_DEFAULT, pool); + status = apr_file_open(&s, from_path, APR_FOPEN_READ, APR_OS_DEFAULT, pool); if (status) return status; @@ -101,7 +101,7 @@ APR_DECLARE(apr_status_t) apr_file_copy(const char *from_path, apr_pool_t *pool) { return apr_file_transfer_contents(from_path, to_path, - (APR_WRITE | APR_CREATE | APR_TRUNCATE), + (APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE), perms, pool); } @@ -112,7 +112,7 @@ APR_DECLARE(apr_status_t) apr_file_append(const char *from_path, apr_pool_t *pool) { return apr_file_transfer_contents(from_path, to_path, - (APR_WRITE | APR_CREATE | APR_APPEND), + (APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_APPEND), perms, pool); } diff --git a/srclib/apr/file_io/unix/filedup.c b/srclib/apr/file_io/unix/filedup.c index 47ea4f33..eb4fbdc6 100644 --- a/srclib/apr/file_io/unix/filedup.c +++ b/srclib/apr/file_io/unix/filedup.c @@ -35,12 +35,12 @@ static apr_status_t file_dup(apr_file_t **new_file, return APR_EINVAL; } #ifdef HAVE_DUP3 - if (!((*new_file)->flags & (APR_FILE_NOCLEANUP|APR_INHERIT))) + if (!((*new_file)->flags & (APR_FOPEN_NOCLEANUP|APR_INHERIT))) flags |= O_CLOEXEC; rv = dup3(old_file->filedes, (*new_file)->filedes, flags); #else rv = dup2(old_file->filedes, (*new_file)->filedes); - if (!((*new_file)->flags & (APR_FILE_NOCLEANUP|APR_INHERIT))) { + if (!((*new_file)->flags & (APR_FOPEN_NOCLEANUP|APR_INHERIT))) { int flags; if (rv == -1) @@ -106,12 +106,12 @@ static apr_status_t file_dup(apr_file_t **new_file, } /* apr_file_dup() retains all old_file flags with the exceptions - * of APR_INHERIT and APR_FILE_NOCLEANUP. + * of APR_INHERIT and APR_FOPEN_NOCLEANUP. * The user must call apr_file_inherit_set() on the dupped * apr_file_t when desired. */ (*new_file)->flags = old_file->flags - & ~(APR_INHERIT | APR_FILE_NOCLEANUP); + & ~(APR_INHERIT | APR_FOPEN_NOCLEANUP); apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file), apr_unix_file_cleanup, @@ -164,7 +164,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), apr_unix_file_cleanup, ((*new_file)->flags & APR_INHERIT) diff --git a/srclib/apr/file_io/unix/mktemp.c b/srclib/apr/file_io/unix/mktemp.c index a78b73ae..28aaf90e 100644 --- a/srclib/apr/file_io/unix/mktemp.c +++ b/srclib/apr/file_io/unix/mktemp.c @@ -178,8 +178,8 @@ APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_i #ifdef HAVE_MKSTEMP int fd; #endif - flags = (!flags) ? APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | - APR_DELONCLOSE : flags; + flags = (!flags) ? APR_FOPEN_CREATE | APR_FOPEN_READ | APR_FOPEN_WRITE | APR_FOPEN_EXCL | + APR_FOPEN_DELONCLOSE : flags; #ifndef HAVE_MKSTEMP return gettemp(template, fp, flags, p); #else @@ -203,7 +203,7 @@ APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_i apr_os_file_put(fp, &fd, flags, p); (*fp)->fname = apr_pstrdup(p, template); - if (!(flags & APR_FILE_NOCLEANUP)) { + if (!(flags & APR_FOPEN_NOCLEANUP)) { int flags; if ((flags = fcntl(fd, F_GETFD)) == -1) diff --git a/srclib/apr/file_io/unix/open.c b/srclib/apr/file_io/unix/open.c index bf3b43b6..d8e17150 100644 --- a/srclib/apr/file_io/unix/open.c +++ b/srclib/apr/file_io/unix/open.c @@ -38,7 +38,7 @@ static apr_status_t file_cleanup(apr_file_t *file, int is_child) if (close(fd) == 0) { /* Only the parent process should delete the file! */ - if (!is_child && (file->flags & APR_DELONCLOSE)) { + if (!is_child && (file->flags & APR_FOPEN_DELONCLOSE)) { unlink(file->fname); } #if APR_HAS_THREADS @@ -100,37 +100,37 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, apr_status_t rv; #endif - if ((flag & APR_READ) && (flag & APR_WRITE)) { + if ((flag & APR_FOPEN_READ) && (flag & APR_FOPEN_WRITE)) { oflags = O_RDWR; } - else if (flag & APR_READ) { + else if (flag & APR_FOPEN_READ) { oflags = O_RDONLY; } - else if (flag & APR_WRITE) { + else if (flag & APR_FOPEN_WRITE) { oflags = O_WRONLY; } else { return APR_EACCES; } - if (flag & APR_CREATE) { - oflags |= O_CREAT; - if (flag & APR_EXCL) { + if (flag & APR_FOPEN_CREATE) { + oflags |= O_CREAT; + if (flag & APR_FOPEN_EXCL) { oflags |= O_EXCL; } } - if ((flag & APR_EXCL) && !(flag & APR_CREATE)) { + if ((flag & APR_FOPEN_EXCL) && !(flag & APR_FOPEN_CREATE)) { return APR_EACCES; } - if (flag & APR_APPEND) { + if (flag & APR_FOPEN_APPEND) { oflags |= O_APPEND; } - if (flag & APR_TRUNCATE) { + if (flag & APR_FOPEN_TRUNCATE) { oflags |= O_TRUNC; } #ifdef O_BINARY - if (flag & APR_BINARY) { + if (flag & APR_FOPEN_BINARY) { oflags |= O_BINARY; } #endif @@ -138,7 +138,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, #ifdef O_CLOEXEC /* Introduced in Linux 2.6.23. Silently ignored on earlier Linux kernels. */ - if (!(flag & APR_FILE_NOCLEANUP)) { + if (!(flag & APR_FOPEN_NOCLEANUP)) { oflags |= O_CLOEXEC; } #endif @@ -146,13 +146,13 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE) oflags |= O_LARGEFILE; #elif defined(O_LARGEFILE) - if (flag & APR_LARGEFILE) { + if (flag & APR_FOPEN_LARGEFILE) { oflags |= O_LARGEFILE; } #endif #if APR_HAS_THREADS - if ((flag & APR_BUFFERED) && (flag & APR_XTHREAD)) { + if ((flag & APR_FOPEN_BUFFERED) && (flag & APR_FOPEN_XTHREAD)) { rv = apr_thread_mutex_create(&thlock, APR_THREAD_MUTEX_DEFAULT, pool); if (rv) { @@ -170,15 +170,17 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, if (fd < 0) { return errno; } - if (!(flag & APR_FILE_NOCLEANUP)) { + if (!(flag & APR_FOPEN_NOCLEANUP)) { int flags; if ((flags = fcntl(fd, F_GETFD)) == -1) return errno; - flags |= FD_CLOEXEC; - if (fcntl(fd, F_SETFD, flags) == -1) - return errno; + if ((flags & FD_CLOEXEC) == 0) { + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) + return errno; + } } (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t)); @@ -189,13 +191,13 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, (*new)->fname = apr_pstrdup(pool, fname); (*new)->blocking = BLK_ON; - (*new)->buffered = (flag & APR_BUFFERED) > 0; + (*new)->buffered = (flag & APR_FOPEN_BUFFERED) > 0; if ((*new)->buffered) { (*new)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); (*new)->bufsize = APR_FILE_DEFAULT_BUFSIZE; #if APR_HAS_THREADS - if ((*new)->flags & APR_XTHREAD) { + if ((*new)->flags & APR_FOPEN_XTHREAD) { (*new)->thlock = thlock; } #endif @@ -218,7 +220,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, */ (*new)->pollset = NULL; #endif - if (!(flag & APR_FILE_NOCLEANUP)) { + if (!(flag & APR_FOPEN_NOCLEANUP)) { apr_pool_cleanup_register((*new)->pool, (void *)(*new), apr_unix_file_cleanup, apr_unix_child_file_cleanup); @@ -271,8 +273,8 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, (*file)->timeout = -1; (*file)->ungetchar = -1; /* no char avail */ (*file)->filedes = *dafile; - (*file)->flags = flags | APR_FILE_NOCLEANUP; - (*file)->buffered = (flags & APR_BUFFERED) > 0; + (*file)->flags = flags | APR_FOPEN_NOCLEANUP; + (*file)->buffered = (flags & APR_FOPEN_BUFFERED) > 0; #ifndef WAITIO_USES_POLL /* Start out with no pollset. apr_wait_for_io_or_timeout() will @@ -285,7 +287,7 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, (*file)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); (*file)->bufsize = APR_FILE_DEFAULT_BUFSIZE; #if APR_HAS_THREADS - if ((*file)->flags & APR_XTHREAD) { + if ((*file)->flags & APR_FOPEN_XTHREAD) { apr_status_t rv; rv = apr_thread_mutex_create(&((*file)->thlock), APR_THREAD_MUTEX_DEFAULT, pool); @@ -312,7 +314,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stderr(apr_file_t **thefile, { int fd = STDERR_FILENO; - return apr_os_file_put(thefile, &fd, flags | APR_WRITE, pool); + return apr_os_file_put(thefile, &fd, flags | APR_FOPEN_WRITE, pool); } APR_DECLARE(apr_status_t) apr_file_open_flags_stdout(apr_file_t **thefile, @@ -321,7 +323,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stdout(apr_file_t **thefile, { int fd = STDOUT_FILENO; - return apr_os_file_put(thefile, &fd, flags | APR_WRITE, pool); + return apr_os_file_put(thefile, &fd, flags | APR_FOPEN_WRITE, pool); } APR_DECLARE(apr_status_t) apr_file_open_flags_stdin(apr_file_t **thefile, @@ -330,7 +332,7 @@ APR_DECLARE(apr_status_t) apr_file_open_flags_stdin(apr_file_t **thefile, { int fd = STDIN_FILENO; - return apr_os_file_put(thefile, &fd, flags | APR_READ, pool); + return apr_os_file_put(thefile, &fd, flags | APR_FOPEN_READ, pool); } APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile, @@ -358,7 +360,7 @@ APR_IMPLEMENT_INHERIT_SET(file, flags, pool, apr_unix_file_cleanup) * suitable on Unix (see PR 41119). */ APR_DECLARE(apr_status_t) apr_file_inherit_unset(apr_file_t *thefile) { - if (thefile->flags & APR_FILE_NOCLEANUP) { + if (thefile->flags & APR_FOPEN_NOCLEANUP) { return APR_EINVAL; } if (thefile->flags & APR_INHERIT) { diff --git a/srclib/apr/file_io/unix/pipe.c b/srclib/apr/file_io/unix/pipe.c index 0411aa5f..7b8f01fb 100644 --- a/srclib/apr/file_io/unix/pipe.c +++ b/srclib/apr/file_io/unix/pipe.c @@ -149,7 +149,7 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put_ex(apr_file_t **file, (*file)->ungetchar = -1; /* no char avail */ (*file)->filedes = *dafile; if (!register_cleanup) { - (*file)->flags = APR_FILE_NOCLEANUP; + (*file)->flags = APR_FOPEN_NOCLEANUP; } (*file)->buffered = 0; #if APR_HAS_THREADS diff --git a/srclib/apr/file_io/unix/readwrite.c b/srclib/apr/file_io/unix/readwrite.c index f2e07534..4b3e7368 100644 --- a/srclib/apr/file_io/unix/readwrite.c +++ b/srclib/apr/file_io/unix/readwrite.c @@ -311,12 +311,16 @@ apr_status_t apr_file_flush_locked(apr_file_t *thefile) apr_status_t rv = APR_SUCCESS; if (thefile->direction == 1 && thefile->bufpos) { - apr_ssize_t written; + apr_ssize_t written = 0, ret; do { - written = write(thefile->filedes, thefile->buffer, thefile->bufpos); - } while (written == -1 && errno == EINTR); - if (written == -1) { + ret = write(thefile->filedes, thefile->buffer + written, + thefile->bufpos - written); + if (ret > 0) + written += ret; + } while (written < thefile->bufpos && + (ret > 0 || (ret == -1 && errno == EINTR))); + if (ret == -1) { rv = errno; } else { thefile->filePtr += written; 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); |