fileio: rework read_one_line_file() on top of read_line()
This commit is contained in:
parent
189912440f
commit
f4b51a2d09
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "ctype.h"
|
#include "ctype.h"
|
||||||
|
#include "def.h"
|
||||||
#include "env-util.h"
|
#include "env-util.h"
|
||||||
#include "escape.h"
|
#include "escape.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
|
@ -177,7 +178,6 @@ fail:
|
||||||
|
|
||||||
int read_one_line_file(const char *fn, char **line) {
|
int read_one_line_file(const char *fn, char **line) {
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
char t[LINE_MAX], *c;
|
|
||||||
|
|
||||||
assert(fn);
|
assert(fn);
|
||||||
assert(line);
|
assert(line);
|
||||||
|
@ -186,21 +186,7 @@ int read_one_line_file(const char *fn, char **line) {
|
||||||
if (!f)
|
if (!f)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
if (!fgets(t, sizeof(t), f)) {
|
return read_line(f, LONG_LINE_MAX, line);
|
||||||
|
|
||||||
if (ferror(f))
|
|
||||||
return errno > 0 ? -errno : -EIO;
|
|
||||||
|
|
||||||
t[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = strdup(t);
|
|
||||||
if (!c)
|
|
||||||
return -ENOMEM;
|
|
||||||
truncate_nl(c);
|
|
||||||
|
|
||||||
*line = c;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
|
int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
|
||||||
|
|
Loading…
Reference in a new issue