void mkdir_p(char *dir)
{
- char *copy, *parent;
+ char *parent;
if ((dir == NULL) || (!strcmp(dir, ".")))
return;
- if ((copy = strdup(dir)) == NULL) {
+ parent = strdup(dirname(dir));
+ if (parent == NULL) {
perror("strdup");
exit(1);
}
- parent = dirname(copy);
+
mkdir_p(parent);
errno = 0;
exit(1);
}
}
- free(copy);
+ free(parent);
}
void write_file(char *fname, unsigned char *buf, int len)
perror("strdup");
exit(1);
}
- dirn = dirname(filename_c);
+ dirn = strdup(dirname(filename_c));
+ if (dirn == NULL) {
+ perror("strdup");
+ exit(1);
+ }
mkdir_p(dirn);
+ free(dirn);
free(filename_c);
if ((fd = open(fname, O_WRONLY|O_CREAT, 0644)) == -1) {