struct stat st;
char fullpath[_POSIX_PATH_MAX];
- snprintf (fullpath, sizeof (fullpath), "%s/%s", folder, path);
+ mutt_concat_path (fullpath, folder, path, sizeof (fullpath));
if (stat (fullpath, &st) == 0)
return (S_ISDIR (st.st_mode));
if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not))
continue;
- snprintf (buffer, sizeof (buffer), "%s/%s", d, de->d_name);
+ mutt_concat_path (buffer, d, de->d_name, sizeof (buffer));
if (lstat (buffer, &s) == -1)
continue;
}
#endif
else
- snprintf (buf, sizeof (buf), "%s/%s", LastDir,
- state.entry[menu->current].name);
+ mutt_concat_path (buf, LastDir, state.entry[menu->current].name, sizeof (buf));
if ((mx_get_magic (buf) <= 0)
#ifdef USE_IMAP
else
{
char tmp[_POSIX_PATH_MAX];
- snprintf (tmp, sizeof (tmp), "%s/%s", LastDir, state.entry[menu->current].name);
+ mutt_concat_path (tmp, LastDir, state.entry[menu->current].name, sizeof (tmp));
strfcpy (LastDir, tmp, sizeof (LastDir));
}
strfcpy (f, state.entry[menu->current].name, flen);
#endif
else
- snprintf (f, flen, "%s/%s", LastDir, state.entry[menu->current].name);
+ mutt_concat_path (f, LastDir, state.entry[menu->current].name, flen);
/* Fall through to OP_EXIT */
char full[_POSIX_PATH_MAX];
if (ff.tagged)
{
- snprintf (full, sizeof (full), "%s/%s", LastDir, ff.name);
+ mutt_concat_path (full, LastDir, ff.name, sizeof (full));
mutt_expand_path (full, sizeof (full));
tfiles[j++] = safe_strdup (full);
}
{
BODY *b;
char buf[_POSIX_PATH_MAX];
-
- snprintf (buf, sizeof (buf), "%s/%s", LastDir,
- state.entry[menu->current].name);
+
+ mutt_concat_path (buf, LastDir, state.entry[menu->current].name, sizeof (buf));
b = mutt_make_file_attach (buf);
if (b != NULL)
{
p = NONULL (Spoolfile);
else
p = NONULL (Maildir);
- if (s[1])
- {
- /* don't append '/' if Maildir/Spoolfile is imap://host/ only */
- if (mx_is_imap (NONULL (p)) && p[strlen (p)-1] == '/')
- snprintf (imap_path, sizeof (imap_path), "%s%s", p, s+1);
- else
- snprintf (imap_path, sizeof (imap_path), "%s/%s", NONULL (p),
- s+1);
- }
- else
- strfcpy (imap_path, NONULL(p), sizeof(imap_path));
+
+ mutt_concat_path (imap_path, p, s+1, sizeof (imap_path));
}
else
strfcpy (imap_path, s, sizeof(imap_path));
{
char buf[_POSIX_PATH_MAX];
*p++ = 0;
- snprintf (buf, sizeof (buf), "%s/%s", exp_dirpart, s+1);
+ mutt_concat_path (buf, exp_dirpart, s + 1, sizeof (buf));
strfcpy (exp_dirpart, buf, sizeof (exp_dirpart));
snprintf (buf, sizeof (buf), "%s%s/", dirpart, s+1);
strfcpy (dirpart, buf, sizeof (dirpart));
{
adr = env->to ? env->to : (env->cc ? env->cc : env->bcc);
mutt_safe_path (buf, sizeof (buf), adr);
- snprintf (path, pathlen, "%s/%s", NONULL (Maildir), buf);
+ mutt_concat_path (path, NONULL(Maildir), buf, pathlen);
if (!option (OPTFORCENAME) && mx_access (path, W_OK) != 0)
strfcpy (path, NONULL (Outbox), pathlen);
}
else
{
#ifdef HOMESPOOL
- snprintf (buffer, sizeof (buffer), "%s/%s", NONULL(Homedir), MAILPATH);
+ mutt_concat_path (buffer, NONULL (Homedir), MAILPATH, sizeof (buffer));
#else
- snprintf (buffer, sizeof (buffer), "%s/%s", MAILPATH, NONULL(Username));
+ mutt_concat_path (buffer, MAILPATH, NONULL(Username), sizeof (buffer));
#endif
Spoolfile = safe_strdup (buffer);
}
for (p = s + mutt_strlen (s) - 1 ; p >= s && ISSPACE (*p) ; p--)
*p = 0;
}
+
+char *mutt_concat_path (char *d, const char *dir, const char *fname, size_t l)
+{
+ const char *fmt = "%s/%s";
+
+ if (!*fname || (*dir && dir[strlen(dir)-1] == '/'))
+ fmt = "%s%s";
+
+ snprintf (d, sizeof (d), fmt, dir, fname);
+ return d;
+}
FILE *safe_fopen (const char *, const char *);
+char *mutt_concat_path (char *, const char *, const char *, size_t);
char *mutt_read_line (char *, size_t *, FILE *, int *);
char *mutt_skip_whitespace (char *);
char *mutt_strlower (char *);