libexplain  1.4.D001
libexplain/gcc_attributes.h
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2010, 2013 Peter Miller
00004  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or (at
00009  * your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #ifndef LIBEXPLAIN_GCC_ATTRIBUTES_H
00021 #define LIBEXPLAIN_GCC_ATTRIBUTES_H
00022 
00023 #ifdef __GNUC__
00024 #define LIBEXPLAIN_NORETURN __attribute__((noreturn))
00025 #define LIBEXPLAIN_LINKAGE_HIDDEN __attribute__((visibility("hidden")))
00026 #define LIBEXPLAIN_FORMAT_PRINTF(x, y) __attribute__((format(printf, x, y)))
00027 #define LIBEXPLAIN_FORMAT_VPRINTF(x) __attribute__((format(printf, x, 0)))
00028 #else
00029 #define LIBEXPLAIN_NORETURN
00030 #define LIBEXPLAIN_LINKAGE_HIDDEN
00031 #define LIBEXPLAIN_FORMAT_PRINTF(x, y)
00032 #define LIBEXPLAIN_FORMAT_VPRINTF(x)
00033 #endif
00034 
00035 /*
00036  * Convenience macros to test the versions of glibc and gcc.
00037  * Use them like this:
00038  *    #if LIBEXPLAIB_GNUC_PREREQ (2,8)
00039  *    ... code requiring gcc 2.8 or later ...
00040  *    #endif
00041  * Note - they won't work for gcc1 or glibc1, since the _MINOR macros
00042  * were not defined way back then.
00043  */
00044 #if defined __GNUC__ && defined __GNUC_MINOR__
00045 # define LIBEXPLAIN_GNUC_MKREV(maj, min)                              \
00046     (((maj) << 16) | (min))
00047 # define LIBEXPLAIN_GNUC_PREREQ(pmaj, pmin)                           \
00048     (                                                                 \
00049         LIBEXPLAIN_GNUC_MKREV(__GNUC__, __GNUC_MINOR__)               \
00050     >=                                                                \
00051         LIBEXPLAIN_GNUC_MKREV(pmaj, pmin)                             \
00052     )
00053 #else
00054 # define LIBEXPLAIN_GNUC_PREREQ(maj, min) 0
00055 #endif
00056 
00057 #if LIBEXPLAIN_GNUC_PREREQ(3, 0)
00058 # define LIBEXPLAIN_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
00059 #else
00060 # define LIBEXPLAIN_ATTRIBUTE_MALLOC
00061 #endif
00062 
00063 #if LIBEXPLAIN_GNUC_PREREQ(4, 3)
00064 # define LIBEXPLAIN_ATTRIBUTE_ALLOC_SIZE(a1) \
00065     __attribute__ ((__alloc_size__(a1)))
00066 # define LIBEXPLAIN_ATTRIBUTE_ALLOC_SIZE2(a1, a2) \
00067     __attribute__ ((__alloc_size__(a1, a2)))
00068 #else
00069 # define LIBEXPLAIN_ATTRIBUTE_ALLOC_SIZE(a1)
00070 # define LIBEXPLAIN_ATTRIBUTE_ALLOC_SIZE2(a1, a2)
00071 #endif
00072 
00073 
00074 /*
00075  * We attach this attribute to functions that should never have their
00076  * return value ignored.  Amongst other things, this can detect the case
00077  * where the client has called explain_fubar when they meant to call
00078  * explain_fubar_or_die instead.
00079  */
00080 #if LIBEXPLAIN_GNUC_PREREQ(3, 4)
00081 #define LIBEXPLAIN_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
00082 #else
00083 #define LIBEXPLAIN_WARN_UNUSED_RESULT
00084 #endif
00085 
00086 #endif /* LIBEXPLAIN_GCC_ATTRIBUTES_H */
00087 /* vim: set ts=8 sw=4 et : */