From: Jim Meyering <jim@meyering.net>
To: Jeff King <peff@peff.net>
Cc: git list <git@vger.kernel.org>
Subject: Re: [PATCH] remove unnecessary test and dead diagnostic
Date: Thu, 26 May 2011 16:37:10 +0200 [thread overview]
Message-ID: <87hb8h5y09.fsf@rho.meyering.net> (raw)
In-Reply-To: <20110526141130.GB18520@sigill.intra.peff.net> (Jeff King's message of "Thu, 26 May 2011 10:11:30 -0400")
Jeff King wrote:
...
> $ sed -n '/read_in_full/,/^}/p' wrapper.c
> ssize_t read_in_full(int fd, void *buf, size_t count)
> {
> char *p = buf;
> ssize_t total = 0;
>
> while (count > 0) {
> ssize_t loaded = xread(fd, p, count);
> if (loaded <= 0)
> return total ? total : loaded;
> count -= loaded;
> p += loaded;
> total += loaded;
> }
>
> return total;
> }
>
> It looks like if we get -1 on the _first_ read, we will then return -1.
> Subsequent errors are then ignored, and we return the (possibly
> truncated) result.
>
> Which, to be honest, seems kind of insane to me. I'd think:
>
> while (count > 0) {
> ssize_t loaded = xread(fd, p, count);
> if (loaded < 0)
> return loaded;
> if (loaded == 0)
> return total;
> ...
> }
>
> would be much more sensible semantics.
That looks better to me, too.
next prev parent reply other threads:[~2011-05-26 14:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-26 13:59 [PATCH] remove unnecessary test and dead diagnostic Jim Meyering
2011-05-26 14:11 ` Jeff King
2011-05-26 14:34 ` Jim Meyering
2011-05-26 16:28 ` Jeff King
2011-05-26 14:37 ` Jim Meyering [this message]
2011-05-26 16:30 ` [PATCH] read_in_full: always report errors Jeff King
2011-05-26 18:35 ` Junio C Hamano
2011-05-26 18:48 ` Jeff King
2011-05-26 20:53 ` Junio C Hamano
2011-05-26 21:04 ` Jeff King
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=87hb8h5y09.fsf@rho.meyering.net \
--to=jim@meyering.net \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.