1 /* xbt_os_file.cpp -- portable interface to file-related functions */
3 /* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "src/internal_config.h"
9 #include "xbt/asserts.h"
10 #include "xbt/file.hpp" /* this module */
23 #include <libgen.h> /* POSIX dirname */
25 simgrid::xbt::Path::Path()
28 std::array<char, 2048> buffer;
29 const char* cwd = getcwd(buffer.data(), 2048);
30 xbt_assert(cwd != nullptr, "Error during getcwd: %s", strerror(errno));
31 path_ = std::string(cwd);
33 path_ = std::string(".");
37 std::string simgrid::xbt::Path::get_dir_name() const
40 const char* res = dirname(&p[0]);
41 return std::string(res, strlen(res));
44 std::string simgrid::xbt::Path::get_base_name() const
47 const char* res = basename(&p[0]);
48 return std::string(res, strlen(res));