Replace usage of fparselen(3) by a getline(3)

This allow to remove the dependency on libutil
This commit is contained in:
Baptiste Daroussin 2017-12-14 08:57:37 +00:00
parent 0bffd21750
commit b37b09244c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=326844
3 changed files with 13 additions and 10 deletions

View File

@ -5,8 +5,6 @@
.if ${MK_MAILWRAPPER} != "no" .if ${MK_MAILWRAPPER} != "no"
PROG= mailwrapper PROG= mailwrapper
MAN= mailwrapper.8 MAN= mailwrapper.8
LIBADD= util
.endif .endif
.if ${MK_MAILWRAPPER} != "no" || ${MK_SENDMAIL} != "no" .if ${MK_MAILWRAPPER} != "no" || ${MK_SENDMAIL} != "no"

View File

@ -7,8 +7,7 @@ DIRDEPS = \
include/xlocale \ include/xlocale \
lib/${CSU_DIR} \ lib/${CSU_DIR} \
lib/libc \ lib/libc \
lib/libcompiler_rt \ lib/libcompiler_rt
lib/libutil \
.include <dirdeps.mk> .include <dirdeps.mk>

View File

@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$");
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <libutil.h>
#include <sysexits.h> #include <sysexits.h>
#include <syslog.h> #include <syslog.h>
@ -89,14 +88,17 @@ int
main(int argc, char *argv[], char *envp[]) main(int argc, char *argv[], char *envp[])
{ {
FILE *config; FILE *config;
char *line, *cp, *from, *to, *ap; char *line, *cp, *from, *to, *ap, *walk;
const char *progname; const char *progname;
char localmailerconf[MAXPATHLEN]; char localmailerconf[MAXPATHLEN];
const char *mailerconf; const char *mailerconf;
size_t len, lineno = 0; size_t linecap = 0, lineno = 0;
ssize_t linelen;
int i; int i;
struct arglist al; struct arglist al;
line = NULL;
/* change __progname to mailwrapper so we get sensible error messages */ /* change __progname to mailwrapper so we get sensible error messages */
progname = getprogname(); progname = getprogname();
setprogname("mailwrapper"); setprogname("mailwrapper");
@ -123,12 +125,16 @@ main(int argc, char *argv[], char *envp[])
} }
for (;;) { for (;;) {
if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) { if ((linelen = getline(&line, &linecap, config)) <= 0) {
if (feof(config)) if (feof(config)) {
errx(EX_CONFIG, "no mapping in %s", mailerconf); errx(EX_CONFIG, "no mapping in %s", mailerconf);
}
err(EX_CONFIG, "cannot parse line %lu", (u_long)lineno); err(EX_CONFIG, "cannot parse line %lu", (u_long)lineno);
} }
lineno++;
walk = line;
/* strip comments */
strsep(&walk, "#");
#define WS " \t\n" #define WS " \t\n"
cp = line; cp = line;