summaryrefslogtreecommitdiff
path: root/usr.bin/tee
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2017-07-11 13:15:00 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2017-07-11 13:15:00 +0000
commitb88d98efefcfbb7026342162785b7b08fe407cb9 (patch)
tree7d5a5a3aec74e2b9aeb1f40adb6330f0ce068689 /usr.bin/tee
parent9ce6653c63e9f74d41dbfd3a9b587061713452ef (diff)
Replace manual list with SLIST.
from Klemens Nanni
Diffstat (limited to 'usr.bin/tee')
-rw-r--r--usr.bin/tee/tee.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/usr.bin/tee/tee.c b/usr.bin/tee/tee.c
index d5e4767e498..f0cd6f2daba 100644
--- a/usr.bin/tee/tee.c
+++ b/usr.bin/tee/tee.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tee.c,v 1.11 2016/10/28 07:22:59 schwarze Exp $ */
+/* $OpenBSD: tee.c,v 1.12 2017/07/11 13:14:59 bluhm Exp $ */
/* $NetBSD: tee.c,v 1.5 1994/12/09 01:43:39 jtc Exp $ */
/*
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/queue.h>
#include <err.h>
#include <errno.h>
@@ -43,11 +44,11 @@
#include <unistd.h>
struct list {
- struct list *next;
+ SLIST_ENTRY(list) next;
int fd;
char *name;
};
-struct list *head;
+SLIST_HEAD(, list) head;
static void
add(int fd, char *name)
@@ -58,8 +59,7 @@ add(int fd, char *name)
err(1, NULL);
p->fd = fd;
p->name = name;
- p->next = head;
- head = p;
+ SLIST_INSERT_HEAD(&head, p, next);
}
int
@@ -75,6 +75,8 @@ main(int argc, char *argv[])
if (pledge("stdio wpath cpath", NULL) == -1)
err(1, "pledge");
+ SLIST_INIT(&head);
+
append = 0;
while ((ch = getopt(argc, argv, "ai")) != -1) {
switch(ch) {
@@ -109,7 +111,7 @@ main(int argc, char *argv[])
err(1, "pledge");
while ((rval = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
- for (p = head; p; p = p->next) {
+ SLIST_FOREACH(p, &head, next) {
n = rval;
bp = buf;
do {
@@ -127,7 +129,7 @@ main(int argc, char *argv[])
exitval = 1;
}
- for (p = head; p; p = p->next) {
+ SLIST_FOREACH(p, &head, next) {
if (close(p->fd) == -1) {
warn("%s", p->name);
exitval = 1;