Return-Path: Delivered-To: apmail-apr-commits-archive@www.apache.org Received: (qmail 73809 invoked from network); 11 May 2007 02:11:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 May 2007 02:11:47 -0000 Received: (qmail 50590 invoked by uid 500); 11 May 2007 02:11:53 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 50548 invoked by uid 500); 11 May 2007 02:11:53 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 50533 invoked by uid 99); 11 May 2007 02:11:53 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 May 2007 19:11:53 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 May 2007 19:11:46 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 0628C1A9838; Thu, 10 May 2007 19:11:26 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r537066 - in /apr/apr/trunk: file_io/unix/readwrite.c test/testfile.c Date: Fri, 11 May 2007 02:11:25 -0000 To: commits@apr.apache.org From: bojan@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070511021126.0628C1A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bojan Date: Thu May 10 19:11:25 2007 New Revision: 537066 URL: http://svn.apache.org/viewvc?view=rev&rev=537066 Log: The file pointer position must be recalculated and set when writev()ing to a buffered file. Fix by Davi Arnaut for bug #40963 Modified: apr/apr/trunk/file_io/unix/readwrite.c apr/apr/trunk/test/testfile.c Modified: apr/apr/trunk/file_io/unix/readwrite.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/readwrite.c?view=diff&rev=537066&r1=537065&r2=537066 ============================================================================== --- apr/apr/trunk/file_io/unix/readwrite.c (original) +++ apr/apr/trunk/file_io/unix/readwrite.c Thu May 10 19:11:25 2007 @@ -252,6 +252,15 @@ if (rv != APR_SUCCESS) { return rv; } + if (thefile->direction == 0) { + /* Position file pointer for writing at the offset we are + * logically reading from + */ + apr_int64_t offset = thefile->filePtr - thefile->dataRead + thefile->bufpos; + if (offset != thefile->filePtr) + lseek(thefile->filedes, offset, SEEK_SET); + thefile->bufpos = thefile->dataRead = 0; + } } #ifdef HAVE_WRITEV Modified: apr/apr/trunk/test/testfile.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testfile.c?view=diff&rev=537066&r1=537065&r2=537066 ============================================================================== --- apr/apr/trunk/test/testfile.c (original) +++ apr/apr/trunk/test/testfile.c Thu May 10 19:11:25 2007 @@ -715,6 +715,44 @@ strlen(TESTSTR) + strlen(LINE1) + strlen(LINE2)); } +static void test_writev_buffered_seek(abts_case *tc, void *data) +{ + apr_file_t *f; + apr_status_t rv; + apr_off_t off = 0; + struct iovec vec[3]; + apr_size_t nbytes = strlen(TESTSTR); + char *str = apr_pcalloc(p, nbytes+1); + const char *fname = "data/testwritev_buffered.dat"; + + APR_ASSERT_SUCCESS(tc, "open file for writing", + apr_file_open(&f, fname, + APR_WRITE | APR_READ | APR_BUFFERED, + APR_OS_DEFAULT, p)); + + rv = apr_file_read(f, str, &nbytes); + ABTS_STR_EQUAL(tc, TESTSTR, str); + APR_ASSERT_SUCCESS(tc, "buffered seek", apr_file_seek(f, APR_SET, &off)); + + vec[0].iov_base = LINE1; + vec[0].iov_len = strlen(LINE1); + vec[1].iov_base = LINE2; + vec[1].iov_len = strlen(LINE2); + vec[2].iov_base = TESTSTR; + vec[2].iov_len = strlen(TESTSTR); + + APR_ASSERT_SUCCESS(tc, "writev of size 2 to file", + apr_file_writev(f, vec, 3, &nbytes)); + + APR_ASSERT_SUCCESS(tc, "close for writing", + apr_file_close(f)); + + file_contents_equal(tc, fname, LINE1 LINE2 TESTSTR, + strlen(LINE1) + strlen(LINE2) + strlen(TESTSTR)); + + APR_ASSERT_SUCCESS(tc, "remove file", apr_file_remove(fname, p)); +} + static void test_truncate(abts_case *tc, void *data) { apr_status_t rv; @@ -941,6 +979,7 @@ abts_run_test(suite, test_writev, NULL); abts_run_test(suite, test_writev_full, NULL); abts_run_test(suite, test_writev_buffered, NULL); + abts_run_test(suite, test_writev_buffered_seek, NULL); abts_run_test(suite, test_bigread, NULL); abts_run_test(suite, test_mod_neg, NULL); abts_run_test(suite, test_truncate, NULL);