68 for (; (r[0] ==
'/') || (r[0] ==
'.'); r++)
79 else if (r[1] ==
'\0')
90 if (is_dir && (w > (buf + 1)) && (w[-1] ==
'/'))
107 if (!buf || (buf[0] !=
'/'))
113 while ((dd = strstr(dd,
"/..")))
121 dest = strrchr(buf,
'/');
126 memmove(dest, dd + 3, strlen(dd + 3) + 1);
128 else if (dd[3] ==
'\0')
137 char *s = strrchr(buf,
'/');
199 if ((
buf_at(path, len) !=
'/') && (
buf_at(path, len) !=
'\0'))
205 path->
data[1] =
'\0';
235 if ((
buf_at(path, 1) ==
'/') || (
buf_at(path, 1) ==
'\0'))
244 dir = path->
data + 1;
248 char user[128] = { 0 };
249 dir = strchr(path->
data + 1,
'/');
255 struct passwd *pw = getpwnam(user);
256 if (!pw || !pw->pw_dir)
285 if (
buf_at(path, 0) ==
'~')
289 else if (
buf_at(path, 0) !=
'/')
292 if (!getcwd(cwd,
sizeof(cwd)))
300 cwd[cwd_len + 1] =
'\0';
319 const char *p = strrchr(path,
'/');
344 if (!dest || (!dir && !file))
347 if (dir && (!file || (file[0] ==
'\0')))
349 strncpy(dest, dir, dlen);
353 if (file && (!dir || (dir[0] ==
'\0')))
355 strncpy(dest, file, dlen);
359 const char *fmt =
"%s/%s";
361 if (dir[strlen(dir) - 1] ==
'/')
364 snprintf(dest, dlen, fmt, dir, file);
404 if (!path || !reference)
411 if ((strlen(path) > 1) && (path[0] ==
'/'))
421 path_len =
sizeof(abs_path) - strlen(path);
423 mutt_strn_cat(abs_path,
sizeof(abs_path), path, (path_len > 0) ? path_len : 0);
425 path = realpath(abs_path, path);
426 if (!path && (errno != ENOENT))
470 if (
buf_at(path, n - 1) ==
'/')
474 for (n--; ((n >= 0) && (
buf_at(path, n) !=
'/')); n--)
480 path->
data[n] =
'\0';
503 if (folder[flen - 1] ==
'/')
509 if (
buf_at(path, flen + 1) ==
'\0')
515 memmove(path->
data + 1, path->
data + flen + 1, rlen + 1);
537 while (*src && (destsize <
sizeof(dest) - 1))
547 if ((destsize + 4) <
sizeof(dest))
577 char *rc = getcwd(cwd->
data, cwd->
dsize);
578 while (!rc && (errno == ERANGE))
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
char buf_at(const struct Buffer *buf, size_t offset)
Return the character at the given offset.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
size_t buf_insert(struct Buffer *buf, size_t offset, const char *s)
Add a string in the middle of a buffer.
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
General purpose object for storing and parsing strings.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
#define mutt_debug(LEVEL,...)
@ LL_DEBUG3
Log at debug level 3.
@ LL_DEBUG1
Log at debug level 1.
Memory management wrappers.
bool mutt_path_tidy_dotdot(char *buf)
Remove dot-dot-slash from a path.
const char * mutt_path_basename(const char *path)
Find the last component for a pathname.
bool mutt_path_tidy(struct Buffer *path, bool is_dir)
Remove unnecessary parts of a path.
bool mutt_path_to_absolute(char *path, const char *reference)
Convert relative filepath to an absolute path.
bool mutt_path_canon(struct Buffer *path, const char *homedir, bool is_dir)
Create the canonical version of a path.
char * mutt_path_escape(const char *src)
Escapes single quotes in a path for a command string.
char * mutt_path_dirname(const char *path)
Return a path up to, but not including, the final '/'.
bool mutt_path_tidy_slash(char *buf, bool is_dir)
Remove unnecessary slashes and dots.
bool mutt_path_abbr_folder(struct Buffer *path, const char *folder)
Create a folder abbreviation.
bool mutt_path_parent(struct Buffer *path)
Find the parent of a path.
size_t mutt_path_realpath(struct Buffer *path)
Resolve path, unraveling symlinks.
bool mutt_path_tilde(struct Buffer *path, const char *homedir)
Expand '~' in a path.
const char * mutt_path_getcwd(struct Buffer *cwd)
Get the current working directory.
char * mutt_path_concat(char *dest, const char *dir, const char *file, size_t dlen)
Join a directory name and a filename.
bool mutt_path_pretty(struct Buffer *path, const char *homedir, bool is_dir)
Tidy a filesystem path.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
char * mutt_strn_cat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Path manipulation functions.
String manipulation functions.
#define STR_COMMAND
Enough space for a long command line.
String manipulation buffer.
size_t dsize
Length of data.
char * data
Pointer to data.