Skip to content

Commit

Permalink
Rework resolve_config_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
lundmar committed Apr 14, 2024
1 parent 76a7a56 commit de0a7c5
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/configfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,30 +393,36 @@ static int resolve_config_file(void)
char *xdg = getenv("XDG_CONFIG_HOME");
if (xdg)
{
asprintf(&c.path, "%s/tio/config", xdg);
if (access(c.path, F_OK) == 0)
if (asprintf(&c.path, "%s/tio/config", xdg) != -1)
{
return 0;
if (access(c.path, F_OK) == 0)
{
return 0;
}
free(c.path);
}
free(c.path);
}

char *home = getenv("HOME");
if (home)
{
asprintf(&c.path, "%s/.config/tio/config", home);
if (access(c.path, F_OK) == 0)
if (asprintf(&c.path, "%s/.config/tio/config", home) != -1)
{
return 0;
if (access(c.path, F_OK) == 0)
{
return 0;
}
free(c.path);
}
free(c.path);

asprintf(&c.path, "%s/.tioconfig", home);
if (access(c.path, F_OK) == 0)
if (asprintf(&c.path, "%s/.tioconfig", home) != -1)
{
return 0;
if (access(c.path, F_OK) == 0)
{
return 0;
}
free(c.path);
}
free(c.path);
}

c.path = NULL;
Expand Down

0 comments on commit de0a7c5

Please sign in to comment.