error.c 952 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * See the COPYING file for the terms of usage and distribution.
  3. */
  4. #ifdef HAVE_CONFIG_H
  5. #include "config.h"
  6. #endif
  7. #include <tchar.h>
  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. static const TCHAR version[] = _T("$Id$");
  21. int sd_debug(const TCHAR *fmt, ...)
  22. {
  23. va_list args;
  24. int r;
  25. if (!_tgetenv(_T("SD_DEBUG")))
  26. return 0;
  27. r = _ftprintf(stderr, _T("[DEBUG] "));
  28. va_start(args, fmt);
  29. r += _vftprintf(stderr, fmt, args);
  30. va_end(args);
  31. r += _ftprintf(stderr, _T("\n"));
  32. return r;
  33. }
  34. int sd_error(const TCHAR *fmt, ...)
  35. {
  36. va_list args;
  37. int r;
  38. if (!_tgetenv(_T("SD_ERROR")))
  39. return 0;
  40. r = _ftprintf(stderr, _T("[ERROR] "));
  41. va_start(args, fmt);
  42. r += _vftprintf(stderr, fmt, args);
  43. va_end(args);
  44. r += _ftprintf(stderr, _T("\n"));
  45. return r;
  46. }