lib.[ch], dvd-sector-copy.c: Publish `read_line'.
[dvdrip] / lib.c
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;