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);