Fix mkostemps and mkdtemp not restoring X's on error.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-06-02 13:31:43 +02:00
parent 447f0596ad
commit 13e8e092a6
2 changed files with 9 additions and 4 deletions

View File

@ -59,5 +59,7 @@ extern "C" char* mkdtemp(char* templ)
return templ;
} while ( errno == EEXIST );
memcpy(templ + xpos, "XXXXXX", 6);
return NULL;
}

View File

@ -54,13 +54,16 @@ extern "C" int mkostemps(char* templ, int suffixlen, int flags)
return errno = EINVAL, -1;
flags &= ~O_ACCMODE;
int fd;
do
{
for ( size_t i = 0; i < 6; i++ )
templ[xpos + i] = random_character();
} while ( (fd = open(templ, flags | O_RDWR | O_EXCL | O_CREAT, 0600)) < 0 &&
(errno == EEXIST) );
int fd = open(templ, flags | O_RDWR | O_EXCL | O_CREAT, 0600);
if ( 0 <= fd )
return fd;
} while ( errno == EEXIST );
return fd;
memcpy(templ + xpos, "XXXXXX", 6);
return -1;
}