- ret = read(fd, buf + loaded, bufsize - loaded);
- if (ret <= 0)
- return ret;
- loaded += ret;
- ret = for_each_stat_item(buf, loaded, update_item);
- if (ret < 0)
- return ret;
- loaded = ret;
+ ret = read_nonblock(stat_pipe, buf + loaded, bufsize - loaded,
+ rfds, &sz);
+ loaded += sz;
+ ret2 = for_each_stat_item(buf, loaded, update_item);
+ if (ret < 0 || ret2 < 0) {
+ loaded = 0;
+ return ret2 < 0? ret2 : ret;
+ }
+ sz = ret2; /* what is left */
+ if (sz > 0 && sz < loaded)
+ memmove(buf, buf + loaded - sz, sz);
+ loaded = sz;