Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove Java bindings. They are not updated since maybe 10 years
[simgrid.git] / src / xbt / xbt_os_file.cpp
1 /* xbt_os_file.cpp -- portable interface to file-related functions          */
2
3 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved.          */
4
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. */
7
8 #include "src/internal_config.h"
9 #include "xbt/asserts.h"
10 #include "xbt/file.hpp" /* this module */
11
12 #if HAVE_UNISTD_H
13 #include <array>
14 #include <cerrno>
15 #include <unistd.h>
16 #endif
17
18 #include <cstring>
19 #include <libgen.h> /* POSIX dirname */
20
21 simgrid::xbt::Path::Path()
22 {
23 #if HAVE_UNISTD_H
24   std::array<char, 2048> buffer;
25   const char* cwd = getcwd(buffer.data(), 2048);
26   xbt_assert(cwd != nullptr, "Error during getcwd: %s", strerror(errno));
27   path_ = cwd;
28 #else
29   path_ = ".";
30 #endif
31 }
32
33 std::string simgrid::xbt::Path::get_dir_name() const
34 {
35   std::string p(path_);
36   return dirname(&p[0]);
37 }
38
39 std::string simgrid::xbt::Path::get_base_name() const
40 {
41   std::string p(path_);
42   return basename(&p[0]);
43 }