cpp-common/bt2c: make `dataFromFile()` take a `CStringView`
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 25 Apr 2024 15:10:55 +0000 (15:10 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
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>
src/cpp-common/bt2c/file-utils.cpp
src/cpp-common/bt2c/file-utils.hpp

index de5e3e194e499876cf4b4ebc447d9c0fdf75b2ac..45d84bee8009ee06d06974c9de26f8af30ca7f13 100644 (file)
 
 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=\"{}\"";
index 9193d12e68e83053a4ecb168453d37dbe1210230..fd290f9ee548cce0c4c8f6c3c2fc4f437277ae1a 100644 (file)
@@ -10,6 +10,8 @@
 #include <cstdint>
 #include <vector>
 
+#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<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 */
 
This page took 0.025057 seconds and 4 git commands to generate.