diff --git a/mx_util.h b/mx_util.h index bf31f4ee..409c31a1 100644 --- a/mx_util.h +++ b/mx_util.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "mx_log.h" @@ -55,12 +56,20 @@ static inline void __mx_fclose(FILE **ptr) { fclose(*ptr); } +static inline void __mx_closedir(DIR **ptr) { + if (*ptr) + closedir(*ptr); +} + #undef _mx_cleanup_free_ #define _mx_cleanup_free_ _mx_cleanup_(__mx_free) #undef _mx_cleanup_fclose_ #define _mx_cleanup_fclose_ _mx_cleanup_(__mx_fclose) +#undef _mx_cleanup_closedir_ +#define _mx_cleanup_closedir_ _mx_cleanup_(__mx_closedir) + #undef likely #define likely(x) __builtin_expect((x),1)