lib.[ch], dvd-sector-copy.c: Publish `read_line'.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 8 Apr 2022 14:35:28 +0000 (15:35 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 8 Apr 2022 14:35:28 +0000 (15:35 +0100)
dvd-sector-copy.c
lib.c
lib.h

index e699741..a608410 100644 (file)
@@ -805,19 +805,6 @@ static void emit(secaddr start, secaddr end)
 #undef BUFSECTORS
 }
 
-static int read_line(FILE *fp, struct buf *b)
-{
-  int ch;
-
-  ch = getc(fp);
-  if (ch == EOF)
-    return (-1);
-  else if (ch != '\n')
-    do { buf_putc(b, ch); ch = getc(fp); } while (ch != EOF && ch != '\n');
-  buf_putz(b);
-  return (0);
-}
-
 #define PRF_HYPHEN 1u
 static int parse_range(const char *p, unsigned f,
                       secaddr *start_out, secaddr *end_out)
diff --git a/lib.c b/lib.c
index 320f04d..2147228 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -137,6 +137,19 @@ double tvdiff(const struct timeval *tv_lo, const struct timeval *tv_hi)
          (tv_hi->tv_usec - tv_lo->tv_usec)/1.0e6);
 }
 
+int read_line(FILE *fp, struct buf *b)
+{
+  int ch;
+
+  ch = getc(fp);
+  if (ch == EOF)
+    return (-1);
+  else if (ch != '\n')
+    do { buf_putc(b, ch); ch = getc(fp); } while (ch != EOF && ch != '\n');
+  buf_putz(b);
+  return (0);
+}
+
 void carefully_write(int fd, const void *buf, size_t sz)
 {
   const unsigned char *p = buf;
diff --git a/lib.h b/lib.h
index 2b8eb6b..b982286 100644 (file)
--- a/lib.h
+++ b/lib.h
@@ -240,6 +240,13 @@ extern void sit(double t);
         * fractional.
         */
 
+extern int read_line(FILE *fp, struct buf *b);
+       /* Read a line from FP, appending it to the buffer B, leaving the
+        * string in B null-terminated (as if by `buf_putz').  Return 0 on
+        * success, or -1 if nothing was read (not even an empty line) before
+        * we encountered end-of-file or a read error.
+        */
+
 extern void carefully_write(int fd, const void *buf, size_t sz);
        /* Write SZ bytes to file descriptor FD, starting at BUF.  Report a
         * fatal error if this fails.  Correctly handles short writes and