From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: [PATCH v2 4/4] Remove unused line_read() Date: Fri, 24 Jun 2022 12:17:32 +1000 Message-ID: <20220624021732.4062212-5-david@gibson.dropbear.id.au> In-Reply-To: <20220624021732.4062212-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============9187320681296392038==" --===============9187320681296392038== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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)); } =20 -/** - * line_read() - Similar to fgets(), no heap usage, a file instead of a stre= am - * @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 =3D !*buf; - char *p; - - if (!do_read) { - char *nl; - - buf[len - 1] =3D 0; - if (!strlen(buf)) - return NULL; - - p =3D buf + strlen(buf) + 1; - - while (*p =3D=3D '\n' && strlen(p) && (size_t)(p - buf) < len) - p++; - - if (!(nl =3D strchr(p, '\n'))) - return NULL; - *nl =3D 0; - - return memmove(buf, p, len - (p - buf)); - } - - n =3D read(fd, buf, --len); - if (n <=3D 0) - return NULL; - - buf[len] =3D 0; - - p =3D buf; - while (*p =3D=3D '\n' && strlen(p) && (size_t)(p - buf) < len) - p++; - - if (!(p =3D strchr(p, '\n'))) - return buf; - - *p =3D 0; - if (p =3D=3D 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 pro= cfs * @proto: IPPROTO_TCP or IPPROTO_UDP --=20 2.36.1 --===============9187320681296392038==--