Replace fparseln(3) with getline(3)

It removes a dependency on libutil.
This commit is contained in:
Baptiste Daroussin 2016-05-07 18:21:58 +00:00
parent 20b5f02214
commit 0c4ac56e16
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=299216
2 changed files with 11 additions and 9 deletions

View File

@ -6,7 +6,6 @@ PROG= sdiff
SRCS= common.c edit.c sdiff.c
WARNS= 3
LIBADD= util
MAN1= sdiff.1
.if ${MK_TESTS} != "no"

View File

@ -22,11 +22,11 @@ __FBSDID("$FreeBSD$");
#include <limits.h>
#include <paths.h>
#include <stdint.h>
#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libutil.h>
#include "common.h"
#include "extern.h"
@ -693,20 +693,23 @@ println(const char *s1, const char div, const char *s2)
static char *
xfgets(FILE *file)
{
const char delim[3] = {'\0', '\0', '\0'};
size_t linecap;
ssize_t l;
char *s;
/* XXX - Is this necessary? */
clearerr(file);
linecap = 0;
s = NULL;
if (!(s = fparseln(file, NULL, NULL, delim, 0)) &&
ferror(file))
err(2, "error reading file");
if (!s) {
if ((l = getline(&s, &linecap, file)) == -1) {
if (ferror(file))
err(2, "error reading file");
return (NULL);
}
if (s[l-1] == '\n')
s[l-1] = '\0';
return (s);
}