log.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. log.c (02.09.09)
  3. exFAT file system implementation library.
  4. Copyright (C) 2010-2013 Andrew Nayenko
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "exfat.h"
  17. #include <stdarg.h>
  18. #include <syslog.h>
  19. #include <unistd.h>
  20. int exfat_errors;
  21. /*
  22. * This message means an internal bug in exFAT implementation.
  23. */
  24. void exfat_bug(const char* format, ...)
  25. {
  26. va_list ap, aq;
  27. va_start(ap, format);
  28. va_copy(aq, ap);
  29. fflush(stdout);
  30. fputs("BUG: ", stderr);
  31. vfprintf(stderr, format, ap);
  32. va_end(ap);
  33. fputs(".\n", stderr);
  34. if (!isatty(STDERR_FILENO))
  35. vsyslog(LOG_CRIT, format, aq);
  36. va_end(aq);
  37. abort();
  38. }
  39. /*
  40. * This message means an error in exFAT file system.
  41. */
  42. void exfat_error(const char* format, ...)
  43. {
  44. va_list ap, aq;
  45. exfat_errors++;
  46. va_start(ap, format);
  47. va_copy(aq, ap);
  48. fflush(stdout);
  49. fputs("ERROR: ", stderr);
  50. vfprintf(stderr, format, ap);
  51. va_end(ap);
  52. fputs(".\n", stderr);
  53. if (!isatty(STDERR_FILENO))
  54. vsyslog(LOG_ERR, format, aq);
  55. va_end(aq);
  56. }
  57. /*
  58. * This message means that there is something unexpected in exFAT file system
  59. * that can be a potential problem.
  60. */
  61. void exfat_warn(const char* format, ...)
  62. {
  63. va_list ap, aq;
  64. va_start(ap, format);
  65. va_copy(aq, ap);
  66. fflush(stdout);
  67. fputs("WARN: ", stderr);
  68. vfprintf(stderr, format, ap);
  69. va_end(ap);
  70. fputs(".\n", stderr);
  71. if (!isatty(STDERR_FILENO))
  72. vsyslog(LOG_WARNING, format, aq);
  73. va_end(aq);
  74. }
  75. /*
  76. * Just debug message. Disabled by default.
  77. */
  78. void exfat_debug(const char* format, ...)
  79. {
  80. va_list ap;
  81. fflush(stdout);
  82. fputs("DEBUG: ", stderr);
  83. va_start(ap, format);
  84. vfprintf(stderr, format, ap);
  85. va_end(ap);
  86. fputs(".\n", stderr);
  87. }