From eeca7f0151d85d563d1db229e3b7ca936323ffa2 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sun, 22 Apr 2018 05:47:33 +0300 Subject: First steps towards adding to the db --- src/ckutil.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/ckutil.c (limited to 'src/ckutil.c') 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 +#include +#include +#include + +#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); +} -- cgit v1.2.3