mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fix mkostemps and mkdtemp not restoring X's on error.
This commit is contained in:
parent
447f0596ad
commit
13e8e092a6
2 changed files with 9 additions and 4 deletions
|
@ -59,5 +59,7 @@ extern "C" char* mkdtemp(char* templ)
|
||||||
return templ;
|
return templ;
|
||||||
} while ( errno == EEXIST );
|
} while ( errno == EEXIST );
|
||||||
|
|
||||||
|
memcpy(templ + xpos, "XXXXXX", 6);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,13 +54,16 @@ extern "C" int mkostemps(char* templ, int suffixlen, int flags)
|
||||||
return errno = EINVAL, -1;
|
return errno = EINVAL, -1;
|
||||||
|
|
||||||
flags &= ~O_ACCMODE;
|
flags &= ~O_ACCMODE;
|
||||||
int fd;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
for ( size_t i = 0; i < 6; i++ )
|
for ( size_t i = 0; i < 6; i++ )
|
||||||
templ[xpos + i] = random_character();
|
templ[xpos + i] = random_character();
|
||||||
} while ( (fd = open(templ, flags | O_RDWR | O_EXCL | O_CREAT, 0600)) < 0 &&
|
int fd = open(templ, flags | O_RDWR | O_EXCL | O_CREAT, 0600);
|
||||||
(errno == EEXIST) );
|
if ( 0 <= fd )
|
||||||
|
return fd;
|
||||||
|
} while ( errno == EEXIST );
|
||||||
|
|
||||||
return fd;
|
memcpy(templ + xpos, "XXXXXX", 6);
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue