error.c 940 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. static const char version[] = "$Id$";
  2. /*
  3. * See the COPYING file for the terms of usage and distribution.
  4. */
  5. #ifdef HAVE_CONFIG_H
  6. #include "config.h"
  7. #endif
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #ifdef HAVE_STDARG_H
  12. # include <stdarg.h>
  13. #else
  14. # ifdef HAVE_VARARGS_H
  15. # include <varargs.h>
  16. # endif
  17. #endif
  18. #include <sd/error.h>
  19. #include <sd/sd_xplatform.h>
  20. int sd_debug(const char *fmt, ...)
  21. {
  22. va_list args;
  23. int r;
  24. if (!getenv("SD_DEBUG"))
  25. return 0;
  26. r = fprintf(stderr, "[DEBUG] ");
  27. va_start(args, fmt);
  28. r += vfprintf(stderr, fmt, args);
  29. va_end(args);
  30. r += fprintf(stderr, "\n");
  31. return r;
  32. }
  33. int sd_error(const char *fmt, ...)
  34. {
  35. va_list args;
  36. int r;
  37. if (!getenv("SD_ERROR"))
  38. return 0;
  39. r = fprintf(stderr, "[ERROR] ");
  40. va_start(args, fmt);
  41. r += vfprintf(stderr, fmt, args);
  42. va_end(args);
  43. r += fprintf(stderr, "\n");
  44. return r;
  45. }