Home | History | Annotate | Line # | Download | only in zone
      1 /*
      2  * attributes.h -- compiler attribute abstractions
      3  *
      4  * Copyright (c) 2022, NLnet Labs. All rights reserved.
      5  *
      6  * SPDX-License-Identifier: BSD-3-Clause
      7  *
      8  */
      9 #ifndef ZONE_ATTRIBUTES_H
     10 #define ZONE_ATTRIBUTES_H
     11 
     12 #if defined __GNUC__
     13 # define zone_has_gnuc(major, minor) \
     14     ((__GNUC__ > major) || (__GNUC__ == major && __GNUC_MINOR__ >= minor))
     15 #else
     16 # define zone_has_gnuc(major, minor) (0)
     17 #endif
     18 
     19 #if defined __has_attribute
     20 # define zone_has_attribute(params) __has_attribute(params)
     21 #else
     22 # define zone_has_attribute(params) (0)
     23 #endif
     24 
     25 #if zone_has_attribute(nonnull)
     26 # define zone_nonnull(params) __attribute__((__nonnull__ params))
     27 # define zone_nonnull_all __attribute__((__nonnull__))
     28 #else
     29 # define zone_nonnull(params)
     30 # define zone_nonnull_all
     31 #endif
     32 
     33 #if zone_has_attribute(format) || zone_has_gnuc(2, 4)
     34 # define zone_format(params) __attribute__((__format__ params))
     35 # if __MINGW32__
     36 #   if __MINGW_PRINTF_FORMAT
     37 #     define zone_format_printf(string_index, first_to_check) \
     38         zone_format((__MINGW_PRINTF_FORMAT, string_index, first_to_check))
     39 #   else
     40 #     define zone_format_printf(string_index, first_to_check) \
     41         zone_format((gnu_printf, string_index, first_to_check))
     42 #   endif
     43 # else
     44 #   define zone_format_printf(string_index, first_to_check) \
     45       zone_format((printf, string_index, first_to_check))
     46 # endif
     47 #else
     48 # define zone_format(params)
     49 # define zone_format_printf(string_index, first_to_check)
     50 #endif
     51 
     52 #endif // ZONE_ATTRIBUTES_H
     53