Git fork
at reftables-rust 54 lines 1.8 kB view raw
1#ifndef ABSPATH_H 2#define ABSPATH_H 3 4int is_directory(const char *); 5char *strbuf_realpath(struct strbuf *resolved, const char *path, 6 int die_on_error); 7char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path, 8 int die_on_error); 9char *real_pathdup(const char *path, int die_on_error); 10const char *absolute_path(const char *path); 11char *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 */ 23char *prefix_filename(const char *prefix, const char *path); 24 25/* Likewise, but path=="-" always yields "-" */ 26char *prefix_filename_except_for_dash(const char *prefix, const char *path); 27 28static inline int is_absolute_path(const char *path) 29{ 30 return is_dir_sep(path[0]) || has_dos_drive_prefix(path); 31} 32 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 */ 38void 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 */ 52void strbuf_add_real_path(struct strbuf *sb, const char *path); 53 54#endif /* ABSPATH_H */