From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15496 invoked by alias); 3 Feb 2017 10:59:32 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 15478 invoked by uid 89); 3 Feb 2017 10:59:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=BAYES_05,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:D*gmx.de, H*r:Fri, H*F:D*gmx.de, positioning X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.17.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Feb 2017 10:59:29 +0000 Received: from Diogenes.ypsiphon.lan ([188.106.27.66]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MCOdh-1cie8w3BGj-009ByW for ; Fri, 03 Feb 2017 11:59:23 +0100 Received: from [192.168.31.219] (Ovid.fritz.box [192.168.31.219]) by Diogenes.ypsiphon.lan (Postfix) with ESMTP id 2A03F25405B for ; Fri, 3 Feb 2017 11:53:30 +0100 (CET) To: "'newlib@sourceware.org'" From: Stefan Heinzmann Subject: fopen() behavior: File positioning in append mode Message-ID: <23012be5-2810-3215-da19-374c7c081b68@gmx.de> Date: Fri, 03 Feb 2017 10:59:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-UI-Out-Filterresults: notjunk:1;V01:K0:pKCjuH1ARb0=:8YriYz7FwhBMBbAvDjR2Ky o2hR5hyqxeFkoQyhQiNrwvCfQA3J+M4w1ZQsgZMGz0gi+7oCTuveIlwbM929kW8aqnZGj0cgp dTloVjLAXjODZumM1PIUZGCjMcJ+QWwAOzrSA1Ycwd6fTihOZxAjJSYJoBgtJy/cv94n03f5k T8/h5UTOsymKeViDY02+2rKR0MMQCXptB0pXflKeAeaSzkmK5A+F3Bymy4WvsCq2VL1QD3WC/ atRS+chRgFMtzy5P3j8dtiM+qk2QY1NZw42uQU7dfM7lq0FAMDqDxr6r4D5I0kff+qxMG1HJr QkL8FEQeL1D6etYkF84pRVPcs3jOmryDCxetpLbdrWWiqXjZtuVWrFqSpnAYMwc/6SDTPyQys x9Yx7MMV4B2vAiLpdyLaZsyPIX4mZbOz52ZXQ1NZZypvrw5il4L+rZA07SdpvHz9/qm97KU5E EJ9WHYotew4Qe8G1MWNQndyDizHHYOCv3T8rM+nj3FL0+7yogcuyito4RrCrLglZgb0ZlzZzs mSYF/tz6h4fOOLIDDBL0WQOkWdYd99HMWXyprAyvMaH/QrPXx+GeOLy/UNOkIUlFwWIbbAO/6 jfvFgYn//BpwPYk8w37+Vs5A/hDAk4nxd1pCUZQO2YNNkh459D8dhgKIVtCaDwlTXndxMxcwz KWGdtKnQQBV0PjXF2nOZOCjROpnfl548GoFXP8GCVDioN4tnWcLLJdTjdc6pObj5jGolGPrOg m21WXh6vYvLPvYWPLKQEespGSzPCPG2c3D0QmOblWhARujn8PEVv9SJWdMkUjb6yWCZX5C2cV 5okoVELEt0E8pYb9DKQrKLebo+/5QhpnqpyfXDQEuBaYfZPp2c4SpwWh2KjQ6KCZX1b36/4Bn PYglYgclY5naumyI9U8ywy75roOsfbvuB9CaYOzJKHkXvUBRFaQFBn6+JAY599tuxxCdMeCZY ByOXLLb2w/J7GVuGh0cleGb+Zkf/1EFRGgMgXSBJF+vh9+2XAr5tp/4AZbQv9BezTLXTtJE3Z tsBagsiqNNbAgJV2GumWM9A= X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00124.txt.bz2 Hi, I am unsure what the behavior of fopen() should be when the "a+" mode is given. The source for this is in file newlib/libc/stdio/fopen.c Mode a+ translates to open() flags O_RDWR|O_CREAT|O_APPEND according to the POSIX standard. This would set the file position to the beginning of the file. The file position would be relevant only to read operations, since the O_APPEND flag causes writes to happen at the file end in any case. However, fopen() seems to set the file position to the end in this case, by calling fseek() explicitly. The consequence is that read operations also happen at the file end. I don't understand why this is done. Wouldn't it be more useful to omit the call to fseek(), or to restrict it to the write-only case? The C standard doesn't seem to be clear here. Does it actually specify what the result of ftell() should be immediately after calling fopen()? I seem to be unable to find conclusive text. Thanks Stefan