git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/4] strbuf.c: keep errno in strbuf_read_file()

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 25, 2014, 15:41 UTC
Message-ID
<CAPig+cS4CV+1nsab2yZCYbYsRfKJoE60Gh5KxjE-0qE-3ZuRtQ@mail.gmail.com>
In-Reply-To
<1406285039-22469-2-git-send-email-pclouds@gmail.com>
On Fri, Jul 25, 2014 at 6:43 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> This function is used to replaced some code in the next patch that
s/replaced/replace/
Show 39 quoted lines
> 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);
> -       if (len < 0)
> +       if (len < 0) {
> +               errno = saved_errno;
>                 return -1;
> +       }
>
>         return len;
>  }
> --
> 1.9.1.346.ga2b5940
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Nguyễn Thái Ngọc DuyNext: Michael Haggerty
Message 3 of 11 in “Consolidate ref parsing code”
  1. 0/4 Consolidate ref parsing codeNguyễn Thái Ngọc Duy, Jul 25, 2014
  2. 1/4 strbuf.c: keep errno in strbuf_read_file()Nguyễn Thái Ngọc Duy, Jul 25, 2014
  3. Eric SunshineJul 25, 2014
  4. Michael HaggertySep 26, 2014
  5. 2/4 refs.c: refactor resolve_ref_unsafe() to use strbuf internallyNguyễn Thái Ngọc Duy, Jul 25, 2014
  6. Eric SunshineJul 25, 2014
  7. Junio C HamanoJul 30, 2014
  8. 3/4 refs.c: move ref parsing code out of resolve_ref()Nguyễn Thái Ngọc Duy, Jul 25, 2014
  9. Ronnie SahlbergJul 25, 2014
  10. Duy NguyenJul 26, 2014
  11. 4/4 refs.c: rewrite resolve_gitlink_ref() to use parse_ref()Nguyễn Thái Ngọc Duy, Jul 25, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.