mirror of
https://github.com/systemd/systemd.git
synced 2025-03-14 04:58:28 +03:00
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 "ctype.h"
|
||||
#include "def.h"
|
||||
#include "env-util.h"
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
@ -177,7 +178,6 @@ fail:
|
||||
|
||||
int read_one_line_file(const char *fn, char **line) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
char t[LINE_MAX], *c;
|
||||
|
||||
assert(fn);
|
||||
assert(line);
|
||||
@ -186,21 +186,7 @@ int read_one_line_file(const char *fn, char **line) {
|
||||
if (!f)
|
||||
return -errno;
|
||||
|
||||
if (!fgets(t, sizeof(t), f)) {
|
||||
|
||||
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;
|
||||
return read_line(f, LONG_LINE_MAX, line);
|
||||
}
|
||||
|
||||
int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user