X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/64c5ab73d49a8347c541d7de42549a50d5ca56aa..73e1f01148bb9709a405e27f7d3c5a95ea03b859:/sbr/path.c diff --git a/sbr/path.c b/sbr/path.c index 416c32b5..a6568db8 100644 --- a/sbr/path.c +++ b/sbr/path.c @@ -5,8 +5,12 @@ * complete copyright information. */ -#include -#include +#include "h/mh.h" +#include "ssequal.h" +#include "getfolder.h" +#include "path.h" +#include "h/utils.h" +#include "m_maildir.h" #define CWD "./" #define DOT "." @@ -21,26 +25,31 @@ static char *pwds; static char *expath(char *,int); static void compath(char *); + +/* Return value must be free(3)'d. */ char * pluspath(char *name) { return path(name + 1, *name == '+' ? TFOLDER : TSUBCWF); } + +/* Return value must be free(3)'d. */ char * path(char *name, int flag) { - char *cp, *ep; + char *p, *last; - if ((cp = expath (name, flag)) - && (ep = cp + strlen (cp) - 1) > cp - && *ep == '/') - *ep = '\0'; + p = expath(name, flag); + last = p + strlen(p) - 1; + if (last > p && *last == '/') + *last = '\0'; - return cp; + return p; } +/* Return value must be free(3)'d. */ static char * expath (char *name, int flag) { @@ -77,9 +86,8 @@ expath (char *name, int flag) ep = pwds + strlen (pwds); if ((cp = strrchr(pwds, '/')) == NULL) cp = ep; - else - if (cp == pwds) - cp++; + else if (cp == pwds) + cp++; if (has_prefix(name, CWD)) name += LEN(CWD);