Move Sprintf,Dputs,Dprintf,Dperror to be defines and call proper

non-inlined functions which are now in debug.c.

(Logical change 1.503)
edge.strict_endians
cantab.net!aia21 2004-08-19 21:01:11 +00:00
parent d33e7eaae4
commit 39b62e050e
2 changed files with 75 additions and 58 deletions

View File

@ -33,77 +33,34 @@
#endif
#include <errno.h>
#include "types.h"
struct _runlist_element;
/**
* Sprintf - silencable output to stderr
* @silent: if false string is output to stderr
* @fmt: printf style format string
* @...: optional arguments for the printf style format string
*
* If @silent is false, output the string @fmt to stderror.
*
* This is basically a replacelment for:
*
* if (!silent)
* fprintf(stderr, fmt, ...);
*
* It is more convenient to use Sprintf instead of the above code and perhaps
* more importantly, Sprintf makes it much easier to turn it into a "do
* nothing" function with an #ifdef, thus removing the whole output completely.
*/
static __inline__ void Sprintf(const BOOL silent, const char *fmt, ...)
{
int eo;
va_list ap;
if (silent)
return;
eo = errno;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
errno = eo;
}
extern void __Sprintf(const int silent, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
#define Sprintf(silent, f, a...) __Sprintf(silent, f, ##a)
#ifdef DEBUG
/* Debug output to stderr. To get it run ./configure --enable-debug. */
static __inline__ void Dprintf(const char *fmt, ...)
{
int eo = errno;
va_list ap;
extern void __Dprintf(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
#define Dprintf(f, a...) __Dprintf(f, ##a)
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
errno = eo;
}
extern void __Dputs(const char *s);
#define Dputs(s) __Dputs(s)
static __inline__ void Dputs(const char *s)
{
int eo = errno;
fprintf(stderr, "%s\n", s);
errno = eo;
}
static __inline__ void Dperror(const char *s)
{
int eo = errno;
perror(s);
errno = eo;
}
extern void __Dperror(const char *s);
#define Dperror(s) __Dperror(s)
extern void ntfs_debug_runlist_dump(const struct _runlist_element *rl);
#else /* if !DEBUG */
static __inline__ void Dprintf(const char *fmt __attribute__((unused)), ...) {}
static __inline__ void Dputs(const char *s __attribute__((unused))) {}
static __inline__ void Dperror(const char *s __attribute__((unused))) {}
#define Dprintf(f, a...) do {} while (0)
#define Dputs(s) do {} while (0)
#define Dperror(s) do {} while (0)
static __inline__ void ntfs_debug_runlist_dump(const struct _runlist_element *rl __attribute__((unused))) {}
#endif /* !DEBUG */

View File

@ -21,10 +21,71 @@
#include "config.h"
#include "types.h"
#include "attrib.h"
#include "debug.h"
/**
* Sprintf - silencable output to stderr
* @silent: if 0 string is output to stderr
* @fmt: printf style format string
* @...: optional arguments for the printf style format string
*
* If @silent is 0, output the string @fmt to stderr.
*
* This is basically a replacement for:
*
* if (!silent)
* fprintf(stderr, fmt, ...);
*
* It is more convenient to use Sprintf instead of the above code and perhaps
* more importantly, Sprintf makes it much easier to turn it into a "do
* nothing" function, by defining it to "do {} while (0)" in debug.h instead of
* to * __Sprintf, thus removing the whole output completely.
*/
void __Sprintf(const int silent, const char *fmt, ...)
{
int eo;
va_list ap;
if (silent)
return;
eo = errno;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
errno = eo;
}
#ifdef DEBUG
/* Debug output to stderr. To get it run ./configure --enable-debug. */
void __Dprintf(const char *fmt, ...)
{
int eo = errno;
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
errno = eo;
}
void __Dputs(const char *s)
{
int eo = errno;
fprintf(stderr, "%s\n", s);
errno = eo;
}
void __Dperror(const char *s)
{
int eo = errno;
perror(s);
errno = eo;
}
/**
* ntfs_debug_runlist_dump - Dump a runlist.
*/
@ -60,4 +121,3 @@ void ntfs_debug_runlist_dump(const runlist_element *rl)
}
#endif