From d0a95de5e7eac0065c2d68e6264c0b5e88979365 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Fri, 8 Apr 2022 15:35:28 +0100 Subject: [PATCH] lib.[ch], dvd-sector-copy.c: Publish `read_line'. --- dvd-sector-copy.c | 13 ------------- lib.c | 13 +++++++++++++ lib.h | 7 +++++++ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/dvd-sector-copy.c b/dvd-sector-copy.c index e699741..a608410 100644 --- a/dvd-sector-copy.c +++ b/dvd-sector-copy.c @@ -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 --- 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 --- 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 -- 2.11.0