From: Simon Marchi Date: Thu, 25 Apr 2024 15:10:55 +0000 (+0000) Subject: cpp-common/bt2c: make `dataFromFile()` take a `CStringView` X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=306722ab67d75c487c5aa83ba6494ef42943c0d2;p=babeltrace.git cpp-common/bt2c: make `dataFromFile()` take a `CStringView` Make it easier to pass an `std::string` to `dataFromFile()`. Change-Id: I0af7d913362e67b69c1f479e3be8024d9337b9d6 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/12739 Reviewed-by: Philippe Proulx Tested-by: jenkins --- diff --git a/src/cpp-common/bt2c/file-utils.cpp b/src/cpp-common/bt2c/file-utils.cpp index de5e3e19..45d84bee 100644 --- a/src/cpp-common/bt2c/file-utils.cpp +++ b/src/cpp-common/bt2c/file-utils.cpp @@ -13,14 +13,14 @@ namespace bt2c { -std::vector dataFromFile(const char * const filePath, const Logger& logger, +std::vector dataFromFile(const CStringView filePath, const Logger& logger, const bool fatalError) { /* * Open a file stream and seek to the end of the stream to compute the size * of the buffer required. */ - std::ifstream file {filePath, std::ios::binary | std::ios::ate}; + std::ifstream file {filePath.data(), std::ios::binary | std::ios::ate}; if (!file) { constexpr const char *msg = "No such file or directory: path=\"{}\""; diff --git a/src/cpp-common/bt2c/file-utils.hpp b/src/cpp-common/bt2c/file-utils.hpp index 9193d12e..fd290f9e 100644 --- a/src/cpp-common/bt2c/file-utils.hpp +++ b/src/cpp-common/bt2c/file-utils.hpp @@ -10,6 +10,8 @@ #include #include +#include "c-string-view.hpp" + namespace bt2c { class Logger; @@ -22,7 +24,8 @@ class Logger; * If `fatalError` is true, log an error and appends an error * cause prior to throwing. Otherwise, log at the debug level. */ -std::vector dataFromFile(const char *path, const Logger& logger, bool fatalError); +std::vector dataFromFile(const CStringView path, const Logger& logger, + bool fatalError); } /* namespace bt2c */