summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2016-05-09 20:04:22 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2016-05-09 20:04:22 +0000
commit8c98e6b1a7f32d70f05262c87a78a8ff008b7c3e (patch)
tree79bf49888cb12795586b015ed50c251fc1f67862
parentd3cd2df1f26bbf484fb71c576979df08d3fd8783 (diff)
downloadsrc-test2-8c98e6b1a7f32d70f05262c87a78a8ff008b7c3e.tar.gz
src-test2-8c98e6b1a7f32d70f05262c87a78a8ff008b7c3e.zip
Notes
-rw-r--r--usr.sbin/services_mkdb/Makefile2
-rw-r--r--usr.sbin/services_mkdb/services_mkdb.c16
2 files changed, 11 insertions, 7 deletions
diff --git a/usr.sbin/services_mkdb/Makefile b/usr.sbin/services_mkdb/Makefile
index 05a4b76bc271..74e892abda13 100644
--- a/usr.sbin/services_mkdb/Makefile
+++ b/usr.sbin/services_mkdb/Makefile
@@ -4,6 +4,4 @@ PROG= services_mkdb
MAN= services_mkdb.8
SRCS= services_mkdb.c uniq.c extern.h
-LIBADD= util
-
.include <bsd.prog.mk>
diff --git a/usr.sbin/services_mkdb/services_mkdb.c b/usr.sbin/services_mkdb/services_mkdb.c
index c928ea995837..fe23355d3e1b 100644
--- a/usr.sbin/services_mkdb/services_mkdb.c
+++ b/usr.sbin/services_mkdb/services_mkdb.c
@@ -40,12 +40,12 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <fcntl.h>
#include <netdb.h>
+#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
-#include <libutil.h>
#include <ctype.h>
#include <errno.h>
#include <stringlist.h>
@@ -235,7 +235,8 @@ add(DB *db, StringList *sl, size_t port, const char *proto, size_t *cnt,
static StringList ***
parseservices(const char *fname, StringList *sl)
{
- size_t len, line, pindex;
+ ssize_t len;
+ size_t linecap, line, pindex;
FILE *fp;
StringList ***svc, *s;
char *p, *ep;
@@ -243,18 +244,23 @@ parseservices(const char *fname, StringList *sl)
if ((fp = fopen(fname, "r")) == NULL)
err(1, "Cannot open `%s'", fname);
- line = 0;
+ line = linecap = 0;
if ((svc = calloc(PMASK + 1, sizeof(StringList **))) == NULL)
err(1, "Cannot allocate %zu bytes", (size_t)(PMASK + 1));
- /* XXX: change NULL to "\0\0#" when fparseln fixed */
- for (; (p = fparseln(fp, &len, &line, NULL, 0)) != NULL; free(p)) {
+ p = NULL;
+ while ((len = getline(&p, &linecap, fp)) != -1) {
char *name, *port, *proto, *aliases, *cp, *alias;
unsigned long pnum;
+ line++;
+
if (len == 0)
continue;
+ if (p[len - 1] == '\n')
+ p[len - 1] = '\0';
+
for (cp = p; *cp && isspace((unsigned char)*cp); cp++)
continue;