You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by ko...@apache.org on 2023/02/07 10:49:56 UTC
svn commit: r1907498 - in /apr/apr/branches/1.7.x: ./ CHANGES file_io/win32/open.c test/testfile.c
Author: kotkov
Date: Tue Feb 7 10:49:56 2023
New Revision: 1907498
URL: http://svn.apache.org/viewvc?rev=1907498&view=rev
Log:
On 1.7.x branch: Merge r1808456 from trunk:
Don't seek to the end when opening files with APR_FOPEN_APPEND on Windows.
Modified:
apr/apr/branches/1.7.x/ (props changed)
apr/apr/branches/1.7.x/CHANGES
apr/apr/branches/1.7.x/file_io/win32/open.c
apr/apr/branches/1.7.x/test/testfile.c
Propchange: apr/apr/branches/1.7.x/
------------------------------------------------------------------------------
Merged /apr/apr/trunk:r1808456
Modified: apr/apr/branches/1.7.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/CHANGES?rev=1907498&r1=1907497&r2=1907498&view=diff
==============================================================================
--- apr/apr/branches/1.7.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.7.x/CHANGES [utf-8] Tue Feb 7 10:49:56 2023
@@ -13,6 +13,9 @@ Changes for APR 1.7.3
on Windows. PR 50058.
[Evgeny Kotkov <evgeny.kotkov visualsvn.com>]
+ *) Don't seek to the end when opening files with APR_FOPEN_APPEND on Windows.
+ [Evgeny Kotkov <evgeny.kotkov visualsvn.com>]
+
Changes for APR 1.7.2
*) Correct a packaging issue in 1.7.1. The contents of the release were
Modified: apr/apr/branches/1.7.x/file_io/win32/open.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/file_io/win32/open.c?rev=1907498&r1=1907497&r2=1907498&view=diff
==============================================================================
--- apr/apr/branches/1.7.x/file_io/win32/open.c (original)
+++ apr/apr/branches/1.7.x/file_io/win32/open.c Tue Feb 7 10:49:56 2023
@@ -445,7 +445,6 @@ APR_DECLARE(apr_status_t) apr_file_open(
if (flag & APR_FOPEN_APPEND) {
(*new)->append = 1;
- SetFilePointer((*new)->filehand, 0, NULL, FILE_END);
}
if (flag & APR_FOPEN_BUFFERED) {
(*new)->buffered = 1;
Modified: apr/apr/branches/1.7.x/test/testfile.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/test/testfile.c?rev=1907498&r1=1907497&r2=1907498&view=diff
==============================================================================
--- apr/apr/branches/1.7.x/test/testfile.c (original)
+++ apr/apr/branches/1.7.x/test/testfile.c Tue Feb 7 10:49:56 2023
@@ -1637,6 +1637,56 @@ static void test_append_locked(abts_case
apr_file_remove(fname, p);
}
+static void test_append_read(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_file_t *f;
+ const char *fname = "data/testappend_read.dat";
+ apr_off_t offset;
+ char buf[64];
+
+ apr_file_remove(fname, p);
+
+ /* Create file with contents. */
+ rv = apr_file_open(&f, fname, APR_FOPEN_WRITE | APR_FOPEN_CREATE,
+ APR_FPROT_OS_DEFAULT, p);
+ APR_ASSERT_SUCCESS(tc, "create file", rv);
+
+ rv = apr_file_puts("abc", f);
+ APR_ASSERT_SUCCESS(tc, "write to file", rv);
+ apr_file_close(f);
+
+ /* Re-open it with APR_FOPEN_APPEND. */
+ rv = apr_file_open(&f, fname,
+ APR_FOPEN_READ | APR_FOPEN_WRITE | APR_FOPEN_APPEND,
+ APR_FPROT_OS_DEFAULT, p);
+ APR_ASSERT_SUCCESS(tc, "open file", rv);
+
+ /* Test the initial file offset. Even though we used APR_FOPEN_APPEND,
+ * the offset should be kept in the beginning of the file until the
+ * first append. (Previously, the Windows implementation performed
+ * an erroneous seek to the file's end right after opening it.)
+ */
+ offset = 0;
+ rv = apr_file_seek(f, APR_CUR, &offset);
+ APR_ASSERT_SUCCESS(tc, "get file offset", rv);
+ ABTS_INT_EQUAL(tc, 0, (int)offset);
+
+ /* Test reading from the file. */
+ rv = apr_file_gets(buf, sizeof(buf), f);
+ APR_ASSERT_SUCCESS(tc, "read from file", rv);
+ ABTS_STR_EQUAL(tc, "abc", buf);
+
+ /* Test the file offset after reading. */
+ offset = 0;
+ rv = apr_file_seek(f, APR_CUR, &offset);
+ APR_ASSERT_SUCCESS(tc, "get file offset", rv);
+ ABTS_INT_EQUAL(tc, 3, (int)offset);
+
+ apr_file_close(f);
+ apr_file_remove(fname, p);
+}
+
abts_suite *testfile(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -1690,6 +1740,7 @@ abts_suite *testfile(abts_suite *suite)
abts_run_test(suite, test_datasync_on_stream, NULL);
abts_run_test(suite, test_atomic_append, NULL);
abts_run_test(suite, test_append_locked, NULL);
+ abts_run_test(suite, test_append_read, NULL);
return suite;
}