Skip to content

Commit

Permalink
Write is_open
Browse files Browse the repository at this point in the history
  • Loading branch information
charmoniumQ committed Jan 21, 2025
1 parent 9aa1136 commit f961abf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libprobe/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,39 @@ static void __debug_stack_indent() {
curr = curr->tail;
}
}
static bool is_open(FILE* file) {
int stored_errno = errno;
errno = 0;
int ret = unwrapped_fcntl(fileno(file), F_GETFD) != -1 && errno == 0;
errno = stored_errno;
return ret;
}
#define DEBUG(...) ({ \
if (is_open(stderr)) { \
__debug_stack_indent(); \
__LOG_PID(); \
__LOG_SOURCE(); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} \
})
#define ENTER(op, ...) ({ \
if (is_open(stderr)) { \
__debug_stack_indent(); \
__LOG_PID(); \
__LOG_SOURCE(); \
fprintf(stderr, "> %s\n", op); \
__debug_stack_enter(op); \
} \
})
#define EXIT(op) ({ \
if (is_open(stderr)) { \
__debug_stack_exit(op); \
__debug_stack_indent(); \
__LOG_PID(); \
__LOG_SOURCE(); \
fprintf(stderr, "< %s\n", op); \
} \
})
#else
#define DEBUG(...)
Expand Down

0 comments on commit f961abf

Please sign in to comment.