shithub: orca

Download patch

ref: 83ea4dfd306469d4ddb2050f1c41909e9aa5619e
parent: a51bfc11169adc42c383754dfbd88c9cf455341b
author: cancel <cancel@cancel.fm>
date: Fri Jan 3 19:26:06 EST 2020

Change cboard_pase() to use fread instead of fgetc

--- a/cboard.c
+++ b/cboard.c
@@ -24,22 +24,24 @@
   Usz start_x = x;
   if (!fp)
     return Cboard_error_popen_failed;
+  char inbuff[512];
   for (;;) {
-    int c = fgetc(fp);
-    if (c == EOF)
-      break;
-    if (c == '\r' || c == '\n') {
-      y++;
-      x = start_x;
-      continue;
+    size_t n = fread(inbuff, 1, sizeof inbuff, fp);
+    for (size_t i = 0; i < n; i++) {
+      char c = inbuff[i];
+      if (c == '\r' || c == '\n') {
+        y++;
+        x = start_x;
+        continue;
+      }
+      if (c != ' ' && y < height && x < width) {
+        Glyph g = is_valid_glyph((Glyph)c) ? (Glyph)c : '.';
+        gbuffer_poke(gbuffer, height, width, y, x, g);
+      }
+      x++;
     }
-    if (c != ' ' && y < height && x < width) {
-      Glyph g = c <= CHAR_MAX && c >= CHAR_MIN && is_valid_glyph((Glyph)c)
-                    ? (Glyph)c
-                    : '.';
-      gbuffer_poke(gbuffer, height, width, y, x, g);
-    }
-    x++;
+    if (n < sizeof inbuff)
+      break;
   }
   int status = pclose(fp);
   return status ? Cboard_error_process_exit_error : Cboard_error_none;