blob: fc6d4b00f92199bfbe0e0dac104636eb4f34aade (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}
|