#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);