const char *basename;
char parent[_POSIX_PATH_MAX];
char *p;
- int rv;
strfcpy (parent, NONULL (path), sizeof (parent));
basename = path;
}
- do
+ snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX");
+ if (mkdtemp(newdir) == NULL)
{
- snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX");
- mktemp (newdir);
- }
- while ((rv = mkdir (newdir, 0700)) == -1 && errno == EEXIST);
-
- if (rv == -1)
- return -1;
+ dprint(1, (debugfile, "mutt_mkwrapdir: mkdtemp() failed\n"));
+ return -1;
+ }
- snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename));
+ if (snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename)) >= nflen)
+ {
+ rmdir(newdir);
+ dprint(1, (debugfile, "mutt_mkwrapdir: string was truncated\n"));
+ return -1;
+ }
return 0;
}