util: add new write_string_filef() helper

This new helper combines asprintf() and write_string_file() in one,
which is useful at various places to shorten the code a bit.
This commit is contained in:
Lennart Poettering
2018-06-06 14:39:15 +02:00
parent 9264cc39ce
commit 3130fca5a7
4 changed files with 30 additions and 22 deletions
+19
View File
@@ -206,6 +206,25 @@ fail:
return 0;
}
int write_string_filef(
const char *fn,
WriteStringFileFlags flags,
const char *format, ...) {
_cleanup_free_ char *p = NULL;
va_list ap;
int r;
va_start(ap, format);
r = vasprintf(&p, format, ap);
va_end(ap);
if (r < 0)
return -ENOMEM;
return write_string_file(fn, p, flags);
}
int read_one_line_file(const char *fn, char **line) {
_cleanup_fclose_ FILE *f = NULL;
int r;