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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user