Date: Wed, 15 Sep 2021 11:04:35 GMT From: Pietro Cerutti <gahr@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 41ba691f9209 - main - tee: use queue(9) in place of a custom linked list Message-ID: <202109151104.18FB4Zvg086662@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by gahr (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=41ba691f9209c37cb245c8d2df0f312e8dc855bd commit 41ba691f9209c37cb245c8d2df0f312e8dc855bd Author: Pietro Cerutti <gahr@FreeBSD.org> AuthorDate: 2021-09-15 11:04:24 +0000 Commit: Pietro Cerutti <gahr@FreeBSD.org> CommitDate: 2021-09-15 11:04:24 +0000 tee: use queue(9) in place of a custom linked list Approved by: cognet --- usr.bin/tee/tee.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/usr.bin/tee/tee.c b/usr.bin/tee/tee.c index b55aa84d2f63..bc338e14bd66 100644 --- a/usr.bin/tee/tee.c +++ b/usr.bin/tee/tee.c @@ -44,6 +44,7 @@ static const char rcsid[] = #endif /* not lint */ #include <sys/capsicum.h> +#include <sys/queue.h> #include <sys/stat.h> #include <sys/types.h> @@ -57,12 +58,12 @@ static const char rcsid[] = #include <string.h> #include <unistd.h> -typedef struct _list { - struct _list *next; +struct entry { int fd; const char *name; -} LIST; -static LIST *head; + STAILQ_ENTRY(entry) entries; +}; +static STAILQ_HEAD(, entry) head = STAILQ_HEAD_INITIALIZER(head); static void add(int, const char *); static void usage(void); @@ -70,7 +71,7 @@ static void usage(void); int main(int argc, char *argv[]) { - LIST *p; + struct entry *p; int n, fd, rval, wval; char *bp; int append, ch, exitval; @@ -112,7 +113,7 @@ main(int argc, char *argv[]) if (caph_enter() < 0) err(EXIT_FAILURE, "unable to enter capability mode"); while ((rval = read(STDIN_FILENO, buf, BSIZE)) > 0) - for (p = head; p; p = p->next) { + STAILQ_FOREACH(p, &head, entries) { n = rval; bp = buf; do { @@ -139,7 +140,7 @@ usage(void) static void add(int fd, const char *name) { - LIST *p; + struct entry *p; cap_rights_t rights; if (fd == STDOUT_FILENO) { @@ -151,10 +152,9 @@ add(int fd, const char *name) err(EXIT_FAILURE, "unable to limit rights"); } - if ((p = malloc(sizeof(LIST))) == NULL) + if ((p = malloc(sizeof(struct entry))) == NULL) err(1, "malloc"); p->fd = fd; p->name = name; - p->next = head; - head = p; + STAILQ_INSERT_HEAD(&head, p, entries); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109151104.18FB4Zvg086662>