diff --git a/usr.bin/tee/tee.c b/usr.bin/tee/tee.c index b55aa84d2f6..bc338e14bd6 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 +#include #include #include @@ -57,12 +58,12 @@ static const char rcsid[] = #include #include -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); }