Skip to content

Commit

Permalink
xdg.c: make_dirpath(): Add error message if cannot create directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ampli committed May 24, 2024
1 parent 8bbfa43 commit b875a11
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions link-parser/lg_xdg.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,23 @@ static bool make_dirpath(const char *path)
if (is_sep(p[-1])) continue; // Ignore directory separator sequences
*p = '\0'; // Now dir is the path up to this point
//prt_error("DEBUG: mkdir: '%s'\n", dir);
mkdir(dir, S_IRWXU); // Try to create the directory
if (stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode))
if (mkdir(dir, S_IRWXU) == -1)
{
prt_error("Error: Cannot create directory '%s'\n", dir);
free(dir);
return false;
int save_errno = errno;
if (errno == EEXIST)
{
if (stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode))
goto mkdir_error;
errno = 0;
}
mkdir_error:
if (errno != 0)
{
prt_error("Error: Cannot create directory '%s': %s.\n",
dir, strerror(save_errno));
free(dir);
return false;
}
}
*p = sep;
}
Expand Down

0 comments on commit b875a11

Please sign in to comment.