mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
fileio: split write_one_line_file into two
The new function allows one to write to an already open file.
This commit is contained in:
committed by
Lennart Poettering
parent
9494131b91
commit
b4bc041b17
@@ -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;
|
||||
|
||||
@@ -21,10 +21,14 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
int write_string_to_file(FILE *f, const char *line);
|
||||
int write_string_file(const char *fn, const char *line);
|
||||
int write_string_file_atomic(const char *fn, const char *line);
|
||||
|
||||
int read_one_line_file(const char *fn, char **line);
|
||||
int read_full_file(const char *fn, char **contents, size_t *size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user