Commit | Line | Data |
---|---|---|
b4987c95 SDJ |
1 | /* Path manipulation routines for GDB and gdbserver. |
2 | ||
42a4f53d | 3 | Copyright (C) 1986-2019 Free Software Foundation, Inc. |
b4987c95 SDJ |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
1a5c2598 TT |
20 | #ifndef COMMON_PATHSTUFF_H |
21 | #define COMMON_PATHSTUFF_H | |
b4987c95 | 22 | |
268a13a5 | 23 | #include "gdbsupport/byte-vector.h" |
29be4d9d | 24 | |
b4987c95 SDJ |
25 | /* Path utilities. */ |
26 | ||
27 | /* Return the real path of FILENAME, expanding all the symbolic links. | |
28 | ||
29 | Contrary to "gdb_abspath", this function does not use | |
30 | CURRENT_DIRECTORY for path expansion. Instead, it relies on the | |
31 | current working directory (CWD) of GDB or gdbserver. */ | |
32 | ||
33 | extern gdb::unique_xmalloc_ptr<char> gdb_realpath (const char *filename); | |
34 | ||
35 | /* Return a copy of FILENAME, with its directory prefix canonicalized | |
36 | by gdb_realpath. */ | |
37 | ||
38 | extern gdb::unique_xmalloc_ptr<char> | |
39 | gdb_realpath_keepfile (const char *filename); | |
40 | ||
41 | /* Return PATH in absolute form, performing tilde-expansion if necessary. | |
42 | PATH cannot be NULL or the empty string. | |
43 | This does not resolve symlinks however, use gdb_realpath for that. | |
44 | ||
45 | Contrary to "gdb_realpath", this function uses CURRENT_DIRECTORY | |
46 | for the path expansion. This may lead to scenarios the current | |
47 | working directory (CWD) is different than CURRENT_DIRECTORY. */ | |
48 | ||
49 | extern gdb::unique_xmalloc_ptr<char> gdb_abspath (const char *path); | |
50 | ||
efac4bfe JB |
51 | /* If the path in CHILD is a child of the path in PARENT, return a |
52 | pointer to the first component in the CHILD's pathname below the | |
53 | PARENT. Otherwise, return NULL. */ | |
54 | ||
55 | extern const char *child_path (const char *parent, const char *child); | |
56 | ||
25e3c82c SDJ |
57 | /* Return whether PATH contains a directory separator character. */ |
58 | ||
59 | extern bool contains_dir_separator (const char *path); | |
60 | ||
87d6a7aa SM |
61 | /* Get the usual user cache directory for the current platform. |
62 | ||
63 | On Linux, it follows the XDG Base Directory specification: use | |
e6cd1dc1 TT |
64 | $XDG_CACHE_HOME/gdb if the XDG_CACHE_HOME environment variable is |
65 | defined, otherwise $HOME/.cache. | |
87d6a7aa | 66 | |
e6cd1dc1 TT |
67 | On macOS, it follows the local convention and uses |
68 | ~/Library/Caches/gdb. | |
69 | ||
70 | The return value is absolute and tilde-expanded. Return an empty | |
71 | string if neither XDG_CACHE_HOME (on Linux) or HOME are defined. */ | |
87d6a7aa SM |
72 | |
73 | extern std::string get_standard_cache_dir (); | |
74 | ||
e8d8cce6 SM |
75 | /* Get the usual temporary directory for the current platform. |
76 | ||
77 | On Windows, this is the TMP or TEMP environment variable. | |
78 | ||
79 | On the rest, this is the TMPDIR environment variable, if defined, else /tmp. | |
80 | ||
81 | Throw an exception on error. */ | |
82 | ||
83 | extern std::string get_standard_temp_dir (); | |
84 | ||
974e6844 TT |
85 | /* Return the file name of the user's shell. Normally this comes from |
86 | the SHELL environment variable. */ | |
87 | ||
88 | extern const char *get_shell (); | |
89 | ||
29be4d9d TT |
90 | /* Make a filename suitable to pass to mkstemp based on F (e.g. |
91 | /tmp/foo -> /tmp/foo-XXXXXX). */ | |
92 | ||
93 | extern gdb::char_vector make_temp_filename (const std::string &f); | |
94 | ||
1a5c2598 | 95 | #endif /* COMMON_PATHSTUFF_H */ |