From: Richard Russon Date: Thu, 11 Apr 2019 01:59:24 +0000 (+0100) Subject: libmutt: promote mutt_buffer_concat_path to the library X-Git-Tag: 2019-10-25~262^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9daf99407962452ea128d67770cc7d48cbfe1b05;p=neomutt libmutt: promote mutt_buffer_concat_path to the library --- diff --git a/browser.h b/browser.h index 0cdee3092..9bdef94bc 100644 --- a/browser.h +++ b/browser.h @@ -107,6 +107,5 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags, char ** void mutt_buffer_select_file(struct Buffer *f, SelectFileFlags flags, char ***files, int *numfiles); void mutt_browser_select_dir(const char *f); void mutt_browser_cleanup(void); -void mutt_buffer_concat_path(struct Buffer *d, const char *dir, const char *fname); #endif /* MUTT_BROWSER_H */ diff --git a/mutt/buffer.c b/mutt/buffer.c index a1b0cc5b6..423fae5eb 100644 --- a/mutt/buffer.c +++ b/mutt/buffer.c @@ -443,3 +443,22 @@ size_t mutt_buffer_len(const struct Buffer *buf) return buf->dptr - buf->data; } + +/** + * mutt_buffer_concat_path - Join a directory name and a filename + * @param buf Buffer to add to + * @param dir Directory name + * @param fname File name + * + * If both dir and fname are supplied, they are separated with '/'. + * If either is missing, then the other will be copied exactly. + */ +void mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname) +{ + const char *fmt = "%s/%s"; + + if ((fname[0] == '\0') || ((dir[0] != '\0') && (dir[strlen(dir) - 1] == '/'))) + fmt = "%s%s"; + + mutt_buffer_printf(buf, fmt, dir, fname); +} diff --git a/mutt/buffer.h b/mutt/buffer.h index d04b7b6dd..400de48e7 100644 --- a/mutt/buffer.h +++ b/mutt/buffer.h @@ -48,6 +48,7 @@ size_t mutt_buffer_addstr (struct Buffer *buf, const char *s); size_t mutt_buffer_addstr_n (struct Buffer *buf, const char *s, size_t len); int mutt_buffer_add_printf (struct Buffer *buf, const char *fmt, ...); struct Buffer *mutt_buffer_alloc (size_t size); +void mutt_buffer_concat_path (struct Buffer *buf, const char *dir, const char *fname); void mutt_buffer_fix_dptr (struct Buffer *buf); void mutt_buffer_free (struct Buffer **p); struct Buffer *mutt_buffer_from (const char *seed); diff --git a/muttlib.c b/muttlib.c index c923a7bfb..0a0a8bc40 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1712,22 +1712,3 @@ int mutt_inbox_cmp(const char *a, const char *b) return 0; } - -/** - * mutt_buffer_concat_path - Join a directory name and a filename - * @param d Buffer to add to - * @param dir Directory name - * @param fname File name - * - * If both dir and fname are supplied, they are separated with '/'. - * If either is missing, then the other will be copied exactly. - */ -void mutt_buffer_concat_path(struct Buffer *d, const char *dir, const char *fname) -{ - const char *fmt = "%s/%s"; - - if (!*fname || (*dir && dir[strlen(dir) - 1] == '/')) - fmt = "%s%s"; - - mutt_buffer_printf(d, fmt, dir, fname); -}