diff options
author | Pietro Cerutti <gahr@FreeBSD.org> | 2021-09-15 11:04:24 +0000 |
---|---|---|
committer | Pietro Cerutti <gahr@FreeBSD.org> | 2021-09-15 11:04:24 +0000 |
commit | 41ba691f9209c37cb245c8d2df0f312e8dc855bd (patch) | |
tree | a129c9647c9ae0fa6e59aa67e264eecd4c368ab2 | |
parent | 1896a0094317c80d46beff5ad42b68215513c996 (diff) | |
download | src-41ba691f9209c37cb245c8d2df0f312e8dc855bd.tar.gz src-41ba691f9209c37cb245c8d2df0f312e8dc855bd.zip |
tee: use queue(9) in place of a custom linked list
Approved by: cognet
-rw-r--r-- | usr.bin/tee/tee.c | 20 |
1 files 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); } |