diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2019-11-04 09:35:44 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2019-11-04 09:35:44 +0000 |
commit | 6470286cfeebe1b3f14de8fa43679eba933f36ee (patch) | |
tree | d5eb6e283ea96a72dd30794fffcc0e044c708bbe /usr.sbin/rpki-client/main.c | |
parent | 2617806ff8aff056898aa218179735eda80d8276 (diff) |
Refactor tal code a bit. Move the file reader back into tal.c so that the
regress test is able to use it.
OK deraadt@
Diffstat (limited to 'usr.sbin/rpki-client/main.c')
-rw-r--r-- | usr.sbin/rpki-client/main.c | 55 |
1 files changed, 3 insertions, 52 deletions
diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 95b30b6b861..4fd5b5cefe8 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.21 2019/10/31 08:36:43 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.22 2019/11/04 09:35:43 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -22,7 +22,6 @@ #include <sys/wait.h> #include <assert.h> -#include <ctype.h> #include <err.h> #include <dirent.h> #include <fcntl.h> @@ -463,59 +462,11 @@ queue_add_from_mft_set(int fd, struct entityq *q, const struct mft *mft, static void queue_add_tal(int fd, struct entityq *q, const char *file, size_t *eid) { - char *nfile, *nbuf, *line = NULL, *buf = NULL; - FILE *in; - ssize_t n, i; - size_t sz = 0, bsz = 0; - int optcomment = 1; - - if ((in = fopen(file, "r")) == NULL) - err(EXIT_FAILURE, "fopen: %s", file); - - while ((n = getline(&line, &sz, in)) != -1) { - /* replace CRLF with just LF */ - if (n > 1 && line[n - 1] == '\n' && line[n - 2] == '\r') { - line[n - 2] = '\n'; - line[n - 1] = '\0'; - n--; - } - if (optcomment) { - /* if this is comment, just eat the line */ - if (line[0] == '#') - continue; - optcomment = 0; - /* - * Empty line is end of section and needs - * to be eaten as well. - */ - if (line[0] == '\n') - continue; - } - - /* make sure every line is valid ascii */ - for (i = 0; i < n; i++) - if (!isprint(line[i]) && !isspace(line[i])) - errx(EXIT_FAILURE, "getline: %s: " - "invalid content", file); - - /* concat line to buf */ - if ((nbuf = realloc(buf, bsz + n + 1)) == NULL) - err(EXIT_FAILURE, NULL); - buf = nbuf; - bsz += n + 1; - strlcat(buf, line, bsz); - /* limit the buffer size */ - if (bsz > 4096) - errx(EXIT_FAILURE, "%s: file too big", file); - } - - free(line); - if (ferror(in)) - err(EXIT_FAILURE, "getline: %s", file); - fclose(in); + char *nfile, *buf; if ((nfile = strdup(file)) == NULL) err(EXIT_FAILURE, "strdup"); + buf = tal_read_file(file); /* Not in a repository, so directly add to queue. */ entityq_add(fd, q, nfile, RTYPE_TAL, NULL, NULL, NULL, 0, buf, eid); |