From 84f1e50cb1a959f3a835b8ba265159cc6e75635a Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 31 Dec 2023 00:36:01 +0530 Subject: pass/rm: init --- util.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 14dfeaa..8e3a108 100644 --- a/util.c +++ b/util.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "util.h" @@ -33,6 +35,25 @@ int r_mkdir(const char *path, mode_t mode) return mkdir(path, mode); } +int r_rmdir(const char *prefix_path, char *rm_path) +{ + int r; + char abs_path[PATH_MAX]; + + if (!strcmp(rm_path, ".")) + return 0; + + r = snprintf(abs_path, sizeof(abs_path), "%s/%s", prefix_path, rm_path); + if (r > (int) sizeof(abs_path)) + err_die(1, "path exceeded PATH_MAX"); + + r = rmdir(abs_path); + if (r && errno != EEXIST && errno != ENOTEMPTY) + err_die(1, "%s", strerror(errno)); + + return r_rmdir(prefix_path, dirname(rm_path)); +} + void util_strtrim(char *s) { char *rend; -- cgit v1.2.3