Fix race condition in makedirs()

This commit is contained in:
Justine Tunney 2022-09-07 22:52:24 -07:00
parent b7c07d548c
commit 571c2c3c69
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
7 changed files with 90 additions and 10 deletions

View file

@ -17,12 +17,16 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/x/x.h"
/**
* Returns directory portion of path.
*/
char *xdirname(const char *path) {
return xstrdup(dirname(gc(xstrdup(path))));
char *dirp;
path = xstrdup(path);
dirp = xstrdup(dirname(path));
free(path);
return dirp;
}