Annotation of acopm/lib/acopm-common.h, Revision 1.1
1.1 ! bountyht 1: /*
! 2: * Copyright (C) 2017 Aaron M. D. Jones <aaronmdjones@gmail.com>
! 3: *
! 4: * Redistribution and use in source and binary forms, with or without
! 5: * modification, are permitted provided that the following
! 6: * conditions are met:
! 7: *
! 8: * 1. Redistributions of source code must retain the above copyright
! 9: * notice, this list of conditions and the following disclaimer.
! 10: *
! 11: * 2. Redistributions in binary form must reproduce the above copyright
! 12: * notice, this list of conditions and the following disclaimer in the
! 13: * documentation and/or other materials provided with the distribution.
! 14: *
! 15: * 3. Neither the name of the copyright holder nor the names of its
! 16: * contributors may be used to endorse or promote products derived from
! 17: * this software without specific prior written permission.
! 18: *
! 19: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
! 20: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 21: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
! 22: * PARTICULAR PURPOSE ARE DISCLAIMED.
! 23: *
! 24: * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
! 25: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! 29: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! 30: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 31: * POSSIBILITY OF SUCH DAMAGE.
! 32: */
! 33:
! 34: #ifndef INC_LIBACOPM_COMMON_H
! 35: #define INC_LIBACOPM_COMMON_H
! 36:
! 37: #include <stdarg.h> /* va_list, va_*(), vfprintf(), vsprintf(), vsnprintf() */
! 38: #include <stdbool.h> /* true, false */
! 39: #include <stddef.h> /* NULL, size_t */
! 40: #include <stdio.h> /* snprintf() */
! 41: #include <stdint.h> /* uint8_t, uint16_t, uint32_t, uint64_t */
! 42: #include <stdlib.h> /* abort(), getenv(), calloc(), malloc(), realloc(), free(), strtoul(), EXIT_* */
! 43:
! 44: #ifdef HAVE_CONFIG_H
! 45: # include "acopm-config.h"
! 46: #endif
! 47:
! 48: #ifndef PACKAGE_NAME
! 49: # define PACKAGE_NAME "ACOPM"
! 50: #endif
! 51:
! 52: #ifndef PACKAGE_TARNAME
! 53: # define PACKAGE_TARNAME "acopm"
! 54: #endif
! 55:
! 56: #ifndef SYSCONFDIR
! 57: # define SYSCONFDIR "/etc"
! 58: #endif
! 59:
! 60: #define ACOPM_CONFIG_FILE_DEFAULT SYSCONFDIR "/" PACKAGE_TARNAME ".conf"
! 61:
! 62: #ifndef BUILD_WITH_DEBUG
! 63: # define NDEBUG 1 /* remove acopm_log_debug() calls, make assert(3) a no-op, etc */
! 64: #else
! 65: # ifdef NDEBUG
! 66: # undef NDEBUG /* NDEBUG was defined but not by our build system -- remove it */
! 67: # endif
! 68: #endif
! 69:
! 70: #define INET_ADDRLEN 4U /* # octets in raw IPv4 address */
! 71: #define INET6_ADDRLEN 16U /* # octets in raw IPv6 address */
! 72:
! 73: #define acopm_attr_inline __attribute__((always_inline))
! 74: #define acopm_attr_malloc __attribute__((malloc))
! 75: #define acopm_attr_noreturn __attribute__((noreturn))
! 76: #define acopm_attr_packed __attribute__((packed))
! 77: #define acopm_attr_printf(f, s) __attribute__((format(printf, (f), (s))))
! 78: #define acopm_attr_pure __attribute__((pure))
! 79: #define acopm_attr_unused __attribute__((unused))
! 80: #define acopm_attr_warn_unused __attribute__((warn_unused_result))
! 81:
! 82: #define acopm_strset_len(b, s, v) ((snprintf((b), (s), "%s", (v)) >= (int) (s)) ? false : true)
! 83: #define acopm_strset_buf(b, v) acopm_strset_len((b), sizeof (b), (v))
! 84:
! 85: #endif /* !INC_LIBACOPM_COMMON_H */
CVSweb