diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-04-22 05:47:33 +0300 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-04-22 05:47:33 +0300 |
commit | eeca7f0151d85d563d1db229e3b7ca936323ffa2 (patch) | |
tree | 32e57172bd786daed9ac4251b3c5edf09c49d242 /src/ckutil.c | |
parent | 3560d8be4b833e888e8386a3dc641fa164b4b808 (diff) | |
download | ck-eeca7f0151d85d563d1db229e3b7ca936323ffa2.tar.gz ck-eeca7f0151d85d563d1db229e3b7ca936323ffa2.tar.bz2 ck-eeca7f0151d85d563d1db229e3b7ca936323ffa2.zip |
First steps towards adding to the db
Diffstat (limited to 'src/ckutil.c')
-rw-r--r-- | src/ckutil.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ckutil.c b/src/ckutil.c new file mode 100644 index 0000000..fc6d4b0 --- /dev/null +++ b/src/ckutil.c @@ -0,0 +1,54 @@ +/* ckutil.c - utility functions for ck ---------------------------------*- C -*- + * + * This file is part of ck, the config keeper + * + * ----------------------------------------------------------------------------- + * + * Copyright (C) 2018 Anastasis Grammenos + * GPLv3 (see LICENCE for the full notice) + * + * -------------------------------------------------------------------------- */ +#include <dirent.h> +#include <ctype.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "ckutil.h" + +int util_is_dir(const char *path) { + DIR *dir; + dir = opendir(path); + if (!dir) { + return 0; + } + closedir(dir); + return 1; +} + +int util_is_str_empty(const char *s) { + while (*s != '\0') { + if (!isspace((unsigned char)*s)) + return 0; + s++; + } + return 1; +} + +int util_file_exists(const char* path) { + struct stat st = {0}; + if (stat(path, &st) == -1) { + return 0; + } + return 1; +} + +int util_is_file_rw(const char* path) { + if (access(path, R_OK | W_OK) == 0) { + return 1; + } + return 0; +} + +void util_mkdir(const char *name) { + mkdir(name, 0755); +} |