Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d7dbf02ffb56590cb8c24c5c77707763d27d5dc2
[simgrid.git] / src / xbt / xbt_os_file.c
1 /* xbt_os_file.c -- portable interface to file-related functions            */
2
3 /* Copyright (c) 2007-2010, 2012-2017. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #include "xbt/sysdep.h"
10 #include "xbt/file.h"    /* this module */
11 #include "xbt/log.h"
12 #include "src/internal_config.h"
13
14 #ifdef _WIN32
15 #include <windows.h>
16 #endif
17
18 #include "libgen.h" /* POSIX dirname */
19
20 /** @brief Returns the directory component of a path (reimplementation of POSIX dirname)
21  *
22  * The argument is never modified, and the returned value must be freed after use.
23  */
24 char *xbt_dirname(const char *path) {
25   char *tmp = xbt_strdup(path);
26   char *res = xbt_strdup(dirname(tmp));
27   free(tmp);
28   return res;
29 }
30
31 /** @brief Returns the file component of a path (reimplementation of POSIX basename)
32  *
33  * The argument is never modified, and the returned value must be freed after use.
34  */
35 char *xbt_basename(const char *path) {
36   char *tmp = xbt_strdup(path);
37   char *res = xbt_strdup(basename(tmp));
38   free(tmp);
39   return res;
40 }