apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Blair Zajac <bl...@orcaware.com>
Subject [PATCH] apr_file_flush_locked and short writes
Date Fri, 04 Feb 2011 23:32:51 GMT
Looking at apr_file_flush_locked(), it looks like it doesn't handle short writes for buffered
apr_file_t's, upon a short write the unwritten data will be lost.

Here's a patch for this:

Index: file_io/unix/readwrite.c
===================================================================
--- file_io/unix/readwrite.c	(revision 1067340)
+++ file_io/unix/readwrite.c	(working copy)
@@ -409,7 +409,11 @@
             rv = errno;
         } else {
             thefile->filePtr += written;
-            thefile->bufpos = 0;
+            if (written != thefile->bufpos)
+                memmove(thefile->buffer,
+                        thefile->buffer + written,
+                        thefile->bufpos - written);
+            thefile->bufpos -= written;
         }
     }
 

Beyond this, there's no a mechanism to report that all the buffered data didn't get into the
file.  Perhaps apr_file_flush() should loop until the entire buffer is written or it gets
a non-EINTR error?

Blair


Mime
View raw message