aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaraz Vahedi <kfv@kfv.io>2024-10-08 09:41:42 +0000
committerWarner Losh <imp@FreeBSD.org>2026-03-01 16:36:15 +0000
commit4ba5c9d015f02eb1fda30de26c23690dd41731fc (patch)
tree064721340b0c078a2938f0b9f27f26d2448147b3
parent5ddfd1db271cc675997a942da599c342ccb53afa (diff)
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
-rw-r--r--usr.bin/paste/paste.c23
1 files 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]))