From 07d8c0eb1e037b7be16e9065a4bce784d7abf372 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 8 Apr 2019 23:40:22 +0900 Subject: [PATCH] fileio: add READ_FULL_FILE_UNBASE64 flag for read_full_file_full() --- src/basic/fileio.c | 8 ++++++++ src/basic/fileio.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 78928979e9..9ab2f501c7 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -17,6 +17,7 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "hexdecoct.h" #include "log.h" #include "macro.h" #include "missing.h" @@ -278,6 +279,7 @@ int read_full_stream_full( assert(f); assert(ret_contents); + assert(!(flags & READ_FULL_FILE_UNBASE64) || ret_size); n_next = LINE_MAX; /* Start size */ @@ -354,6 +356,12 @@ int read_full_stream_full( n_next = MIN(n * 2, READ_FULL_BYTES_MAX); } + if (flags & READ_FULL_FILE_UNBASE64) { + buf[l++] = 0; + r = unbase64mem_full(buf, l, flags & READ_FULL_FILE_SECURE, (void **) ret_contents, ret_size); + goto finalize; + } + if (!ret_size) { /* Safety check: if the caller doesn't want to know the size of what we just read it will rely on the * trailing NUL byte. But if there's an embedded NUL byte, then we should refuse operation as otherwise diff --git a/src/basic/fileio.h b/src/basic/fileio.h index 6add67750a..760e738688 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -29,7 +29,8 @@ typedef enum { } WriteStringFileFlags; typedef enum { - READ_FULL_FILE_SECURE = 1 << 0, + READ_FULL_FILE_SECURE = 1 << 0, + READ_FULL_FILE_UNBASE64 = 1 << 1, } ReadFullFileFlags; int write_string_stream_ts(FILE *f, const char *line, WriteStringFileFlags flags, struct timespec *ts);