From 6fd33254e60d7e287fc5733f95a6b35dd8c5ff7d Mon Sep 17 00:00:00 2001 From: Vee Satayamas <5ssgdxltv@relay.firefox.com> Date: Sat, 28 Oct 2023 00:15:31 +0700 Subject: [PATCH] Add InputFile::open_in_memory (#178) --- configure.ac | 2 +- lttoolbox/input_file.cc | 8 ++++++++ lttoolbox/input_file.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index cd691dcf..ac56f882 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ(2.52) m4_define([PKG_VERSION_MAJOR], [3]) m4_define([PKG_VERSION_MINOR], [7]) -m4_define([PKG_VERSION_PATCH], [4]) +m4_define([PKG_VERSION_PATCH], [5]) # Bump if the ABI (not API) changed in a backwards-incompatible manner m4_define([PKG_VERSION_ABI], [3]) diff --git a/lttoolbox/input_file.cc b/lttoolbox/input_file.cc index cddb8101..b10d4184 100644 --- a/lttoolbox/input_file.cc +++ b/lttoolbox/input_file.cc @@ -44,6 +44,14 @@ InputFile::open(const char* fname) return (infile != nullptr); } +bool +InputFile::open_in_memory(char *input_buffer) +{ + close(); + infile = fmemopen(input_buffer, strlen(input_buffer), "rb"); + return (infile != nullptr); +} + void InputFile::open_or_exit(const char* fname) { diff --git a/lttoolbox/input_file.h b/lttoolbox/input_file.h index dffcf7fd..7925ad4b 100644 --- a/lttoolbox/input_file.h +++ b/lttoolbox/input_file.h @@ -34,6 +34,7 @@ class InputFile InputFile(); ~InputFile(); bool open(const char* fname = nullptr); + bool open_in_memory(char* input_buffer); void open_or_exit(const char* fname = nullptr); void close(); void wrap(FILE* newinfile);