wte.c: restructure into seperate files
This commit is contained in:
parent
20f4ae0581
commit
64d5fb6f89
2 changed files with 69 additions and 0 deletions
55
src/file.c
Normal file
55
src/file.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#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;
|
||||
}
|
14
src/manage.c
Normal file
14
src/manage.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue