Browse Source

Add .conf extension when looking for config file

Allow to specify a base filename (without extension) to the -c
option. A .conf extension will automatically be added when looking
for a configuration file in the XDG directory.
master
Damien Goutte-Gattat 6 years ago
parent
commit
0018c67340
  1. 6
      src/gfsec-use.c

6
src/gfsec-use.c

@ -82,9 +82,9 @@ get_config_file_in_dir(const char *filename, char *buffer, size_t len)
const char *env_info;
if ( (env_info = getenv("XDG_CONFIG_HOME")) )
rc = snprintf(buffer, len, "%s/gfsecret/%s", env_info, filename);
rc = snprintf(buffer, len, "%s/gfsecret/%s.conf", env_info, filename);
else if ( (env_info = getenv("HOME")) )
rc = snprintf(buffer, len, "%s/.config/gfsecret/%s", env_info, filename);
rc = snprintf(buffer, len, "%s/.config/gfsecret/%s.conf", env_info, filename);
else {
rc = -1;
errno = ENOENT;
@ -106,7 +106,7 @@ get_config_file(const char *filename, char *buffer, size_t len)
int rc;
if ( ! filename )
rc = get_config_file_in_dir("default.conf", buffer, len);
rc = get_config_file_in_dir("default", buffer, len);
else if ( file_exists(filename) == -1 )
rc = get_config_file_in_dir(filename, buffer, len);
else if ( strlen(filename) < len ) {

Loading…
Cancel
Save