From 64d5fb6f8988114fd70f4e2d6cef331b0543c9b1 Mon Sep 17 00:00:00 2001 From: xesc Date: Sat, 12 Oct 2024 21:09:32 +0200 Subject: [PATCH] wte.c: restructure into seperate files --- src/file.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/manage.c | 14 +++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/file.c create mode 100644 src/manage.c diff --git a/src/file.c b/src/file.c new file mode 100644 index 0000000..eba640d --- /dev/null +++ b/src/file.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include "wte.h" + +char *get_path() +{ + const char *home = getenv("HOME"); + char *path = NULL; + if (home) { + size_t path_len = strlen(home) + sizeof(DATA_DIR); + path = malloc(sizeof(char) * path_len); + if (path) { + snprintf(path, path_len, "%s" DATA_DIR, home); + dbg("path: %s", path); + } + } + return path; +} + +int create_data_dir() +{ + int ret = 0; + struct stat st; + int dir_exists = stat(DATA_DIR, &st); + if (-1 == dir_exists) { + dbg("%s", "creating data dir"); + char *path = get_path(); + if (path && 0 != (ret = mkdir(path, 0700))) { + error("%s", "failed to create directory"); + } + free(path); + } + return ret; +} + +static int remove_file() +{ + int ret = 0; + return ret; +} + +int remove_data_dir() +{ + int ret = 0; + ret = remove_file(); + char *path = get_path(); + if (path) { + // here: for loop to delete all entries in directory + ret = remove(path); + free(path); + } + dbg("ret: %d", ret); + return ret; +} diff --git a/src/manage.c b/src/manage.c new file mode 100644 index 0000000..67ae9bd --- /dev/null +++ b/src/manage.c @@ -0,0 +1,14 @@ +#include "wte.h" + +int insert_choice() +{ + int ret = 1; + return ret; +} + +int remove_choice() +{ + int ret = 1; + error("%s", "unable to remove choice"); + return ret; +}