dd65c9
From aab6aeb2529a1e9b51eeadf91decd06e03af5da1 Mon Sep 17 00:00:00 2001
dd65c9
From: Jan Synacek <jsynacek@redhat.com>
dd65c9
Date: Thu, 23 Nov 2017 09:23:34 +0100
dd65c9
Subject: [PATCH] fileio: rework read_one_line_file() on top of read_line()
dd65c9
dd65c9
(cherry picked from commit f4b51a2d092685c9a080e84130fec2d74c834f5c)
dd65c9
dd65c9
Resolves: #1503106
dd65c9
---
dd65c9
 src/shared/fileio.c | 18 ++----------------
dd65c9
 1 file changed, 2 insertions(+), 16 deletions(-)
dd65c9
dd65c9
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
dd65c9
index 107737573..be775f982 100644
dd65c9
--- a/src/shared/fileio.c
dd65c9
+++ b/src/shared/fileio.c
dd65c9
@@ -25,6 +25,7 @@
dd65c9
 #include "strv.h"
dd65c9
 #include "utf8.h"
dd65c9
 #include "ctype.h"
dd65c9
+#include "def.h"
dd65c9
 #include "fileio.h"
dd65c9
 
dd65c9
 int write_string_stream(FILE *f, const char *line) {
dd65c9
@@ -108,7 +109,6 @@ int write_string_file_atomic(const char *fn, const char *line) {
dd65c9
 
dd65c9
 int read_one_line_file(const char *fn, char **line) {
dd65c9
         _cleanup_fclose_ FILE *f = NULL;
dd65c9
-        char t[LINE_MAX], *c;
dd65c9
 
dd65c9
         assert(fn);
dd65c9
         assert(line);
dd65c9
@@ -117,21 +117,7 @@ int read_one_line_file(const char *fn, char **line) {
dd65c9
         if (!f)
dd65c9
                 return -errno;
dd65c9
 
dd65c9
-        if (!fgets(t, sizeof(t), f)) {
dd65c9
-
dd65c9
-                if (ferror(f))
dd65c9
-                        return errno ? -errno : -EIO;
dd65c9
-
dd65c9
-                t[0] = 0;
dd65c9
-        }
dd65c9
-
dd65c9
-        c = strdup(t);
dd65c9
-        if (!c)
dd65c9
-                return -ENOMEM;
dd65c9
-        truncate_nl(c);
dd65c9
-
dd65c9
-        *line = c;
dd65c9
-        return 0;
dd65c9
+        return read_line(f, LONG_LINE_MAX, line);
dd65c9
 }
dd65c9
 
dd65c9
 int read_full_stream(FILE *f, char **contents, size_t *size) {