Kvm/src/util.c
cannoli-fruit 79e255d19d Init
2026-08-01 23:26:59 -04:00

26 lines
400 B
C

#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
int makeFileAndParents(const char *path) {
char buf[4096];
strcpy(buf, path);
for (char *p = buf + 1; *p; p++) {
if (*p == '/') {
*p = '\0';
if (mkdir(buf, 0755) == -1 && errno != EEXIST)
return -1;
*p = '/';
}
}
return open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
}