public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top
Subject: [PATCH 4/4] Remove unused line_read()
Date: Fri, 17 Jun 2022 13:10:26 +1000	[thread overview]
Message-ID: <20220617031026.498690-5-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20220617031026.498690-1-david@gibson.dropbear.id.au>

[-- Attachment #1: Type: text/plain, Size: 1656 bytes --]

The old, ugly implementation of line_read() is no longer used.  Remove it.

Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au>
---
 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
-- 
@@ -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
-- 
2.36.1


      parent reply	other threads:[~2022-06-17  3:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17  3:10 [PATCH 0/4] New line reading implementation David Gibson
2022-06-17  3:10 ` [PATCH 1/4] Add cleaner line-by-line reading primitives David Gibson
2022-06-23  9:31   ` Stefano Brivio
2022-06-24  2:12     ` David Gibson
2022-06-17  3:10 ` [PATCH 2/4] Parse resolv.conf with new lineread implementation David Gibson
2022-06-17  3:10 ` [PATCH 3/4] Use new lineread implementation for procfs_scan_listen() David Gibson
2022-06-17  3:10 ` David Gibson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220617031026.498690-5-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).