1 /* xbt_os_file.cpp -- portable interface to file-related functions */
3 /* Copyright (c) 2017. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/file.hpp" /* this module */
12 #include "xbt/sysdep.h"
19 #include <libgen.h> /* POSIX dirname */
21 /** @brief Returns the file component of a path (reimplementation of POSIX basename)
23 * The argument is never modified, and the returned value must be freed after use.
25 char *xbt_basename(const char *path)
27 return xbt_strdup(simgrid::xbt::Path(path).getBasename().c_str());
30 std::string simgrid::xbt::Path::getDirname()
33 char *res = dirname(&p[0]);
34 return std::string(res, strlen(res));
37 std::string simgrid::xbt::Path::getBasename()
40 char *res = basename(&p[0]);
41 return std::string(res, strlen(res));