diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 866abf6b5553458d5043911585738b99d654042f
parent f29201a64705b70e5320811c21db089ce988b726
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Mon, 31 May 2021 23:08:12 +0200

reuse expand_path in read_config

Diffstat:
Mdiary.c | 14++++----------
Mutils.c | 2+-
Mutils.h | 2+-
3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/diary.c b/diary.c @@ -236,17 +236,12 @@ struct tm find_closest_entry(const struct tm current, bool read_config(const char* file_path) { - wordexp_t config_file_path_wordexp; + char* expaned_value; char config_file_path[256]; - if ( wordexp( file_path, &config_file_path_wordexp, 0 ) == 0) { - if (strlen(config_file_path_wordexp.we_wordv[0]) + 1 > sizeof config_file_path) { - fprintf(stderr, "Config file path '%s' too long\n", config_file_path_wordexp.we_wordv[0]); - return false; - } - strcpy(config_file_path, config_file_path_wordexp.we_wordv[0]); - } - wordfree(&config_file_path_wordexp); + expaned_value = expand_path(file_path); + strcpy(config_file_path, expaned_value); + free(expaned_value); // check if config file is readable if( access( config_file_path, R_OK ) != 0 ) { @@ -257,7 +252,6 @@ bool read_config(const char* file_path) char key_buf[80]; char value_buf[80]; char line[256]; - char* expaned_value; FILE * pfile; // read config file line by line diff --git a/utils.c b/utils.c @@ -91,7 +91,7 @@ char* extract_ical_field(const char* ics, char* key, bool multiline) { } // Return expanded file path -char* expand_path(char* str) { +char* expand_path(const char* str) { char* res; wordexp_t str_wordexp; if ( wordexp( str, &str_wordexp, 0 ) == 0) { diff --git a/utils.h b/utils.h @@ -23,7 +23,7 @@ char* extract_json_value(char* json, char* key, bool quoted); char* extract_ical_field(const char* ical, char* key, bool multline); -char* expand_path(char* str); +char* expand_path(const char* str); char* strrstr(char *haystack, char *needle); void fpath(const char* dir, size_t dir_size, const struct tm* date, char** rpath, size_t rpath_size);