1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

Replace manual list with SLIST.

from Klemens Nanni
This commit is contained in:
bluhm 2017-07-11 13:14:59 +00:00
parent 768fe98d9b
commit 3aad691af2

View File

@ -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;