From: Kevin McCarthy Date: Mon, 11 Mar 2019 09:38:58 +0000 (+0800) Subject: Add mutt_getcwd() X-Git-Tag: 2019-10-25~276^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=646f26d9f14be047e784e6bd424111fc706edc0f;p=neomutt Add mutt_getcwd() Co-authored-by: Richard Russon --- diff --git a/muttlib.c b/muttlib.c index 3ff5ea20c..fd7065d67 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1699,3 +1699,22 @@ int mutt_inbox_cmp(const char *a, const char *b) return 0; } + +/** + * mutt_getcwd - Get the current working directory + * @param cwd Buffer for the result + */ +void mutt_getcwd(struct Buffer *cwd) +{ + mutt_buffer_increase_size(cwd, PATH_MAX); + char *retval = getcwd(cwd->data, cwd->dsize); + while (!retval && (errno == ERANGE)) + { + mutt_buffer_increase_size(cwd, cwd->dsize + 256); + retval = getcwd(cwd->data, cwd->dsize); + } + if (retval) + mutt_buffer_fix_dptr(cwd); + else + mutt_buffer_reset(cwd); +} diff --git a/muttlib.h b/muttlib.h index 8b7276097..2daf552b5 100644 --- a/muttlib.h +++ b/muttlib.h @@ -53,6 +53,7 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, char * mutt_expand_path(char *s, size_t slen); char * mutt_expand_path_regex(char *buf, size_t buflen, bool regex); char * mutt_gecos_name(char *dest, size_t destlen, struct passwd *pw); +void mutt_getcwd(struct Buffer *cwd); void mutt_get_parent_path(char *path, char *buf, size_t buflen); int mutt_inbox_cmp(const char *a, const char *b); bool mutt_is_text_part(struct Body *b);