From: Michael Haggerty <mhagger@alum.mit.edu>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 1/4] strbuf.c: keep errno in strbuf_read_file()
Date: Fri, 26 Sep 2014 12:30:38 +0200 [thread overview]
Message-ID: <5425404E.7050100@alum.mit.edu> (raw)
In-Reply-To: <1406285039-22469-2-git-send-email-pclouds@gmail.com>
On 07/25/2014 12:43 PM, Nguyễn Thái Ngọc Duy wrote:
> This function is used to replaced some code in the next patch that
> does this (i.e. keep the errno when read() fails)
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> strbuf.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/strbuf.c b/strbuf.c
> index 33018d8..61d685d 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -454,15 +454,18 @@ int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
>
> int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
> {
> - int fd, len;
> + int fd, len, saved_errno;
>
> fd = open(path, O_RDONLY);
> if (fd < 0)
> return -1;
> len = strbuf_read(sb, fd, hint);
> + saved_errno = errno;
> close(fd);
Theoretically close() can fail, though it seems a little far-fetched
(and also uninteresting) if it fails for a file opened read-only. But if
it did, you would not notice the error.
So I grepped through our code to see whether we typically bother to
check the return value when close()ing a read-only file. And I found
that we rarely even check its return value when *writing* to a file.
(Many of those places are probably bugs.)
So, carry on and forget I said anything :-)
> - if (len < 0)
> + if (len < 0) {
> + errno = saved_errno;
> return -1;
> + }
>
> return len;
> }
>
Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu>
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
next prev parent reply other threads:[~2014-09-26 10:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-25 10:43 [PATCH 0/4] Consolidate ref parsing code Nguyễn Thái Ngọc Duy
2014-07-25 10:43 ` [PATCH 1/4] strbuf.c: keep errno in strbuf_read_file() Nguyễn Thái Ngọc Duy
2014-07-25 15:41 ` Eric Sunshine
2014-09-26 10:30 ` Michael Haggerty [this message]
2014-07-25 10:43 ` [PATCH 2/4] refs.c: refactor resolve_ref_unsafe() to use strbuf internally Nguyễn Thái Ngọc Duy
2014-07-25 15:55 ` Eric Sunshine
2014-07-30 19:53 ` Junio C Hamano
2014-07-25 10:43 ` [PATCH 3/4] refs.c: move ref parsing code out of resolve_ref() Nguyễn Thái Ngọc Duy
2014-07-25 16:12 ` Ronnie Sahlberg
2014-07-26 1:50 ` Duy Nguyen
2014-07-25 10:43 ` [PATCH 4/4] refs.c: rewrite resolve_gitlink_ref() to use parse_ref() Nguyễn Thái Ngọc Duy
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=5425404E.7050100@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.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.
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).