apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r373453 - in /apr/apr/trunk: CHANGES file_io/win32/seek.c test/testfile.c
Date Mon, 30 Jan 2006 06:49:01 GMT
Author: rooneg
Date: Sun Jan 29 22:48:56 2006
New Revision: 373453

URL: http://svn.apache.org/viewcvs?rev=373453&view=rev
Log:
Fix bug #38438, seeks are broken for files opened for append in xthread
mode on win32.

Submitted by: M Joonas Pihlaja <jpihlaja cc.helsinki.fi>
Test by: Garrett Rooney

* file_io/win32/seek.c
  (apr_file_seek): Fix APR_END case of APR_XTHREAD case.

* test/testfile.c
  (test_xthread): New test.
  (testfile): Run new test.

* CHANGES: Note change.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/file_io/win32/seek.c
    apr/apr/trunk/test/testfile.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/CHANGES?rev=373453&r1=373452&r2=373453&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES (original)
+++ apr/apr/trunk/CHANGES Sun Jan 29 22:48:56 2006
@@ -1,5 +1,8 @@
 Changes for APR 1.3.0
 
+  *) Fix seeks with files opened in xthread mode for append on win32.
+     [M Joonas Pihlaja <jpihlaja cc.helsinki.fi>, Garrett Rooney]
+
   *) Keep testpipe.c from hanging on win32. [Garrett Rooney]
 
   *) Fix assertion from double close of a handle with a rwlock on win32.

Modified: apr/apr/trunk/file_io/win32/seek.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/win32/seek.c?rev=373453&r1=373452&r2=373453&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/seek.c (original)
+++ apr/apr/trunk/file_io/win32/seek.c Sun Jan 29 22:48:56 2006
@@ -105,8 +105,8 @@
         
             case APR_END:
                 rc = apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile);
-                if (rc == APR_SUCCESS && finfo.size - *offset < 0)
-                    thefile->filePtr = finfo.size - *offset;
+                if (rc == APR_SUCCESS && finfo.size + *offset >= 0)
+                    thefile->filePtr = finfo.size + *offset;
                 break;
 
             default:

Modified: apr/apr/trunk/test/testfile.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/test/testfile.c?rev=373453&r1=373452&r2=373453&view=diff
==============================================================================
--- apr/apr/trunk/test/testfile.c (original)
+++ apr/apr/trunk/test/testfile.c Sun Jan 29 22:48:56 2006
@@ -808,6 +808,56 @@
     apr_file_close(f);
 }
 
+static void test_xthread(abts_case *tc, void *data)
+{
+    apr_file_t *f;
+    const char *fname = "data/testxthread.dat";
+    apr_status_t rv;
+    apr_int32_t flags = APR_CREATE|APR_READ|APR_WRITE|APR_APPEND|APR_XTHREAD;
+    char buf[128] = { 0 };
+
+    /* Test for bug 38438, opening file with append + xthread and seeking to 
+       the end of the file resulted in writes going to the beginning not the
+       end. */
+
+    apr_file_remove(fname, p);
+
+    APR_ASSERT_SUCCESS(tc, "open test file",
+                       apr_file_open(&f, fname, flags,
+                                     APR_UREAD|APR_UWRITE, p));
+
+    APR_ASSERT_SUCCESS(tc, "write should succeed",
+                       apr_file_puts("hello", f));
+
+    apr_file_close(f);
+    
+    APR_ASSERT_SUCCESS(tc, "open test file",
+                       apr_file_open(&f, fname, flags,
+                                     APR_UREAD|APR_UWRITE, p));
+
+    /* Seek to the end. */
+    {
+        apr_off_t offset = 0;
+
+        rv = apr_file_seek(f, APR_END, &offset);
+    }
+
+    APR_ASSERT_SUCCESS(tc, "more writes should succeed",
+                       apr_file_puts("world", f));
+
+    /* Back to the beginning. */
+    {
+        apr_off_t offset = 0;
+        
+        rv = apr_file_seek(f, APR_SET, &offset);
+    }
+    
+    apr_file_read_full(f, buf, sizeof(buf), NULL);
+
+    ABTS_STR_EQUAL(tc, "helloworld", buf);
+
+    apr_file_close(f);
+}
 
 abts_suite *testfile(abts_suite *suite)
 {
@@ -842,6 +892,7 @@
     abts_run_test(suite, test_fail_write_flush, NULL);
     abts_run_test(suite, test_fail_read_flush, NULL);
     abts_run_test(suite, test_buffer_set_get, NULL);
+    abts_run_test(suite, test_xthread, NULL);
 
     return suite;
 }



Mime
View raw message