mkdtemp: proper error detection on mktemp

On error, mktemp returns an empty string, not NULL.

Signed-off-by: Xabier Oneca <xoneca@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Xabier Oneca 2020-12-01 23:14:59 +01:00 committed by Denys Vlasenko
parent c9b93cf290
commit abaee4aada

View File

@ -107,7 +107,8 @@ void* FAST_FUNC memrchr(const void *s, int c, size_t n)
/* This is now actually part of POSIX.1, but was only added in 2008 */ /* This is now actually part of POSIX.1, but was only added in 2008 */
char* FAST_FUNC mkdtemp(char *template) char* FAST_FUNC mkdtemp(char *template)
{ {
if (mktemp(template) == NULL || mkdir(template, 0700) != 0) /* NB: on error, mktemp returns an empty string, not NULL */
if (mktemp(template)[0] == '\0' || mkdir(template, 0700) != 0)
return NULL; return NULL;
return template; return template;
} }