Make it easier to pass an `std::string` to `dataFromFile()`.
Change-Id: I0af7d913362e67b69c1f479e3be8024d9337b9d6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12739
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
namespace bt2c {
-std::vector<std::uint8_t> dataFromFile(const char * const filePath, const Logger& logger,
+std::vector<std::uint8_t> 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=\"{}\"";
#include <cstdint>
#include <vector>
+#include "c-string-view.hpp"
+
namespace bt2c {
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<std::uint8_t> dataFromFile(const char *path, const Logger& logger, bool fatalError);
+std::vector<std::uint8_t> dataFromFile(const CStringView path, const Logger& logger,
+ bool fatalError);
} /* namespace bt2c */