X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fio%2Fio.c;h=bdcbf9e26b8f9f580fea08c2c0913d31efe9dcc7;hp=c0dd9b838e84af6ec8ef6b62dec8fe3695adf94c;hb=fedf515165bfafaf4fb98252ecda1abe050c8da5;hpb=b6e8d929d2c0c37afc840ac99e3e0f469e33e6c0 diff --git a/ccan/io/io.c b/ccan/io/io.c index c0dd9b83..bdcbf9e2 100644 --- a/ccan/io/io.c +++ b/ccan/io/io.c @@ -202,8 +202,12 @@ struct io_plan *io_write_(struct io_conn *conn, const void *data, size_t len, static int do_read(int fd, struct io_plan_arg *arg) { ssize_t ret = read(fd, arg->u1.cp, arg->u2.s); - if (ret <= 0) + if (ret <= 0) { + /* Errno isn't set if we hit EOF, so set it to distinct value */ + if (ret == 0) + errno = 0; return -1; + } arg->u1.cp += ret; arg->u2.s -= ret; @@ -230,8 +234,12 @@ struct io_plan *io_read_(struct io_conn *conn, static int do_read_partial(int fd, struct io_plan_arg *arg) { ssize_t ret = read(fd, arg->u1.cp, *(size_t *)arg->u2.vp); - if (ret <= 0) + if (ret <= 0) { + /* Errno isn't set if we hit EOF, so set it to distinct value */ + if (ret == 0) + errno = 0; return -1; + } *(size_t *)arg->u2.vp = ret; return 1;