xsum_output.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * xxhsum - Command line interface for xxhash algorithms
  3. * Copyright (C) 2013-2021 Yann Collet
  4. *
  5. * GPL v2 License
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * You can contact the author at:
  22. * - xxHash homepage: https://www.xxhash.com
  23. * - xxHash source repository: https://github.com/Cyan4973/xxHash
  24. */
  25. #include "xsum_output.h"
  26. #include "xsum_os_specific.h" /* XSUM_API */
  27. int XSUM_logLevel = 2;
  28. XSUM_ATTRIBUTE((__format__(__printf__, 1, 2)))
  29. XSUM_API int XSUM_log(const char* format, ...)
  30. {
  31. int ret;
  32. va_list ap;
  33. va_start(ap, format);
  34. ret = XSUM_vfprintf(stderr, format, ap);
  35. va_end(ap);
  36. return ret;
  37. }
  38. XSUM_ATTRIBUTE((__format__(__printf__, 1, 2)))
  39. XSUM_API int XSUM_output(const char* format, ...)
  40. {
  41. int ret;
  42. va_list ap;
  43. va_start(ap, format);
  44. ret = XSUM_vfprintf(stdout, format, ap);
  45. va_end(ap);
  46. return ret;
  47. }
  48. XSUM_ATTRIBUTE((__format__(__printf__, 2, 3)))
  49. XSUM_API int XSUM_logVerbose(int minLevel, const char* format, ...)
  50. {
  51. if (XSUM_logLevel >= minLevel) {
  52. int ret;
  53. va_list ap;
  54. va_start(ap, format);
  55. ret = XSUM_vfprintf(stderr, format, ap);
  56. va_end(ap);
  57. return ret;
  58. }
  59. return 0;
  60. }