From dev-return-15244-apmail-apr-dev-archive=apr.apache.org@apr.apache.org Thu Jan 05 01:57:52 2006 Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 25633 invoked from network); 5 Jan 2006 01:57:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 Jan 2006 01:57:51 -0000 Received: (qmail 57304 invoked by uid 500); 5 Jan 2006 01:57:48 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 57254 invoked by uid 500); 5 Jan 2006 01:57:48 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 57182 invoked by uid 99); 5 Jan 2006 01:57:46 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jan 2006 17:57:46 -0800 X-ASF-Spam-Status: No, hits=-2.9 required=10.0 tests=DNS_FROM_RFC_WHOIS,HTML_MESSAGE,NO_REAL_NAME,RCVD_IN_BSP_TRUSTED X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [150.229.7.37] (HELO act-ironport-ext-out1.csiro.au) (150.229.7.37) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jan 2006 17:57:45 -0800 DomainKey-Signature: s=email; d=csiro.au; c=nofws; q=dns; b=npZv9WWMLOw5NiEELV/PGBvUPVExSjA30+S8ZYMerWax22dv28n/bRbX31Gs2oV4XBC0P8/Ywk2wVqmj2yA/Fp5/i/irUsIRwfVYxdRoLJwS4FTAnwiLdAoGRuTCqdhk; Received: from exgw1-cbr.nexus.csiro.au ([152.83.3.66]) by act-ironport-ext-out1.csiro.au with ESMTP; 05 Jan 2006 12:57:32 +1100 X-IronPort-AV: i="3.99,331,1131282000"; d="scan'208,217"; a="75895951:sNHT66727940" Received: from EXACTN1-CBR.nexus.csiro.au ([152.83.3.131]) by exgw1-cbr.nexus.csiro.au with Microsoft SMTPSVC(5.0.2195.6713); Thu, 5 Jan 2006 12:57:31 +1100 Received: from exnswn2-syd.nexus.csiro.au ([130.155.3.32]) by EXACTN1-CBR.nexus.csiro.au with Microsoft SMTPSVC(5.0.2195.6713); Thu, 5 Jan 2006 12:57:32 +1100 X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C6119B.639A0B4E" Subject: RE: problem appending to a file Date: Thu, 5 Jan 2006 12:57:31 +1100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: problem appending to a file Thread-Index: AcYRmK0dZTpE2ysBQSeLwa1DHCrfdQAAgzOQ From: To: X-OriginalArrivalTime: 05 Jan 2006 01:57:32.0020 (UTC) FILETIME=[63E51B40:01C6119B] X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. ------_=_NextPart_001_01C6119B.639A0B4E Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Whoops, I forgot to mention that this is occurring under windows, whereas it works fine under linux. =20 Alex =20 -----Original Message----- From: Krumm-Heller, Alex (ICT Centre, Marsfield)=20 Sent: Thursday, 5 January 2006 12:38 PM To: dev@apr.apache.org Subject: problem appending to a file =20 Hi, =20 I am trying to do some file I/O. The scenario I am aiming for is to create a file if it doesn't exist, append to it if it exists as well as allowing for writes to the file from multiple threads. Yet when I use this combination of options in apr_file_open it always overwrites the file rather than appending to it. If I remove the multiple thread option from the open call, it appends correctly. Is this a bug or am I doing something wrong? Test case follows. =20 =20 #include #include "apr_file_io.h" =20 int main(int argc, char* argv[]) { if (apr_initialize() !=3D APR_SUCCESS)=20 { return -1; } =20 apr_pool_t *context; =20 if (apr_pool_create(&context, NULL) !=3D APR_SUCCESS)=20 { fprintf(stderr, "Couldn't allocate context."); exit(-1); } =20 apr_file_t *logfile; apr_status_t openstatus =3D apr_file_open(&logfile, "test.txt", APR_APPEND | APR_CREATE | APR_WRITE | APR_XTHREAD, APR_OS_DEFAULT, context); if (openstatus !=3D APR_SUCCESS) { return -1; } =20 std::string output("String 1"); apr_size_t written; apr_status_t writestatus =3D apr_file_write_full(logfile, output.c_str(), output.length(), &written); if (writestatus !=3D APR_SUCCESS || written !=3D output.length()) { } =20 apr_file_flush(logfile); if (apr_file_close(logfile) !=3D APR_SUCCESS) { return -1; =20 } logfile =3D NULL; =20 openstatus =3D apr_file_open(&logfile, "test.txt", = APR_APPEND | APR_CREATE | APR_WRITE | APR_XTHREAD, APR_OS_DEFAULT, context); if (openstatus !=3D APR_SUCCESS) { return -1; } =20 output.assign("String 2"); written; writestatus =3D apr_file_write_full(logfile, output.c_str(), output.length(), &written); if (writestatus !=3D APR_SUCCESS || written !=3D output.length()) { } =20 apr_file_flush(logfile); if (apr_file_close(logfile) !=3D APR_SUCCESS) { return -1; =20 } logfile =3D NULL; =20 apr_pool_destroy(context); =20 apr_terminate(); =20 return 0; } =20 =20 --------------------------------------------------------- Alex.Krumm-Heller@csiro.au Centie www.centie.net.au Tel: +61 2 9372 4657 CSIRO ICT Centre=20 Fax: +61 2 9372 4490 Marsfield, NSW, Australia --------------------------------------------------------- =20 ------_=_NextPart_001_01C6119B.639A0B4E Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Whoops, I forgot to mention that = this is occurring under windows, whereas it works fine under linux.

 

Alex

 

-----Original = Message-----
From: Krumm-Heller, Alex = (ICT Centre, Marsfield)
Sent: Thursday, 5 January = 2006 12:38 PM
To: = dev@apr.apache.org
Subject: problem = appending to a file

 

Hi,

 

I am trying to = do some file I/O. The scenario I am aiming for is to create a file if it = doesn’t exist, append to it if it exists as well as allowing for writes to the = file from multiple threads. Yet when I use this combination of options in = apr_file_open it always overwrites the file rather than appending to it. If I remove = the multiple thread option from the open call, it appends correctly. Is this = a bug or am I doing something wrong? Test case follows.

 

 

#include = <string>

#include "apr_file_io.h"

 

int = main(int argc, char* argv[])

{

    &nbs= p;       if (apr_initialize() !=3D APR_SUCCESS)

    &nbs= p;       {

    &nbs= p;   return -1;

            }

 

    &nbs= p;       apr_pool_t *context;

 

    &nbs= p;       if (apr_pool_create(&context, NULL) !=3D APR_SUCCESS) =

    &nbs= p;       {

    &nbs= p;   fprintf(stderr, "Couldn't allocate = context.");

    &nbs= p;   exit(-1);

            }

 

    &nbs= p;       apr_file_t *logfile;

    &nbs= p;       apr_status_t openstatus =3D apr_file_open(&logfile, = "test.txt", APR_APPEND | APR_CREATE | APR_WRITE | APR_XTHREAD, APR_OS_DEFAULT, = context);

    &nbs= p;       if (openstatus !=3D APR_SUCCESS)

    &nbs= p;       {

    &nbs= p;            = ;       return -1;

    &nbs= p;       }

 

    &nbs= p;       std::string output("String 1");

    &nbs= p;       apr_size_t written;

    &nbs= p;       apr_status_t writestatus =3D apr_file_write_full(logfile, = output.c_str(), output.length(), &written);

    &nbs= p;       if (writestatus !=3D APR_SUCCESS || written !=3D = output.length())

    &nbs= p;       {

    &nbs= p;       }

 

    &nbs= p;       apr_file_flush(logfile);

    &nbs= p;       if (apr_file_close(logfile) !=3D APR_SUCCESS)

    &nbs= p;       {

    &nbs= p;            = ;       return -1;           =

    &nbs= p;       }

    &nbs= p;       logfile =3D NULL;

 

    &nbs= p;       openstatus =3D apr_file_open(&logfile, "test.txt", = APR_APPEND | APR_CREATE | APR_WRITE | APR_XTHREAD, APR_OS_DEFAULT, = context);

    &nbs= p;       if (openstatus !=3D APR_SUCCESS)

    &nbs= p;       {

    &nbs= p;            = ;       return -1;

    &nbs= p;       }

 

    &nbs= p;       output.assign("String 2");

    &nbs= p;       written;

    &nbs= p;       writestatus =3D apr_file_write_full(logfile, output.c_str(), = output.length(), &written);

    &nbs= p;       if (writestatus !=3D APR_SUCCESS || written !=3D = output.length())

    &nbs= p;       {

    &nbs= p;       }

 

    &nbs= p;       apr_file_flush(logfile);

    &nbs= p;       if (apr_file_close(logfile) !=3D APR_SUCCESS)

    &nbs= p;       {

    &nbs= p;            = ;       return -1;           =

    &nbs= p;       }

    &nbs= p;       logfile =3D NULL;

 

    &nbs= p;       apr_pool_destroy(context);

 

    &nbs= p;       apr_terminate();

 

    &nbs= p;       return 0;

}

 

 

---------------------------------------------------------

 Alex.Krumm-Heller@csiro.au   = Centie www.centie.net.au

 Tel: +61 2 9372 4657         CSIRO ICT Centre =

 Fax: +61 2 9372 4490         Marsfield, NSW, = Australia

---------------------------------------------------------

 

=00 ------_=_NextPart_001_01C6119B.639A0B4E--