Use Strnew_charp() to create char * instead of strdup().

This commit is contained in:
Yash Lala
2022-06-03 17:04:07 -07:00
parent f812275fe6
commit 4c8f4f6cd9

16
rc.c
View File

@@ -1248,9 +1248,7 @@ do_recursive_mkdir(const char *dir)
if (*dir == '\0')
return -1;
if ((dircpy = strdup(dir)) == NULL)
return -1;
dircpy = Strnew_charp(dir)->ptr;
ch = dircpy + 1;
do {
while (!(*ch == '/' || *ch == '\0')) {
@@ -1262,30 +1260,26 @@ do_recursive_mkdir(const char *dir)
if (stat(dircpy, &st) < 0) {
if (errno != ENOENT) { /* no directory */
goto err;
return -1;
}
if (do_mkdir(dircpy, 0700) < 0) {
goto err;
return -1;
}
stat(dircpy, &st);
}
if (!S_ISDIR(st.st_mode)) {
/* not a directory */
goto err;
return -1;
}
if (!(st.st_mode & S_IWUSR)) {
goto err;
return -1;
}
*ch = tmp;
} while (*ch++ != '\0');
free(dircpy);
return 0;
err:
free(dircpy);
return -1;
}
static void loadSiteconf(void);