From cbac0245c8fd94ce66c05b1abe05bfa0d6dda251 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Fri, 24 Jun 2022 12:17:32 +1000 Subject: Remove unused line_read() The old, ugly implementation of line_read() is no longer used. Remove it. Signed-off-by: David Gibson --- util.c | 54 ------------------------------------------------------ 1 file changed, 54 deletions(-) diff --git a/util.c b/util.c index 83729d2..98946e4 100644 --- a/util.c +++ b/util.c @@ -409,60 +409,6 @@ int bitmap_isset(const uint8_t *map, int bit) return !!(*word & BITMAP_BIT(bit)); } -/** - * line_read() - Similar to fgets(), no heap usage, a file instead of a stream - * @buf: Read buffer: on non-empty string, use that instead of reading - * @len: Maximum line length - * @fd: File descriptor for reading - * - * Return: @buf if a line is found, NULL on EOF or error - */ -char *line_read(char *buf, size_t len, int fd) -{ - int n, do_read = !*buf; - char *p; - - if (!do_read) { - char *nl; - - buf[len - 1] = 0; - if (!strlen(buf)) - return NULL; - - p = buf + strlen(buf) + 1; - - while (*p == '\n' && strlen(p) && (size_t)(p - buf) < len) - p++; - - if (!(nl = strchr(p, '\n'))) - return NULL; - *nl = 0; - - return memmove(buf, p, len - (p - buf)); - } - - n = read(fd, buf, --len); - if (n <= 0) - return NULL; - - buf[len] = 0; - - p = buf; - while (*p == '\n' && strlen(p) && (size_t)(p - buf) < len) - p++; - - if (!(p = strchr(p, '\n'))) - return buf; - - *p = 0; - if (p == buf) - return buf; - - lseek(fd, (p - buf) - n + 1, SEEK_CUR); - - return buf; -} - /** * procfs_scan_listen() - Set bits for listening TCP or UDP sockets from procfs * @proto: IPPROTO_TCP or IPPROTO_UDP -- cgit v1.2.3