mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 08:56:15 +09:00
fileio: add new helper write_base64_file_at() which encodes a binary object into base64 and writes it to a file
This commit is contained in:
committed by
Luca Boccassi
parent
73fade298a
commit
dc163cd40b
@@ -355,6 +355,22 @@ int write_string_filef(
|
||||
return write_string_file(fn, p, flags);
|
||||
}
|
||||
|
||||
int write_base64_file_at(
|
||||
int dir_fd,
|
||||
const char *fn,
|
||||
const struct iovec *data,
|
||||
WriteStringFileFlags flags) {
|
||||
|
||||
_cleanup_free_ char *encoded = NULL;
|
||||
ssize_t n;
|
||||
|
||||
n = base64mem_full(data ? data->iov_base : NULL, data ? data->iov_len : 0, 79, &encoded);
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
||||
return write_string_file_at(dir_fd, fn, encoded, flags);
|
||||
}
|
||||
|
||||
int read_one_line_file_at(int dir_fd, const char *filename, char **ret) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
int r;
|
||||
|
||||
@@ -66,6 +66,8 @@ static inline int write_string_file(const char *fn, const char *line, WriteStrin
|
||||
return write_string_file_ts(fn, line, flags, NULL);
|
||||
}
|
||||
|
||||
int write_base64_file_at(int dir_fd, const char *fn, const struct iovec *data, WriteStringFileFlags flags);
|
||||
|
||||
int write_string_filef(const char *fn, WriteStringFileFlags flags, const char *format, ...) _printf_(3, 4);
|
||||
|
||||
int read_one_line_file_at(int dir_fd, const char *filename, char **ret);
|
||||
|
||||
Reference in New Issue
Block a user