Storage::getCname() to get a char*.
XBT
+ - Define class simgrid::xbt::Path to manage file names.
- Removed unused functions:
- xbt/file.h: xbt_getline()
--- /dev/null
+/* Copyright (c) 2017. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef XBT_FILE_HPP
+#define XBT_FILE_HPP
+
+#include <string>
+#include <xbt/base.h>
+
+namespace simgrid {
+namespace xbt {
+
+class Path {
+public:
+ explicit Path(const char* path): path_(path) {}
+ explicit Path(std::string path): path_(std::move(path)) {}
+
+ /** @brief Returns the full path name */
+ std::string getName() { return path_; }
+ /** @brief Returns the directory component of a path (reimplementation of POSIX dirname) */
+ std::string getDirname();
+ /** @brief Returns the file component of a path (reimplementation of POSIX basename) */
+ std::string getBasename();
+
+private:
+ std::string path_;
+};
+}}
+
+#endif /* XBT_FILE_HPP */
+++ /dev/null
-/* xbt_os_file.c -- portable interface to file-related functions */
-
-/* Copyright (c) 2007-2010, 2012-2017. The SimGrid Team.
- * All rights reserved. */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "xbt/sysdep.h"
-#include "xbt/file.h" /* this module */
-#include "xbt/log.h"
-#include "src/internal_config.h"
-
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
-#include "libgen.h" /* POSIX dirname */
-
-/** @brief Returns the directory component of a path (reimplementation of POSIX dirname)
- *
- * The argument is never modified, and the returned value must be freed after use.
- */
-char *xbt_dirname(const char *path) {
- char *tmp = xbt_strdup(path);
- char *res = xbt_strdup(dirname(tmp));
- free(tmp);
- return res;
-}
-
-/** @brief Returns the file component of a path (reimplementation of POSIX basename)
- *
- * The argument is never modified, and the returned value must be freed after use.
- */
-char *xbt_basename(const char *path) {
- char *tmp = xbt_strdup(path);
- char *res = xbt_strdup(basename(tmp));
- free(tmp);
- return res;
-}
--- /dev/null
+/* xbt_os_file.cpp -- portable interface to file-related functions */
+
+/* Copyright (c) 2017. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "xbt/file.hpp" /* this module */
+
+#include "xbt/file.h"
+#include "xbt/sysdep.h"
+
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#include <cstring>
+#include <libgen.h> /* POSIX dirname */
+
+/** @brief Returns the directory component of a path (reimplementation of POSIX dirname)
+ *
+ * The argument is never modified, and the returned value must be freed after use.
+ */
+char *xbt_dirname(const char *path)
+{
+ return xbt_strdup(simgrid::xbt::Path(path).getDirname().c_str());
+}
+
+/** @brief Returns the file component of a path (reimplementation of POSIX basename)
+ *
+ * The argument is never modified, and the returned value must be freed after use.
+ */
+char *xbt_basename(const char *path)
+{
+ return xbt_strdup(simgrid::xbt::Path(path).getBasename().c_str());
+}
+
+std::string simgrid::xbt::Path::getDirname()
+{
+ std::string p(path_);
+ char *res = dirname(&p[0]);
+ return std::string(res, strlen(res));
+}
+
+std::string simgrid::xbt::Path::getBasename()
+{
+ std::string p(path_);
+ char *res = basename(&p[0]);
+ return std::string(res, strlen(res));
+}
src/xbt/xbt_log_layout_format.c
src/xbt/xbt_log_layout_simple.c
src/xbt/xbt_main.cpp
- src/xbt/xbt_os_file.c
+ src/xbt/xbt_os_file.cpp
src/xbt/xbt_os_synchro.cpp
src/xbt/xbt_os_time.c
src/xbt/xbt_replay.cpp
include/xbt/exception.hpp
include/xbt/Extendable.hpp
include/xbt/file.h
+ include/xbt/file.hpp
include/xbt/functional.hpp
include/xbt/function_types.h
include/xbt/future.hpp