}
}
/* resolve paths navigated from GUI */
- if (mutt_realpath(LastDir) == 0)
+ if (mutt_path_realpath(LastDir) == 0)
break;
}
/* Resolve path from <chdir>
* Avoids buildup such as /a/b/../../c
* Symlinks are always unraveled to keep code simple */
- if (mutt_realpath(buf) == 0)
+ if (mutt_path_realpath(buf) == 0)
break;
if (stat(buf, &st) == 0)
return true;
}
+/**
+ * mutt_path_realpath - resolve path, unraveling symlinks
+ * @param buf Buffer containing path
+ * @retval num String length of resolved path
+ * @retval 0 Error, buf is not overwritten
+ *
+ * Resolve and overwrite the path in buf.
+ *
+ * @note Size of buf should be at least PATH_MAX bytes.
+ */
+size_t mutt_path_realpath(char *buf)
+{
+ char s[PATH_MAX];
+
+ if (realpath(buf, s) == NULL)
+ return 0;
+
+ return mutt_str_strfcpy(buf, s, sizeof(s));
+}
+
+/**
+ * mutt_path_get_parent - Find the parent of a path
+ * @param path Path to use
+ * @param buf Buffer for the result
+ * @param buflen Length of buffer
+ */
+void mutt_path_get_parent(char *path, char *buf, size_t buflen)
+{
+ if (!path || !buf || (buflen == 0))
+ return;
+
+ mutt_str_strfcpy(buf, path, buflen);
+ int n = mutt_str_strlen(buf);
+ if (n == 0)
+ return;
+
+ /* remove any final trailing '/' */
+ if (buf[n - 1] == '/')
+ buf[n - 1] = '\0';
+
+ /* Remove everything until the next slash */
+ for (n--; ((n >= 0) && (buf[n] != '/')); n--)
+ ;
+
+ if (n > 0)
+ buf[n] = '\0';
+ else
+ {
+ buf[0] = '/';
+ buf[1] = '\0';
+ }
+}
char * mutt_path_concat(char *d, const char *dir, const char *fname, size_t l);
char * mutt_path_concatn(char *dst, size_t dstlen, const char *dir, size_t dirlen, const char *fname, size_t fnamelen);
char * mutt_path_dirname(const char *path);
+void mutt_path_get_parent(char *path, char *buf, size_t buflen);
bool mutt_path_pretty(char *buf, size_t buflen, const char *homedir);
+size_t mutt_path_realpath(char *buf);
bool mutt_path_tidy(char *buf);
bool mutt_path_tidy_dotdot(char *buf);
bool mutt_path_tidy_slash(char *buf);
}
}
-/**
- * mutt_realpath - resolve path, unraveling symlinks
- * @param buf Buffer containing path
- * @retval num String length of resolved path
- * @retval 0 Error, buf is not overwritten
- *
- * Resolve and overwrite the path in buf.
- *
- * @note Size of buf should be at least PATH_MAX bytes.
- */
-size_t mutt_realpath(char *buf)
-{
- char s[PATH_MAX];
-
- if (realpath(buf, s) == NULL)
- return 0;
-
- return mutt_str_strfcpy(buf, s, sizeof(s));
-}
-
/**
* mutt_inbox_cmp - do two folders share the same path and one is an inbox
* @param a First path
uint64_t mutt_rand64(void);
void mutt_rand_base32(void *out, size_t len);
int mutt_randbuf(void *out, size_t len);
-size_t mutt_realpath(char *buf);
void mutt_safe_path(char *s, size_t l, struct Address *a);
int mutt_save_confirm(const char *s, struct stat *st);
void mutt_save_path(char *d, size_t dsize, struct Address *a);