]> git.sven.stormbind.net Git - sven/exfat-utils.git/blob - libexfat/log.c
New upstream version 1.3.0
[sven/exfat-utils.git] / libexfat / log.c
1 /*
2         log.c (02.09.09)
3         exFAT file system implementation library.
4
5         Free exFAT implementation.
6         Copyright (C) 2010-2018  Andrew Nayenko
7
8         This program is free software; you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 2 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License along
19         with this program; if not, write to the Free Software Foundation, Inc.,
20         51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include "exfat.h"
24 #include <stdarg.h>
25 #ifdef __ANDROID__
26 #include <android/log.h>
27 #else
28 #include <syslog.h>
29 #endif
30 #include <unistd.h>
31
32 int exfat_errors;
33
34 /*
35  * This message means an internal bug in exFAT implementation.
36  */
37 void exfat_bug(const char* format, ...)
38 {
39         va_list ap, aq;
40
41         va_start(ap, format);
42         va_copy(aq, ap);
43
44         fflush(stdout);
45         fputs("BUG: ", stderr);
46         vfprintf(stderr, format, ap);
47         va_end(ap);
48         fputs(".\n", stderr);
49
50 #ifdef __ANDROID__
51         __android_log_vprint(ANDROID_LOG_FATAL, PACKAGE, format, aq);
52 #else
53         if (!isatty(STDERR_FILENO))
54                 vsyslog(LOG_CRIT, format, aq);
55 #endif
56         va_end(aq);
57
58         abort();
59 }
60
61 /*
62  * This message means an error in exFAT file system.
63  */
64 void exfat_error(const char* format, ...)
65 {
66         va_list ap, aq;
67
68         exfat_errors++;
69         va_start(ap, format);
70         va_copy(aq, ap);
71
72         fflush(stdout);
73         fputs("ERROR: ", stderr);
74         vfprintf(stderr, format, ap);
75         va_end(ap);
76         fputs(".\n", stderr);
77
78 #ifdef __ANDROID__
79         __android_log_vprint(ANDROID_LOG_ERROR, PACKAGE, format, aq);
80 #else
81         if (!isatty(STDERR_FILENO))
82                 vsyslog(LOG_ERR, format, aq);
83 #endif
84         va_end(aq);
85 }
86
87 /*
88  * This message means that there is something unexpected in exFAT file system
89  * that can be a potential problem.
90  */
91 void exfat_warn(const char* format, ...)
92 {
93         va_list ap, aq;
94
95         va_start(ap, format);
96         va_copy(aq, ap);
97
98         fflush(stdout);
99         fputs("WARN: ", stderr);
100         vfprintf(stderr, format, ap);
101         va_end(ap);
102         fputs(".\n", stderr);
103
104 #ifdef __ANDROID__
105         __android_log_vprint(ANDROID_LOG_WARN, PACKAGE, format, aq);
106 #else
107         if (!isatty(STDERR_FILENO))
108                 vsyslog(LOG_WARNING, format, aq);
109 #endif
110         va_end(aq);
111 }
112
113 /*
114  * Just debug message. Disabled by default.
115  */
116 void exfat_debug(const char* format, ...)
117 {
118         va_list ap;
119
120         fflush(stdout);
121         fputs("DEBUG: ", stderr);
122         va_start(ap, format);
123         vfprintf(stderr, format, ap);
124         va_end(ap);
125         fputs(".\n", stderr);
126 }