/*
* Copyright (C) 2017 Aaron M. D. Jones <aaronmdjones@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef INC_LIBACOPM_COMMON_H
#define INC_LIBACOPM_COMMON_H
#include <stdarg.h> /* va_list, va_*(), vfprintf(), vsprintf(), vsnprintf() */
#include <stdbool.h> /* true, false */
#include <stddef.h> /* NULL, size_t */
#include <stdio.h> /* snprintf() */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, uint64_t */
#include <stdlib.h> /* abort(), getenv(), calloc(), malloc(), realloc(), free(), strtoul(), EXIT_* */
#ifdef HAVE_CONFIG_H
# include "acopm-config.h"
#endif
#ifndef PACKAGE_NAME
# define PACKAGE_NAME "ACOPM"
#endif
#ifndef PACKAGE_TARNAME
# define PACKAGE_TARNAME "acopm"
#endif
#ifndef SYSCONFDIR
# define SYSCONFDIR "/etc"
#endif
#define ACOPM_CONFIG_FILE_DEFAULT SYSCONFDIR "/" PACKAGE_TARNAME ".conf"
#ifndef BUILD_WITH_DEBUG
# define NDEBUG 1 /* remove acopm_log_debug() calls, make assert(3) a no-op, etc */
#else
# ifdef NDEBUG
# undef NDEBUG /* NDEBUG was defined but not by our build system -- remove it */
# endif
#endif
#define INET_ADDRLEN 4U /* # octets in raw IPv4 address */
#define INET6_ADDRLEN 16U /* # octets in raw IPv6 address */
#define acopm_attr_inline __attribute__((always_inline))
#define acopm_attr_malloc __attribute__((malloc))
#define acopm_attr_noreturn __attribute__((noreturn))
#define acopm_attr_packed __attribute__((packed))
#define acopm_attr_printf(f, s) __attribute__((format(printf, (f), (s))))
#define acopm_attr_pure __attribute__((pure))
#define acopm_attr_unused __attribute__((unused))
#define acopm_attr_warn_unused __attribute__((warn_unused_result))
#define acopm_strset_len(b, s, v) ((snprintf((b), (s), "%s", (v)) >= (int) (s)) ? false : true)
#define acopm_strset_buf(b, v) acopm_strset_len((b), sizeof (b), (v))
#endif /* !INC_LIBACOPM_COMMON_H */