Thread (6 messages) 6 messages, 2 authors, 2021-06-23

Re: [PATCH 2/3] libfile: Add copy_fd()

From: Trent Piepho <hidden>
Date: 2021-06-23 06:26:35

On Tue, Jun 22, 2021 at 9:34 PM Sascha Hauer [off-list ref] wrote:
+       while (1) {
+               int now, wr;
+
+               now = read(in, buf, bs);
+               if (now < 0) {
+                       ret = now;
+                       goto err;
+               }
+
+               if (!now)
+                       break;
+
+               wr = write_full(out, buf, now);
+               if (wr < 0) {
+                       ret = wr;
+                       goto err;
+               }
+       }
+
+       ret = 0;
+err:
+        free(buf);
+
+       return ret;
This can be quite a bit shorter:

while (1) {
       ret = read(in, buf, bs);
       if (ret <= 0)
               break;
       ret = write_full(out, buf, ret);
       if (ret < 0)
               break;
}
free(buf)
return ret;

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help