X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftal%2Fgrab_file%2Fgrab_file.c;fp=ccan%2Ftal%2Fgrab_file%2Fgrab_file.c;h=6528780a67813aae78f43b318ce72e7eaca3b6c1;hp=88e7c22533ad2b8d1a1b07253e5ea613e99baf14;hb=9bdb4be82879348fc3867a922445a4aa06ff8ffd;hpb=0dc646755921a05961442f5f11faf5ce7007f558 diff --git a/ccan/tal/grab_file/grab_file.c b/ccan/tal/grab_file/grab_file.c index 88e7c225..6528780a 100644 --- a/ccan/tal/grab_file/grab_file.c +++ b/ccan/tal/grab_file/grab_file.c @@ -5,6 +5,7 @@ #include #include #include +#include #include void *grab_fd(const void *ctx, int fd) @@ -22,7 +23,12 @@ void *grab_fd(const void *ctx, int fd) max = 16384; buffer = tal_arr(ctx, char, max+1); - while ((ret = read(fd, buffer + size, max - size)) > 0) { + while ((ret = read(fd, buffer + size, max - size)) != 0) { + if (ret < 0) { + if (errno == EINTR) + continue; + return tal_free(buffer); + } size += ret; if (size == max) { size_t extra = max; @@ -35,12 +41,8 @@ void *grab_fd(const void *ctx, int fd) max += extra; } } - if (ret < 0) - buffer = tal_free(buffer); - else { - buffer[size] = '\0'; - tal_resize(&buffer, size+1); - } + buffer[size] = '\0'; + tal_resize(&buffer, size+1); return buffer; }