rm-rf: introduce rm_rf_safe() and rm_rf_safep()
This commit is contained in:
+16
-4
@@ -34,8 +34,20 @@ static inline int rm_rf(const char *path, RemoveFlags flags) {
|
||||
return rm_rf_at(AT_FDCWD, path, flags);
|
||||
}
|
||||
|
||||
/* Useful for usage with _cleanup_(), destroys a directory and frees the pointer */
|
||||
static inline char *rm_rf_physical_and_free(char *p) {
|
||||
/* Useful for using with _cleanup_(), destroys a directory on a temporary file system. */
|
||||
static inline const char* rm_rf_safe(const char *p) {
|
||||
PROTECT_ERRNO;
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
(void) rm_rf(p, REMOVE_ROOT|REMOVE_MISSING_OK|REMOVE_CHMOD);
|
||||
return NULL;
|
||||
}
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(const char*, rm_rf_safe);
|
||||
|
||||
/* Similar as above, but allow to destroy a directory on a physical file system, and also frees the pointer. */
|
||||
static inline char* rm_rf_physical_and_free(char *p) {
|
||||
PROTECT_ERRNO;
|
||||
|
||||
if (!p)
|
||||
@@ -46,8 +58,8 @@ static inline char *rm_rf_physical_and_free(char *p) {
|
||||
}
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, rm_rf_physical_and_free);
|
||||
|
||||
/* Similar as above, but also has magic btrfs subvolume powers */
|
||||
static inline char *rm_rf_subvolume_and_free(char *p) {
|
||||
/* Similar as above, but also has magic btrfs subvolume powers. */
|
||||
static inline char* rm_rf_subvolume_and_free(char *p) {
|
||||
PROTECT_ERRNO;
|
||||
|
||||
if (!p)
|
||||
|
||||
Reference in New Issue
Block a user