tee: use queue(9) in place of a custom linked list

Approved by: cognet
This commit is contained in:
Pietro Cerutti 2021-09-15 11:04:24 +00:00
parent 1896a00943
commit 41ba691f92

View file

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