From c06d284b7016a02d33294be5793febd05e52839d Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 16 Jul 2023 12:12:49 +0200 Subject: [PATCH] Minor changes --- src/utils.c | 10 ++++++++++ src/utils.h | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/utils.c b/src/utils.c index 909655e..832cc9b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -4,4 +4,14 @@ void mkdirp(char *path){ char buffer[255]="mkdir -p "; strcat(buffer,path); system(buffer); +} + +unsigned char dir_exists(char *path){ + DIR* dir = opendir(path); + if (dir) { + /* Directory exists. */ + closedir(dir); + return 1; + } + return 0; } \ No newline at end of file diff --git a/src/utils.h b/src/utils.h index 6c5741c..fafe99b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -4,6 +4,7 @@ #include #include #include +#include #define MIN_INTERVAL 30 #define INA260_SYSFS "/sys/kernel/ina260" @@ -28,5 +29,7 @@ #define INTERVAL_LAST(duration)\ (INTERVAL(INTERVAL((TIMESTAMP()),(duration))-1,(duration))) #define FILE_EXISTS(path) (access((path), F_OK) == 0) +#define DIR_EXISTS(path) (dir_exists(path)) -void mkdirp(char *path); \ No newline at end of file +void mkdirp(char *path); +unsigned char dir_exists(char *path); \ No newline at end of file