From d6fc63d0b18bcc8da36b2fc1bba73349b83afe1f Mon Sep 17 00:00:00 2001 From: "cantab.net!aia21" Date: Thu, 9 Sep 2004 07:54:06 +0000 Subject: [PATCH] Add ntfs_debug() and ntfs_error() to make kernel<->userspace porting easier. (Logical change 1.538) --- include/ntfs/debug.h | 12 ++++++++++++ libntfs/debug.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/ntfs/debug.h b/include/ntfs/debug.h index fc14333c..1652ba62 100644 --- a/include/ntfs/debug.h +++ b/include/ntfs/debug.h @@ -43,6 +43,15 @@ extern void __Sprintf(const int silent, const char *fmt, ...) /* Debug output to stderr. To get it run ./configure --enable-debug. */ +extern void __ntfs_debug (const char *file, int line, const char *function, + const char *format, ...) __attribute__((format(printf, 4, 5))); +#define ntfs_debug(f, a...) \ + __ntfs_debug(__FILE__, __LINE__, __FUNCTION__, f, ##a) + +extern void __ntfs_error(const char *function, + const char *fmt, ...) __attribute__((format(printf, 3, 4))); +#define ntfs_error(sb, f, a...) __ntfs_error(__FUNCTION__, f, ##a) + extern void __Dprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); #define Dprintf(f, a...) __Dprintf(f, ##a) @@ -57,6 +66,9 @@ extern void ntfs_debug_runlist_dump(const struct _runlist_element *rl); #else /* if !DEBUG */ +#define ntfs_debug(f, a...) do {} while (0) +#define ntfs_error(f, a...) do {} while (0) + #define Dprintf(f, a...) do {} while (0) #define Dputs(s) do {} while (0) #define Dperror(s) do {} while (0) diff --git a/libntfs/debug.c b/libntfs/debug.c index af355811..55008543 100644 --- a/libntfs/debug.c +++ b/libntfs/debug.c @@ -61,6 +61,41 @@ void __Sprintf(const int silent, const char *fmt, ...) /* Debug output to stderr. To get it run ./configure --enable-debug. */ +void __ntfs_error(const char *function, const char *fmt, ...) +{ + int eo = errno; + int flen = 0; + va_list args; + char err_buf[1024]; + + if (function) + flen = strlen(function); + va_start(args, fmt); + vsnprintf(err_buf, sizeof(err_buf), fmt, args); + va_end(args); + fprintf(stderr, "NTFS error: %s(): %s\n", flen ? function : "", + err_buf); + errno = eo; +} + +void __ntfs_debug (const char *file, int line, const char *function, + const char *fmt, ...) +{ + int eo = errno; + int flen = 0; + va_list args; + char err_buf[1024]; + + if (function) + flen = strlen(function); + va_start(args, fmt); + vsnprintf(err_buf, sizeof(err_buf), fmt, args); + va_end(args); + fprintf(stderr, "NTFS DEBUG (%s, %d): %s(): %s\n", file, line, + flen ? function : "", err_buf); + errno = eo; +} + void __Dprintf(const char *fmt, ...) { int eo = errno;