From: Stefan Heinzmann <stefan_heinzmann@gmx.de>
To: "'newlib@sourceware.org'" <newlib@sourceware.org>
Subject: fopen() behavior: File positioning in append mode
Date: Fri, 03 Feb 2017 10:59:00 -0000 [thread overview]
Message-ID: <23012be5-2810-3215-da19-374c7c081b68@gmx.de> (raw)
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
next reply other threads:[~2017-02-03 10:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-03 10:59 Stefan Heinzmann [this message]
2017-02-03 15:11 ` Craig Howland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23012be5-2810-3215-da19-374c7c081b68@gmx.de \
--to=stefan_heinzmann@gmx.de \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).