Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 01 Mar 2026 16:36:29 +0000
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Cc:        Faraz Vahedi <kfv@kfv.io>
Subject:   git: 4ba5c9d015f0 - main - paste(1): Utilise STAILQ from <sys/queue.h> in lieu of the home-rolled linked-list
Message-ID:  <69a46b0d.3a5ab.5275dbf3@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=4ba5c9d015f02eb1fda30de26c23690dd41731fc

commit 4ba5c9d015f02eb1fda30de26c23690dd41731fc
Author:     Faraz Vahedi <kfv@kfv.io>
AuthorDate: 2024-10-08 09:41:42 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-03-01 16:36:15 +0000

    paste(1): Utilise STAILQ from <sys/queue.h> in lieu of the home-rolled linked-list
    
    Signed-off-by: Faraz Vahedi <kfv@kfv.io>
    Reviewed by: imp, oshogbo
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1443
---
 usr.bin/paste/paste.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/usr.bin/paste/paste.c b/usr.bin/paste/paste.c
index 8114a85a869a..fa8be54ebe53 100644
--- a/usr.bin/paste/paste.c
+++ b/usr.bin/paste/paste.c
@@ -33,6 +33,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/queue.h>
 
 #include <err.h>
 #include <errno.h>
@@ -106,43 +107,43 @@ main(int argc, char *argv[])
 }
 
 typedef struct _list {
-	struct _list *next;
+	STAILQ_ENTRY(_list) entries;
 	FILE *fp;
 	int cnt;
 	char *name;
 } LIST;
 
+static STAILQ_HEAD(head, _list) lh;
+
 static int
 parallel(char **argv)
 {
+	struct head lh;
 	LIST *lp;
 	int cnt;
 	wint_t ich;
 	wchar_t ch;
 	char *p;
-	LIST *head, *tmp;
 	int opencnt, output;
 
-	for (cnt = 0, head = tmp = NULL; (p = *argv); ++argv, ++cnt) {
+	STAILQ_INIT(&lh);
+
+	for (cnt = 0; (p = *argv); ++argv, ++cnt) {
 		if ((lp = malloc(sizeof(LIST))) == NULL)
 			err(1, NULL);
 		if (p[0] == '-' && !p[1])
 			lp->fp = stdin;
 		else if (!(lp->fp = fopen(p, "r")))
 			err(1, "%s", p);
-		lp->next = NULL;
 		lp->cnt = cnt;
 		lp->name = p;
-		if (!head)
-			head = tmp = lp;
-		else {
-			tmp->next = lp;
-			tmp = lp;
-		}
+
+		STAILQ_INSERT_TAIL(&lh, lp, entries);
 	}
 
 	for (opencnt = cnt; opencnt;) {
-		for (output = 0, lp = head; lp; lp = lp->next) {
+		output = 0;
+		STAILQ_FOREACH(lp, &lh, entries) {
 			if (!lp->fp) {
 				if (output && lp->cnt &&
 				    (ch = delim[(lp->cnt - 1) % delimcnt]))


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69a46b0d.3a5ab.5275dbf3>