From 76396a3022cbeec8948062b99c9f504340d41578 Mon Sep 17 00:00:00 2001 From: Zvonimir Rudinski Date: Sun, 2 Jun 2024 05:55:54 +0200 Subject: [PATCH] store the default file in the home directory dotfile --- main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.c b/main.c index 1d9647f..52e3201 100644 --- a/main.c +++ b/main.c @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #define MAX_TODOS UINT_MAX #define MAX_PATH_LENGTH 1024 @@ -299,6 +302,14 @@ int main(int argc, char **argv) { // set the save file path if provided if (argc > 1 && strlen(argv[1]) < MAX_PATH_LENGTH) { strncpy(SAVE_FILE, argv[1], MAX_PATH_LENGTH); + } else { + // load the default save file which is "~/.todos.todd" + struct passwd *pw = getpwuid(getuid()); + const char *homedir = pw->pw_dir; + // check if we have enough space to store the path + assert(strlen(homedir) + strlen("/.todos.todd") < MAX_PATH_LENGTH); + // create the path + snprintf(SAVE_FILE, MAX_PATH_LENGTH, "%s/.todos.todd", homedir); } initialize_curses(&terminal_width, &terminal_height);