From 805c5882c752092fbb09acac661628e808801b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 17 Mar 2013 15:13:08 -0400 Subject: [PATCH 1/2] fileio: split write_one_line_file into two The new function allows one to write to an already open file. --- src/shared/fileio.c | 24 ++++++++++++++---------- src/shared/fileio.h | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/shared/fileio.c b/src/shared/fileio.c index 0eca441..239cded 100644 --- a/src/shared/fileio.c +++ b/src/shared/fileio.c @@ -24,16 +24,7 @@ #include "util.h" #include "strv.h" -int write_one_line_file(const char *fn, const char *line) { - _cleanup_fclose_ FILE *f = NULL; - - assert(fn); - assert(line); - - f = fopen(fn, "we"); - if (!f) - return -errno; - +int write_one_line_to_file(FILE *f, const char *line) { errno = 0; if (fputs(line, f) < 0) return errno ? -errno : -EIO; @@ -49,6 +40,19 @@ int write_one_line_file(const char *fn, const char *line) { return 0; } +int write_one_line_file(const char *fn, const char *line) { + _cleanup_fclose_ FILE *f = NULL; + + assert(fn); + assert(line); + + f = fopen(fn, "we"); + if (!f) + return -errno; + + return write_one_line_to_file(f, line); +} + int write_one_line_file_atomic(const char *fn, const char *line) { _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *p = NULL; diff --git a/src/shared/fileio.h b/src/shared/fileio.h index 0023204..467a0b5 100644 --- a/src/shared/fileio.h +++ b/src/shared/fileio.h @@ -21,8 +21,10 @@ along with systemd; If not, see . ***/ #include +#include #include "macro.h" +int write_one_line_to_file(FILE *f, const char *line); int write_one_line_file(const char *fn, const char *line); int write_one_line_file_atomic(const char *fn, const char *line); int read_one_line_file(const char *fn, char **line); -- 1.8.1.4