X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1691e80890e5d8ba258c51c214a3e91880e1db2b..b3d4a4452c332fc3550db3fbdf9e02027b41e985:/sbr/m_maildir.c diff --git a/sbr/m_maildir.c b/sbr/m_maildir.c index 11c6ee3e..8be011d5 100644 --- a/sbr/m_maildir.c +++ b/sbr/m_maildir.c @@ -1,18 +1,18 @@ - -/* - * m_maildir.c -- get the path for the mail directory +/* m_maildir.c -- get the path for the mail directory * - * $Id$ + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ -#include +#include "h/mh.h" +#include "h/utils.h" +#include "m_maildir.h" #define CWD "./" -#define NCWD (sizeof(CWD) - 1) #define DOT "." #define DOTDOT ".." #define PWD "../" -#define NPWD (sizeof(PWD) - 1) static char mailfold[BUFSIZ]; @@ -22,10 +22,11 @@ static char mailfold[BUFSIZ]; static char *exmaildir (char *); +/* Returns static char[], never NULL. */ char * m_maildir (char *folder) { - register char *cp, *ep; + char *cp, *ep; if ((cp = exmaildir (folder)) && (ep = cp + strlen (cp) - 1) > cp @@ -36,19 +37,20 @@ m_maildir (char *folder) } +/* Return value must be free(3)'d. */ char * m_mailpath (char *folder) { - register char *cp; + char *cp; char maildir[BUFSIZ]; if (*folder != '/' - && strncmp (folder, CWD, NCWD) + && !has_prefix(folder, CWD) && strcmp (folder, DOT) && strcmp (folder, DOTDOT) - && strncmp (folder, PWD, NPWD)) { + && !has_prefix(folder, PWD)) { strncpy (maildir, mailfold, sizeof(maildir)); /* preserve... */ - cp = getcpy (m_maildir (folder)); + cp = mh_xstrdup(m_maildir(folder)); strncpy (mailfold, maildir, sizeof(mailfold)); } else { cp = path (folder, TFOLDER); @@ -58,20 +60,21 @@ m_mailpath (char *folder) } +/* Returns static char[], never NULL. */ static char * exmaildir (char *folder) { - register char *cp, *pp; + char *cp, *pp; /* use current folder if none is specified */ if (folder == NULL) folder = getfolder(1); if (!(*folder != '/' - && strncmp (folder, CWD, NCWD) + && !has_prefix(folder, CWD) && strcmp (folder, DOT) && strcmp (folder, DOTDOT) - && strncmp (folder, PWD, NPWD))) { + && !has_prefix(folder, PWD))) { strncpy (mailfold, folder, sizeof(mailfold)); return mailfold; } @@ -79,12 +82,14 @@ exmaildir (char *folder) cp = mailfold; if ((pp = context_find ("path")) && *pp) { if (*pp != '/') { - sprintf (cp, "%s/", mypath); + snprintf(cp, sizeof mailfold, "%s/", mypath); cp += strlen (cp); } - cp = copy (pp, cp); + cp = stpcpy(cp, pp); } else { - cp = copy (path ("./", TFOLDER), cp); + char *p = path("./", TFOLDER); + cp = stpcpy(cp, p); + free(p); } if (cp[-1] != '/') *cp++ = '/';