Skip to content

Commit

Permalink
Update: util.c
Browse files Browse the repository at this point in the history
  • Loading branch information
rxxuzi committed Apr 29, 2024
1 parent 9efc401 commit 0e6c736
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
#include <dirent.h>
#include <sys/stat.h>

static struct stat buffer;

int file_exists(const char *path) {
return (stat(path, &buffer) == 0);
}

int dir_exists(const char *path) {
return (stat(path, &buffer) == 0 && S_ISDIR(buffer.st_mode));
}

int remove_directory(const char *path) {
DIR *d = opendir(path);
size_t path_len = strlen(path);
Expand Down
4 changes: 4 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#ifndef UTIL_H
#define UTIL_H

int file_exists(const char *path);
int directory_exists(const char *path);

int remove_directory(const char *path);
void refresh_dir(const char *path);
#endif //UTIL_H

0 comments on commit 0e6c736

Please sign in to comment.