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