Elijah Newren | 0b027f6 | 2023-03-21 06:25:58 +0000 | [diff] [blame] | 1 | #ifndef ABSPATH_H |
| 2 | #define ABSPATH_H |
| 3 | |
| 4 | int is_directory(const char *); |
| 5 | char *strbuf_realpath(struct strbuf *resolved, const char *path, |
| 6 | int die_on_error); |
| 7 | char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path, |
| 8 | int die_on_error); |
| 9 | char *real_pathdup(const char *path, int die_on_error); |
| 10 | const char *absolute_path(const char *path); |
| 11 | char *absolute_pathdup(const char *path); |
| 12 | |
| 13 | /* |
| 14 | * Concatenate "prefix" (if len is non-zero) and "path", with no |
| 15 | * connecting characters (so "prefix" should end with a "/"). |
| 16 | * Unlike prefix_path, this should be used if the named file does |
| 17 | * not have to interact with index entry; i.e. name of a random file |
| 18 | * on the filesystem. |
| 19 | * |
| 20 | * The return value is always a newly allocated string (even if the |
| 21 | * prefix was empty). |
| 22 | */ |
| 23 | char *prefix_filename(const char *prefix, const char *path); |
| 24 | |
| 25 | /* Likewise, but path=="-" always yields "-" */ |
| 26 | char *prefix_filename_except_for_dash(const char *prefix, const char *path); |
| 27 | |
| 28 | static inline int is_absolute_path(const char *path) |
| 29 | { |
| 30 | return is_dir_sep(path[0]) || has_dos_drive_prefix(path); |
| 31 | } |
| 32 | |
Calvin Wan | 5d1344b | 2023-06-06 19:48:39 +0000 | [diff] [blame] | 33 | /** |
| 34 | * Add a path to a buffer, converting a relative path to an |
| 35 | * absolute one in the process. Symbolic links are not |
| 36 | * resolved. |
| 37 | */ |
| 38 | void strbuf_add_absolute_path(struct strbuf *sb, const char *path); |
| 39 | |
| 40 | /** |
| 41 | * Canonize `path` (make it absolute, resolve symlinks, remove extra |
| 42 | * slashes) and append it to `sb`. Die with an informative error |
| 43 | * message if there is a problem. |
| 44 | * |
| 45 | * The directory part of `path` (i.e., everything up to the last |
| 46 | * dir_sep) must denote a valid, existing directory, but the last |
| 47 | * component need not exist. |
| 48 | * |
| 49 | * Callers that don't mind links should use the more lightweight |
| 50 | * strbuf_add_absolute_path() instead. |
| 51 | */ |
| 52 | void strbuf_add_real_path(struct strbuf *sb, const char *path); |
| 53 | |
Elijah Newren | 0b027f6 | 2023-03-21 06:25:58 +0000 | [diff] [blame] | 54 | #endif /* ABSPATH_H */ |