namespace simgrid {
namespace xbt {
-FILE* fopen_path(const std::string& name, const char* mode, const std::vector<std::string>& path);
-std::ifstream* ifsopen_path(const std::string& name, const std::vector<std::string>& path);
+void path_push(std::string const& str);
+void path_pop();
+FILE* path_fopen(const std::string& name, const char* mode);
+std::ifstream* path_ifsopen(const std::string& name);
+std::string path_to_string();
class Path {
public:
Profile* ProfileBuilder::from_file(const std::string& filename)
{
xbt_assert(not filename.empty(), "Cannot parse a trace from an empty filename");
- auto f = std::unique_ptr<std::ifstream>(simgrid::xbt::ifsopen_path(filename, surf_path));
- xbt_assert(not f->fail(), "Cannot open file '%s' (path=%s)", filename.c_str(), (boost::join(surf_path, ":")).c_str());
+ auto f = std::unique_ptr<std::ifstream>(simgrid::xbt::path_ifsopen(filename));
+ xbt_assert(not f->fail(), "Cannot open file '%s' (path=%s)", filename.c_str(),
+ simgrid::xbt::path_to_string().c_str());
std::stringstream buffer;
buffer << f->rdbuf();
auto* parse_content = new std::map<std::string, sg_size_t, std::less<>>();
- auto fs = std::unique_ptr<std::ifstream>(simgrid::xbt::ifsopen_path(filename, surf_path));
+ auto fs = std::unique_ptr<std::ifstream>(simgrid::xbt::path_ifsopen(filename));
xbt_assert(not fs->fail(), "Cannot open file '%s' (path=%s)", filename.c_str(),
- (boost::join(surf_path, ":")).c_str());
+ simgrid::xbt::path_to_string().c_str());
std::string line;
std::vector<std::string> tokens;
#include <simgrid/instr.h>
#include <simgrid/version.h>
#include <xbt/config.hpp>
+#include <xbt/file.hpp>
#include "simgrid/sg_config.hpp"
#include "src/include/xbt/mmalloc.h"
/* Inclusion path */
static simgrid::config::Flag<std::string> cfg_path{
- "path", "Lookup path for inclusions in platform and deployment XML files", "", [](std::string const& path) {
+ "path", "Lookup path for inclusions in platform and deployment XML files", "./", [](std::string const& path) {
if (not path.empty())
- surf_path.push_back(path);
+ simgrid::xbt::path_push(path);
}};
static simgrid::config::Flag<bool> cfg_cpu_maxmin_selective_update{
static simgrid::config::Flag<bool> cfg_execution_cutpath{
"exception/cutpath", "Whether to cut all path information from call traces, used e.g. in exceptions.", false};
- if (surf_path.empty())
- simgrid::config::set_default<std::string>("path", "./");
-
_sg_cfg_init_status = 1;
sg_config_cmd_line(argc, argv);
XBT_PUBLIC_DATA double sg_surf_precision;
XBT_PUBLIC_DATA int sg_concurrency_limit;
-extern XBT_PRIVATE std::vector<std::string> surf_path;
extern XBT_PRIVATE std::unordered_map<std::string, simgrid::kernel::profile::Profile*> traces_set_list;
/** set of hosts for which one want to be notified if they ever restart */
{
surf_parsed_filename = file;
std::string dir = simgrid::xbt::Path(file).get_dir_name();
- surf_path.push_back(dir);
+ simgrid::xbt::path_push(dir);
- surf_file_to_parse = simgrid::xbt::fopen_path(file, "r", surf_path);
+ surf_file_to_parse = simgrid::xbt::path_fopen(file, "r");
if (surf_file_to_parse == nullptr)
throw std::invalid_argument("Unable to open '" + file + "' from '" + simgrid::xbt::Path().get_name() +
"'. Does this file exist?");
void surf_parse_close()
{
- surf_path.pop_back(); // remove the dirname of the opened file, that was added in surf_parse_open()
+ simgrid::xbt::path_pop(); // remove the dirname of the opened file, that was added in surf_parse_open()
if (surf_file_to_parse) {
surf_parse__delete_buffer(surf_input_buffer);
#include <unistd.h>
#endif
+#include <boost/algorithm/string.hpp>
#include <cstring>
#include <fstream>
#include <libgen.h> /* POSIX dirname */
-FILE* simgrid::xbt::fopen_path(const std::string& name, const char* mode, const std::vector<std::string>& path)
+static std::vector<std::string> file_path;
+
+void simgrid::xbt::path_push(std::string const& str)
+{
+ file_path.push_back(str);
+}
+void simgrid::xbt::path_pop()
+{
+ file_path.pop_back();
+}
+std::string simgrid::xbt::path_to_string()
+{
+ return boost::join(file_path, ":");
+}
+FILE* simgrid::xbt::path_fopen(const std::string& name, const char* mode)
{
- if (name.c_str()[0] == '/') // don't mess with absolute file names
+ if (name[0] == '/') // don't mess with absolute file names
return fopen(name.c_str(), mode);
/* search relative files in the path */
- for (auto const& path_elm : path) {
+ for (auto const& path_elm : file_path) {
std::string buff = path_elm + "/" + name;
FILE* file = fopen(buff.c_str(), mode);
return nullptr;
}
-std::ifstream* simgrid::xbt::ifsopen_path(const std::string& name, const std::vector<std::string>& path)
+std::ifstream* simgrid::xbt::path_ifsopen(const std::string& name)
{
xbt_assert(not name.empty());
auto* fs = new std::ifstream();
- if (name.c_str()[0] == '/') // don't mess with absolute file names
+ if (name[0] == '/') // don't mess with absolute file names
fs->open(name.c_str(), std::ifstream::in);
/* search relative files in the path */
- for (auto const& path_elm : path) {
+ for (auto const& path_elm : file_path) {
std::string buff = path_elm + "/" + name;
fs->open(buff.c_str(), std::ifstream::in);