diff options
author | Martin Pärtel <martin.partel@gmail.com> | 2012-07-03 11:16:22 +0300 |
---|---|---|
committer | Martin Pärtel <martin.partel@gmail.com> | 2012-07-03 11:16:22 +0300 |
commit | 99003bc33fa71dfd91bafdbcc8b563f396d1bb52 (patch) | |
tree | 8561028cad620a26ad412d6e0fc5b582cd3d7cfe /src/debug.h | |
parent | 6feab338aed1ad390ba4b0042f0490c7e317c7e3 (diff) | |
download | bindfs-99003bc33fa71dfd91bafdbcc8b563f396d1bb52.tar.gz |
Made strerror() safe to use in DPRINTF.
Diffstat (limited to 'src/debug.h')
-rw-r--r-- | src/debug.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/debug.h b/src/debug.h index 1883101..661c299 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,5 +1,5 @@ /* - Copyright 2006,2007,2008 Martin Pärtel <martin.partel@gmail.com> + Copyright 2006,2007,2008,2012 Martin Pärtel <martin.partel@gmail.com> This file is part of bindfs. @@ -21,10 +21,20 @@ #define INC_BINDFS_DEBUG_H #include <config.h> +#include <string.h> +#include <stdio.h> +#include <pthread.h> + +/* Handier to lock and use strerror() than allocate buffer for strerror_r(). */ +extern pthread_mutex_t strerror_lock; #if BINDFS_DEBUG #include <stdio.h> -#define DPRINTF(fmt, ...) fprintf(stderr, "DEBUG: " fmt "\n", __VA_ARGS__) +#define DPRINTF(fmt, ...) do { \ + pthread_mutex_lock(&strerror_lock); \ + fprintf(stderr, "DEBUG: " fmt "\n", __VA_ARGS__); \ + pthread_mutex_unlock(&strerror_lock); \ + } while (0) #else #define DPRINTF(...) #endif |