summaryrefslogtreecommitdiff
path: root/src/shared/fileio.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-05-04 11:38:23 -0400
committerLennart Poettering <lennart@poettering.net>2013-05-06 22:51:47 +0200
commitb4bc041b1756aab117df40abdcc16a9dc2e72d07 (patch)
tree4fa67fc4df31bc5f41f0bef92cb38910f824ca7b /src/shared/fileio.c
parent9494131b91decc5300f9bbfa0568e64546d7917a (diff)
fileio: split write_one_line_file into two
The new function allows one to write to an already open file.
Diffstat (limited to 'src/shared/fileio.c')
-rw-r--r--src/shared/fileio.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index 48dd44239f..ad068bf30d 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -24,16 +24,8 @@
#include "util.h"
#include "strv.h"
-int write_string_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_string_to_file(FILE *f, const char *line) {
errno = 0;
fputs(line, f);
if (!endswith(line, "\n"))
@@ -47,6 +39,19 @@ int write_string_file(const char *fn, const char *line) {
return 0;
}
+int write_string_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_string_to_file(f, line);
+}
+
int write_string_file_atomic(const char *fn, const char *line) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;