Skip to content

Commit

Permalink
mx_util: Add _mx_cleanup_closedir_
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Aug 24, 2021
1 parent 63fa968 commit 3225c82
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mx_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sched.h>
#include <unistd.h>
#include <sys/time.h>
#include <dirent.h>

#include "mx_log.h"

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 3225c82

Please sign in to comment.