libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

extractor_logging.h (2766B)


      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 /* for strerror() in the LOG_STRERROR* macros below */
     29 #include <string.h>
     30 
     31 #define DEBUG 0
     32 
     33 #if DEBUG
     34 
     35 /**
     36  * Log function.
     37  *
     38  * @param file name of file with the error
     39  * @param line line number with the error
     40  * @param ... log message and arguments
     41  */
     42 void
     43 EXTRACTOR_log_ (const char *file, int line, const char *format, ...);
     44 
     45 /**
     46  * Log a message.
     47  *
     48  * @param ... format string and arguments for fmt (printf-style)
     49  */
     50 #define LOG(...) EXTRACTOR_log_ (__FILE__, __LINE__, __VA_ARGS__)
     51 
     52 #else
     53 
     54 /**
     55  * Log a message.
     56  *
     57  * @param ... format string and arguments for fmt (printf-style)
     58  */
     59 #define LOG(...)
     60 
     61 #endif
     62 
     63 
     64 /**
     65  * Log an error message about a failed system/libc call
     66  * using an error message based on 'errno'.
     67  *
     68  * @param syscall name of the syscall that failed
     69  */
     70 #define LOG_STRERROR(syscall) LOG ("System call `%s' failed: %s\n", syscall, \
     71                                    strerror (errno))
     72 
     73 
     74 /**
     75  * Log an error message about a failed system/libc call
     76  * involving a file using an error message based on 'errno'.
     77  *
     78  * @param syscall name of the syscall that failed
     79  * @param filename name of the file that was involved
     80  */
     81 #define LOG_STRERROR_FILE(syscall,filename) LOG ( \
     82           "System call `%s' failed for file `%s': %s\n", syscall, filename, \
     83           strerror ( \
     84             errno))
     85 
     86 
     87 /**
     88  * Abort the program reporting an assertion failure
     89  *
     90  * @param file filename with the failure
     91  * @param line line number with the failure
     92  */
     93 void
     94 EXTRACTOR_abort_ (const char *file,
     95                   int line);
     96 
     97 
     98 /**
     99  * Abort program if assertion fails.
    100  *
    101  * @param cond assertion that must hold.
    102  */
    103 #define ASSERT(cond) do { if (! (cond)) EXTRACTOR_abort_ (__FILE__, __LINE__); \
    104 } while (0)
    105 
    106 
    107 #endif