libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

extractor_logging.h
Go to the documentation of this file.
1 /*
2  This file is part of libextractor.
3  Copyright (C) 2012 Vidyut Samanta and Christian Grothoff
4 
5  libextractor is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published
7  by the Free Software Foundation; either version 3, or (at your
8  option) any later version.
9 
10  libextractor is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with libextractor; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19  */
20 /**
21  * @file main/extractor_logging.h
22  * @brief logging API for GNU libextractor
23  * @author Christian Grothoff
24  */
25 #ifndef EXTRACTOR_LOGGING_H
26 #define EXTRACTOR_LOGGING_H
27 
28 #define DEBUG 0
29 
30 #if DEBUG
31 
32 /**
33  * Log function.
34  *
35  * @param file name of file with the error
36  * @param line line number with the error
37  * @param ... log message and arguments
38  */
39 void
40 EXTRACTOR_log_ (const char *file, int line, const char *format, ...);
41 
42 /**
43  * Log a message.
44  *
45  * @param ... format string and arguments for fmt (printf-style)
46  */
47 #define LOG(...) EXTRACTOR_log_ (__FILE__, __LINE__, __VA_ARGS__)
48 
49 #else
50 
51 /**
52  * Log a message.
53  *
54  * @param ... format string and arguments for fmt (printf-style)
55  */
56 #define LOG(...)
57 
58 #endif
59 
60 
61 /**
62  * Log an error message about a failed system/libc call
63  * using an error message based on 'errno'.
64  *
65  * @param syscall name of the syscall that failed
66  */
67 #define LOG_STRERROR(syscall) LOG ("System call `%s' failed: %s\n", syscall, \
68  STRERROR (errno))
69 
70 
71 /**
72  * Log an error message about a failed system/libc call
73  * involving a file using an error message based on 'errno'.
74  *
75  * @param syscall name of the syscall that failed
76  * @param filename name of the file that was involved
77  */
78 #define LOG_STRERROR_FILE(syscall,filename) LOG ( \
79  "System call `%s' failed for file `%s': %s\n", syscall, filename, STRERROR ( \
80  errno))
81 
82 
83 /**
84  * Abort the program reporting an assertion failure
85  *
86  * @param file filename with the failure
87  * @param line line number with the failure
88  */
89 void
90 EXTRACTOR_abort_ (const char *file,
91  int line);
92 
93 
94 /**
95  * Abort program if assertion fails.
96  *
97  * @param cond assertion that must hold.
98  */
99 #define ASSERT(cond) do { if (! (cond)) EXTRACTOR_abort_ (__FILE__, __LINE__); \
100 } while (0)
101 
102 
103 #endif
void EXTRACTOR_abort_(const char *file, int line)