summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apr.dsp4
-rw-r--r--file_io/win32/buffer.c59
-rw-r--r--file_io/win32/filedup.c3
-rw-r--r--file_io/win32/open.c6
-rw-r--r--file_io/win32/readwrite.c7
-rw-r--r--include/arch/win32/apr_arch_file_io.h5
-rw-r--r--libapr.dsp4
7 files changed, 81 insertions, 7 deletions
diff --git a/apr.dsp b/apr.dsp
index a67674148..0004e5ebe 100644
--- a/apr.dsp
+++ b/apr.dsp
@@ -105,6 +105,10 @@ SOURCE=.\dso\win32\dso.c
# PROP Default_Filter ""
# Begin Source File
+SOURCE=.\file_io\win32\buffer.c
+# End Source File
+# Begin Source File
+
SOURCE=.\file_io\unix\copy.c
# End Source File
# Begin Source File
diff --git a/file_io/win32/buffer.c b/file_io/win32/buffer.c
new file mode 100644
index 000000000..e4ff676f7
--- /dev/null
+++ b/file_io/win32/buffer.c
@@ -0,0 +1,59 @@
+/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "win32/apr_arch_file_io.h"
+#include "apr_thread_mutex.h"
+
+APR_DECLARE(apr_status_t) apr_file_buffer_set(apr_file_t *file,
+ char * buffer,
+ apr_size_t bufsize)
+{
+ apr_status_t rv;
+
+ apr_thread_mutex_lock(file->mutex);
+
+ if(file->buffered) {
+ /* Flush the existing buffer */
+ rv = apr_file_flush(file);
+ if (rv != APR_SUCCESS) {
+ apr_thread_mutex_unlock(file->mutex);
+ return rv;
+ }
+ }
+
+ file->buffer = buffer;
+ file->bufsize = bufsize;
+ file->buffered = 1;
+ file->bufpos = 0;
+ file->direction = 0;
+ file->dataRead = 0;
+
+ if (file->bufsize == 0) {
+ /* Setting the buffer size to zero is equivalent to turning
+ * buffering off.
+ */
+ file->buffered = 0;
+ }
+
+ apr_thread_mutex_unlock(file->mutex);
+
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_size_t) apr_file_buffer_size_get(apr_file_t *file)
+{
+ return file->bufsize;
+} \ No newline at end of file
diff --git a/file_io/win32/filedup.c b/file_io/win32/filedup.c
index d2e3af46b..9cac74d47 100644
--- a/file_io/win32/filedup.c
+++ b/file_io/win32/filedup.c
@@ -145,7 +145,8 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
memcpy(*new_file, old_file, sizeof(apr_file_t));
(*new_file)->pool = p;
if (old_file->buffered) {
- (*new_file)->buffer = apr_palloc(p, APR_FILE_BUFSIZE);
+ (*new_file)->buffer = apr_palloc(p, old_file->bufsize);
+ (*new_file)->bufsize = old_file->bufsize;
if (old_file->direction == 1) {
memcpy((*new_file)->buffer, old_file->buffer, old_file->bufpos);
}
diff --git a/file_io/win32/open.c b/file_io/win32/open.c
index 83beb977a..56b73b51e 100644
--- a/file_io/win32/open.c
+++ b/file_io/win32/open.c
@@ -386,7 +386,8 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname,
}
if (flag & APR_BUFFERED) {
(*new)->buffered = 1;
- (*new)->buffer = apr_palloc(pool, APR_FILE_BUFSIZE);
+ (*new)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
+ (*new)->bufsize = APR_FILE_DEFAULT_BUFSIZE;
}
/* Need the mutex to handled buffered and O_APPEND style file i/o */
if ((*new)->buffered || (*new)->append) {
@@ -528,7 +529,8 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file,
}
if (flags & APR_BUFFERED) {
(*file)->buffered = 1;
- (*file)->buffer = apr_palloc(pool, APR_FILE_BUFSIZE);
+ (*file)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
+ (*file)->bufsize = APR_FILE_DEFAULT_BUFSIZE;
}
if ((*file)->append || (*file)->buffered) {
diff --git a/file_io/win32/readwrite.c b/file_io/win32/readwrite.c
index e1b56ba8f..23538f9c7 100644
--- a/file_io/win32/readwrite.c
+++ b/file_io/win32/readwrite.c
@@ -177,7 +177,7 @@ APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size
if (thefile->bufpos >= thefile->dataRead) {
apr_size_t read;
rv = read_with_timeout(thefile, thefile->buffer,
- APR_FILE_BUFSIZE, &read);
+ thefile->bufsize, &read);
if (read == 0) {
if (rv == APR_EOF)
thefile->eof_hit = TRUE;
@@ -251,10 +251,11 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a
rv = 0;
while (rv == 0 && size > 0) {
- if (thefile->bufpos == APR_FILE_BUFSIZE) // write buffer is full
+ if (thefile->bufpos == thefile->bufsize) // write buffer is full
rv = apr_file_flush(thefile);
- blocksize = size > APR_FILE_BUFSIZE - thefile->bufpos ? APR_FILE_BUFSIZE - thefile->bufpos : size;
+ blocksize = size > thefile->bufsize - thefile->bufpos ?
+ thefile->bufsize - thefile->bufpos : size;
memcpy(thefile->buffer + thefile->bufpos, pos, blocksize);
thefile->bufpos += blocksize;
pos += blocksize;
diff --git a/include/arch/win32/apr_arch_file_io.h b/include/arch/win32/apr_arch_file_io.h
index 3af8720b9..57a4a61c7 100644
--- a/include/arch/win32/apr_arch_file_io.h
+++ b/include/arch/win32/apr_arch_file_io.h
@@ -84,7 +84,9 @@ void *res_name_from_filename(const char *file, int global, apr_pool_t *pool);
#define APR_FILE_MAX MAX_PATH
-#define APR_FILE_BUFSIZE 4096
+#define APR_FILE_DEFAULT_BUFSIZE 4096
+/* For backwards-compat */
+#define APR_FILE_BUFSIZE APR_FILE_DEFAULT_BUFSIZE
/* obscure ommissions from msvc's sys/stat.h */
#ifdef _MSC_VER
@@ -173,6 +175,7 @@ struct apr_file_t {
/* Stuff for buffered mode */
char *buffer;
apr_size_t bufpos; // Read/Write position in buffer
+ apr_size_t bufsize; // The size of the buffer
apr_size_t dataRead; // amount of valid data read into buffer
int direction; // buffer being used for 0 = read, 1 = write
apr_off_t filePtr; // position in file of handle
diff --git a/libapr.dsp b/libapr.dsp
index 13835e4d1..cd7098f71 100644
--- a/libapr.dsp
+++ b/libapr.dsp
@@ -111,6 +111,10 @@ SOURCE=.\dso\win32\dso.c
# PROP Default_Filter ""
# Begin Source File
+SOURCE=.\file_io\win32\buffer.c
+# End Source File
+# Begin Source File
+
SOURCE=.\file_io\unix\copy.c
# End Source File
# Begin Source File