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