openbsd-pkg.c - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
openbsd-pkg.c (843B)
---
1 #include <err.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6
7 struct pkgname {
8 char *name;
9 struct pkgname *next;
10 };
11
12 static struct pkgname *pkghead;
13 static struct pkgname *pkgcur;
14
15 int
16 main(void)
17 {
18 char *line = NULL;
19 size_t linesiz = 0;
20 ssize_t n;
21 struct pkgname *p;
22
23 if (pledge("stdio", NULL) == -1)
24 err(1, "pledge");
25
26 while ((n = getline(&line, &linesiz, stdin)) > 0) {
27 line[strcspn(line, "|\r\n")] = '\0';
28
29 /* TODO: strip p[0-9] suffix? */
30
31 if (!(p = calloc(1, sizeof(*pkgcur))))
32 err(1, "calloc");
33 if (pkghead) {
34 pkgcur->next = p;
35 pkgcur = pkgcur->next;
36 } else {
37 pkghead = pkgcur = p;
38 }
39 if (!(p->name = strdup(line)))
40 err(1, "strdup");
41 }
42 if (ferror(stdin))
43 err(1, "getline");
44
45 for (p = pkghead; p; p = p->next) {
46 printf("%s\n", p->name);
47 }
48
49 return 0;
50 }