int check_create_dir(const char *file_orig) {
struct stat statbuf;
- char file_copy[512];
- char dir[512];
- int dir_len = 512;
+ char file_copy[PATH_MAX];
+ char dir[PATH_MAX];
char *fields[16];
int fields_num;
char *ptr;
if ((len = strlen(file_orig)) < 1)
return -1;
- else if (len >= sizeof(file_copy))
+ else if (len >= sizeof(file_copy)) {
+ ERROR("check_create_dir: name (%s) is too long.", file_orig);
return -1;
+ }
/*
* If `file_orig' ends in a slash the last component is a directory,
* Join the components together again
*/
dir[0] = '/';
- if (strjoin(dir + path_is_absolute, (size_t)(dir_len - path_is_absolute),
- fields, (size_t)(i + 1), "/") < 0) {
+ if (strjoin(dir + path_is_absolute,
+ (size_t)(sizeof(dir) - path_is_absolute), fields,
+ (size_t)(i + 1), "/") < 0) {
ERROR("strjoin failed: `%s', component #%i", file_orig, i);
return -1;
}