serialize: add serialize_item_hexmem()

This commit is contained in:
Luca Boccassi
2023-10-12 13:37:22 +01:00
parent b646fc324a
commit 3f12c5ff2e
3 changed files with 42 additions and 0 deletions
+23
View File
@@ -7,6 +7,7 @@
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "hexdecoct.h"
#include "memfd-util.h"
#include "missing_mman.h"
#include "missing_syscall.h"
@@ -173,6 +174,28 @@ int serialize_pidref(FILE *f, FDSet *fds, const char *key, PidRef *pidref) {
return serialize_item_format(f, key, "@%i", copy);
}
int serialize_item_hexmem(FILE *f, const char *key, const void *p, size_t l) {
_cleanup_free_ char *encoded = NULL;
int r;
assert(f);
assert(key);
assert(p || l == 0);
if (l == 0)
return 0;
encoded = hexmem(p, l);
if (!encoded)
return log_oom_debug();
r = serialize_item(f, key, encoded);
if (r < 0)
return r;
return 1;
}
int deserialize_read_line(FILE *f, char **ret) {
_cleanup_free_ char *line = NULL;
int r;
+1
View File
@@ -12,6 +12,7 @@
int serialize_item(FILE *f, const char *key, const char *value);
int serialize_item_escaped(FILE *f, const char *key, const char *value);
int serialize_item_format(FILE *f, const char *key, const char *value, ...) _printf_(3,4);
int serialize_item_hexmem(FILE *f, const char *key, const void *p, size_t l);
int serialize_fd(FILE *f, FDSet *fds, const char *key, int fd);
int serialize_usec(FILE *f, const char *key, usec_t usec);
int serialize_dual_timestamp(FILE *f, const char *key, const dual_timestamp *t);