diff options
author | rooneg <rooneg@13f79535-47bb-0310-9956-ffa450edef68> | 2006-01-30 07:04:30 +0000 |
---|---|---|
committer | rooneg <rooneg@13f79535-47bb-0310-9956-ffa450edef68> | 2006-01-30 07:04:30 +0000 |
commit | 688f28e2f67df4d40f84fb805f2c2f282d1b2383 (patch) | |
tree | dc0cdc8e50b26eafb1dc6ccba483cd5cc9ae4dad | |
parent | 467af56e0fc313a35672d2b7f6549663ce9541fe (diff) | |
download | libapr-688f28e2f67df4d40f84fb805f2c2f282d1b2383.tar.gz |
Merge r373453 into 0.9.x, with necessary changes to tests to account for
the old test framework.
Original log message:
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.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/0.9.x@373455 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | file_io/win32/seek.c | 4 | ||||
-rw-r--r-- | test/testfile.c | 50 |
3 files changed, 55 insertions, 2 deletions
@@ -1,5 +1,8 @@ Changes with APR 0.9.8 + *) 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] *) Cause apr_file_write_full on win32 to consider the timeout value set by diff --git a/file_io/win32/seek.c b/file_io/win32/seek.c index a278cbd8b..f1e1cb685 100644 --- a/file_io/win32/seek.c +++ b/file_io/win32/seek.c @@ -99,8 +99,8 @@ APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t wh 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: diff --git a/test/testfile.c b/test/testfile.c index 7871fc3d6..811a1b787 100644 --- a/test/testfile.c +++ b/test/testfile.c @@ -596,6 +596,55 @@ static void test_fail_read_flush(CuTest *tc) apr_file_remove(fname, p); } +static void test_xthread(CuTest *tc) +{ + 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); + + rv = apr_file_open(&f, fname, flags, APR_UREAD|APR_UWRITE, p); + CuAssert(tc, "open test file", rv == APR_SUCCESS); + + rv = apr_file_puts("hello", f); + CuAssert(tc, "write should succeed", rv == APR_SUCCESS); + + apr_file_close(f); + + rv = apr_file_open(&f, fname, flags, APR_UREAD|APR_UWRITE, p); + CuAssert(tc, "open test file", rv == APR_SUCCESS); + + /* Seek to the end. */ + { + apr_off_t offset = 0; + + rv = apr_file_seek(f, APR_END, &offset); + } + + rv = apr_file_puts("world", f); + CuAssert(tc, "more writes should succeed", rv == APR_SUCCESS); + + /* 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); + + CuAssertStrEquals(tc, "helloworld", buf); + + apr_file_close(f); +} + CuSuite *testfile(void) { CuSuite *suite = CuSuiteNew("File I/O"); @@ -623,6 +672,7 @@ CuSuite *testfile(void) SUITE_ADD_TEST(suite, test_truncate); SUITE_ADD_TEST(suite, test_fail_write_flush); SUITE_ADD_TEST(suite, test_fail_read_flush); + SUITE_ADD_TEST(suite, test_xthread); return suite; } |