From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] errno not set to EBADF when reading from invalid descriptor
Date: Fri, 26 Jun 2020 12:06:24 -0400 [thread overview]
Message-ID: <20200626160624.GZ6430@brightrain.aerifal.cx> (raw)
In-Reply-To: <20200626051400.GB13001@voyager>
On Fri, Jun 26, 2020 at 07:14:00AM +0200, Markus Wichmann wrote:
> On Thu, Jun 25, 2020 at 11:38:04AM -0400, Rich Felker wrote:
> > Note that there are lots of other reasons you can't safely use stdio
> > read functions on a stream you don't know is suitable for it.
> > Switching from writing to reading without a successful flush produces
> > UB, and switching the other direction without a successful seek does,
> > even if the FILE stream is open for both.
>
> So I can't actually use a FILE open for reading and writing that refers
> to something non-seekable, like a serial line, to both read and write to
> it? I mean, I suppose I could write something and then flush and stay in
> read mode forever, but that is not really the nature of my application.
> I suppose I'll just open the serial line twice.
Indeed, you basically always need 2 FILEs for bidirectional io. The
only case where you don't is when it's a normal seekable file and
you're willing to follow the arcane rules for switching modes (which
may make sense if it's a trivial case like writing whole file,
rewinding, then only reading from that point forward, which is a
fairly canonical use case for tmpfile()).
Rich
prev parent reply other threads:[~2020-06-26 16:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-25 13:21 Stefan Ciotec
2020-06-25 15:38 ` Rich Felker
2020-06-26 5:14 ` Markus Wichmann
2020-06-26 5:39 ` Damian McGuckin
2020-06-26 16:06 ` Rich Felker [this message]
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=20200626160624.GZ6430@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).