Blame snprintfv/compat.h

Packit Service 96b5d3
/*  -*- Mode: C -*-
Packit Service 96b5d3
 * --------------------------------------------------------------------
Packit Service 96b5d3
 * compat.h.in --- verbose but portable cpp defines for snprintfv
Packit Service 96b5d3
 * Copyright (C) 1999 Gary V. Vaughan
Packit Service 96b5d3
 * Originally by Gary V. Vaughan, 1999
Packit Service 96b5d3
 * This file is part of Snprintfv
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Snprintfv is free software; you can redistribute it and/or
Packit Service 96b5d3
 * modify it under the terms of the GNU General Public License as
Packit Service 96b5d3
 * published by the Free Software Foundation; either version 2 of the
Packit Service 96b5d3
 * License, or (at your option) any later version.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Snprintfv program is distributed in the hope that it will be useful,
Packit Service 96b5d3
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 96b5d3
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 96b5d3
 * General Public License for more details.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * You should have received a copy of the GNU General Public License
Packit Service 96b5d3
 * along with this program.  If not, see <http://www.gnu.org/licenses>.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * As a special exception to the GNU General Public License, if you
Packit Service 96b5d3
 * distribute this file as part of a program that also links with and
Packit Service 96b5d3
 * uses the libopts library from AutoGen, you may include it under
Packit Service 96b5d3
 * the same distribution terms used by the libopts library.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Code:  */
Packit Service 96b5d3
Packit Service 96b5d3
#ifndef SNPRINTFV_COMPAT_H
Packit Service 96b5d3
#define SNPRINTFV_COMPAT_H 1
Packit Service 96b5d3
Packit Service 96b5d3
#define  _GNU_SOURCE    1 /* for strsignal in GNU's libc */
Packit Service 96b5d3
#define  __USE_GNU      1 // likewise
Packit Service 96b5d3
#define  __EXTENSIONS__ 1 /* and another way to call for it */
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef __cplusplus
Packit Service 96b5d3
#define SNV_START_EXTERN_C extern "C" {
Packit Service 96b5d3
SNV_START_EXTERN_C
Packit Service 96b5d3
#define SNV_END_EXTERN_C }
Packit Service 96b5d3
#else
Packit Service 96b5d3
#define SNV_END_EXTERN_C
Packit Service 96b5d3
#endif /* __cplusplus */
Packit Service 96b5d3
Packit Service 96b5d3
#define NO_FLOAT_PRINTING
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef HAVE_SYS_TYPES_H
Packit Service 96b5d3
#  include <sys/types.h>
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#include <stdio.h>
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef HAVE_STDLIB_H
Packit Service 96b5d3
#  include <stdlib.h>
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef HAVE_ERRNO_H
Packit Service 96b5d3
#  include <errno.h>
Packit Service 96b5d3
#  ifndef errno
Packit Service 96b5d3
     /* Some sytems #define this! */
Packit Service 96b5d3
     extern int errno;
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#if defined( HAVE_LIMITS_H )
Packit Service 96b5d3
#  include <limits.h>
Packit Service 96b5d3
Packit Service 96b5d3
#elif defined( HAVE_SYS_LIMITS_H )
Packit Service 96b5d3
#  include <sys/limits.h>
Packit Service 96b5d3
Packit Service 96b5d3
#elif defined( HAVE_VALUES_H )
Packit Service 96b5d3
#  ifndef MAXINT
Packit Service 96b5d3
#    include <values.h>
Packit Service 96b5d3
#  endif /* MAXINT */
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#if defined( HAVE_STRING_H )
Packit Service 96b5d3
#  include <string.h>
Packit Service 96b5d3
Packit Service 96b5d3
#elif defined( HAVE_STRINGS_H )
Packit Service 96b5d3
#  include <strings.h>
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#if defined( HAVE_MEMORY_H )
Packit Service 96b5d3
#  include <memory.h>
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#if defined( HAVE_INTTYPES_H )
Packit Service 96b5d3
#  include <inttypes.h>
Packit Service 96b5d3
Packit Service 96b5d3
#elif defined( HAVE_STDINT_H )
Packit Service 96b5d3
#  include <stdint.h>
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifndef HAVE_UINTMAX_T
Packit Service 96b5d3
#  if defined( HAVE_LONG_LONG )
Packit Service 96b5d3
     typedef long long intmax_t;
Packit Service 96b5d3
     typedef unsigned long long uintmax_t;
Packit Service 96b5d3
#  else
Packit Service 96b5d3
     typedef long intmax_t;
Packit Service 96b5d3
     typedef unsigned long uintmax_t;
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#if defined( HAVE_STDARG_H )
Packit Service 96b5d3
#  include <stdarg.h>
Packit Service 96b5d3
#  ifndef   VA_START
Packit Service 96b5d3
#    define VA_START(a, f)  va_start(a, f)
Packit Service 96b5d3
#    define VA_END(a)	    va_end(a)
Packit Service 96b5d3
#  endif /* VA_START */
Packit Service 96b5d3
#  define SNV_USING_STDARG_H
Packit Service 96b5d3
#elif defined( HAVE_VARARGS_H )
Packit Service 96b5d3
#  include <varargs.h>
Packit Service 96b5d3
#  ifndef   VA_START
Packit Service 96b5d3
#    define VA_START(a, f) va_start(a)
Packit Service 96b5d3
#    define VA_END(a)	 va_end(a)
Packit Service 96b5d3
#  endif /* VA_START */
Packit Service 96b5d3
#  undef  SNV_USING_STDARG_H
Packit Service 96b5d3
#else
Packit Service 96b5d3
#  include "must-have-stdarg-or-varargs"
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#if HAVE_RUNETYPE_H
Packit Service 96b5d3
# include <runetype.h>
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef HAVE_WCHAR_H
Packit Service 96b5d3
# include <wchar.h>
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef HAVE_WCHAR_T
Packit Service 96b5d3
typedef wchar_t snv_wchar_t;
Packit Service 96b5d3
#else
Packit Service 96b5d3
typedef int snv_wchar_t;
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef HAVE_WINT_T
Packit Service 96b5d3
typedef wint_t snv_wint_t;
Packit Service 96b5d3
#else
Packit Service 96b5d3
typedef int snv_wint_t;
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
/* inline and const keywords are (mostly) handled by config.h */
Packit Service 96b5d3
#ifdef __GNUC__
Packit Service 96b5d3
Packit Service 96b5d3
#  define GCC_VERSION (__GNUC__ * 10000 \
Packit Service 96b5d3
                    + __GNUC_MINOR__ * 100 \
Packit Service 96b5d3
                    + __GNUC_PATCHLEVEL__)
Packit Service 96b5d3
Packit Service 96b5d3
#  if GCC_VERSION > 40400
Packit Service 96b5d3
#    pragma  GCC diagnostic ignored "-Wextra"
Packit Service 96b5d3
#    pragma  GCC diagnostic ignored "-Wconversion"
Packit Service 96b5d3
#    pragma  GCC diagnostic ignored "-Wsign-conversion"
Packit Service 96b5d3
#    pragma  GCC diagnostic ignored "-Wstrict-overflow"
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
Packit Service 96b5d3
#  ifndef const
Packit Service 96b5d3
#    define const	__const
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
#  ifndef inline
Packit Service 96b5d3
#    define inline	__inline
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
#  ifndef signed
Packit Service 96b5d3
#    define signed	__signed
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
Packit Service 96b5d3
#else
Packit Service 96b5d3
#  define GCC_VERSION 0
Packit Service 96b5d3
#  ifndef __STDC__
Packit Service 96b5d3
#    undef  signed
Packit Service 96b5d3
#    define signed
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef __STDC__
Packit Service 96b5d3
#  define _SNV_STR(x)		#x
Packit Service 96b5d3
   typedef void *snv_pointer;
Packit Service 96b5d3
   typedef const void *snv_constpointer;
Packit Service 96b5d3
#else
Packit Service 96b5d3
#  define _SNV_STR(x)		"x"
Packit Service 96b5d3
   typedef char *snv_pointer;
Packit Service 96b5d3
   typedef char *snv_constpointer;
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#if defined(HAVE_FPUTC_UNLOCKED) && defined(HAVE_FLOCKFILE)
Packit Service 96b5d3
#  define SNV_FPUTC_UNLOCKED fputc_unlocked
Packit Service 96b5d3
#  define SNV_PUTC_UNLOCKED putc_unlocked
Packit Service 96b5d3
#  define SNV_WITH_LOCKED_FP(fp, tmp_var) \
Packit Service 96b5d3
     for (flockfile (fp), tmp_var = 1; \
Packit Service 96b5d3
       tmp_var--; funlockfile (fp))
Packit Service 96b5d3
#else
Packit Service 96b5d3
#  define SNV_FPUTC_UNLOCKED fputc
Packit Service 96b5d3
#  define SNV_PUTC_UNLOCKED putc
Packit Service 96b5d3
#  define SNV_WITH_LOCKED_FP(fp, tmp_var) \
Packit Service 96b5d3
     for (tmp_var = 1; tmp_var--; )
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
/*
Packit Service 96b5d3
 * Define macros for storing integers inside pointers.
Packit Service 96b5d3
 * Be aware that it is only safe to use these macros to store `int'
Packit Service 96b5d3
 * values in `char*' (or `void*') words, and then extract them later.
Packit Service 96b5d3
 * Although it will work the other way round on many common
Packit Service 96b5d3
 * architectures, it is not portable to assume a `char*' can be
Packit Service 96b5d3
 * stored in an `int' and extracted later without loss of the msb's
Packit Service 96b5d3
 */
Packit Service 96b5d3
#define SNV_POINTER_TO_LONG(p)	((long)(p))
Packit Service 96b5d3
#define SNV_POINTER_TO_ULONG(p)	((unsigned long)(p))
Packit Service 96b5d3
#define SNV_LONG_TO_POINTER(i)	((snv_pointer)(long)(i))
Packit Service 96b5d3
#define SNV_ULONG_TO_POINTER(u)	((snv_pointer)(unsigned long)(u))
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef HAVE_STDBOOL_H
Packit Service 96b5d3
#include <stdbool.h>
Packit Service 96b5d3
#else
Packit Service 96b5d3
typedef enum {
Packit Service 96b5d3
    false = 0,
Packit Service 96b5d3
    true  = 1
Packit Service 96b5d3
} bool;
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef __CYGWIN32__
Packit Service 96b5d3
#  ifndef __CYGWIN__
Packit Service 96b5d3
#    define __CYGWIN__
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
#endif
Packit Service 96b5d3
#ifdef __CYGWIN__
Packit Service 96b5d3
#  ifndef _WIN32
Packit Service 96b5d3
#    define _WIN32
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifndef PARAMS
Packit Service 96b5d3
#  define PARAMS(args)      args
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#undef SNV_STMT_START
Packit Service 96b5d3
#undef SNV_STMT_END
Packit Service 96b5d3
#if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
Packit Service 96b5d3
#  define SNV_STMT_START	(void)(
Packit Service 96b5d3
#  define SNV_STMT_END		)
Packit Service 96b5d3
Packit Service 96b5d3
#elif (defined (sun) || defined (__sun__))
Packit Service 96b5d3
#  define SNV_STMT_START	if (1)
Packit Service 96b5d3
#  define SNV_STMT_END		else (void)0
Packit Service 96b5d3
Packit Service 96b5d3
#else
Packit Service 96b5d3
#  define SNV_STMT_START	do
Packit Service 96b5d3
#  define SNV_STMT_END		while (false)
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef _WIN32
Packit Service 96b5d3
#  ifdef DLL_EXPORT
Packit Service 96b5d3
#    define SNV_SCOPE	extern __declspec(dllexport)
Packit Service 96b5d3
#  else
Packit Service 96b5d3
#    ifdef LIBSNPRINTFV_DLL_IMPORT
Packit Service 96b5d3
#      define SNV_SCOPE	extern __declspec(dllimport)
Packit Service 96b5d3
#    endif
Packit Service 96b5d3
#  endif
Packit Service 96b5d3
#endif
Packit Service 96b5d3
#ifndef SNV_SCOPE
Packit Service 96b5d3
#  define SNV_SCOPE	extern
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#undef SNV_GNUC_PRINTF
Packit Service 96b5d3
#undef SNV_GNUC_NORETURN
Packit Service 96b5d3
#if GCC_VERSION > 20400
Packit Service 96b5d3
#  define SNV_GNUC_PRINTF( args, format_idx, arg_idx )		\
Packit Service 96b5d3
  	args __attribute__((format (printf, format_idx, arg_idx)))
Packit Service 96b5d3
#  define SNV_GNUC_NORETURN						\
Packit Service 96b5d3
	__attribute__((__noreturn__))
Packit Service 96b5d3
#  define SNV_ASSERT_FCN  	 " (", __PRETTY_FUNCTION__, ")"
Packit Service 96b5d3
#else /* GCC_VERSION */
Packit Service 96b5d3
#  define SNV_GNUC_PRINTF( args, format_idx, arg_idx ) args
Packit Service 96b5d3
#  define SNV_GNUC_NORETURN
Packit Service 96b5d3
#  define SNV_ASSERT_FCN		"", "", ""
Packit Service 96b5d3
#endif /* GCC_VERSION */
Packit Service 96b5d3
Packit Service 96b5d3
#define SNV_ASSERT_FMT  "file %s: line %d%s%s%s: assertion \"%s\" failed.\n"
Packit Service 96b5d3
Packit Service 96b5d3
#define snv_assert(expr)		snv_fassert(stderr, expr)
Packit Service 96b5d3
#define snv_fassert(stream, expr)   SNV_STMT_START {        \
Packit Service 96b5d3
    if (!(expr))   {                                        \
Packit Service 96b5d3
    fprintf (stream, SNV_ASSERT_FMT, __FILE__, __LINE__,    \
Packit Service 96b5d3
             SNV_ASSERT_FCN, _SNV_STR(expr));               \
Packit Service 96b5d3
    exit(EXIT_FAILURE);                                     \
Packit Service 96b5d3
    }; } SNV_STMT_END
Packit Service 96b5d3
Packit Service 96b5d3
#define return_if_fail(expr)		freturn_if_fail(stderr, expr)
Packit Service 96b5d3
#define freturn_if_fail(expr)       SNV_STMT_START {        \
Packit Service 96b5d3
    if (!(expr))   {                                        \
Packit Service 96b5d3
    fprintf (stream, SNV_ASSERT_FMT, __FILE__, __LINE__,    \
Packit Service 96b5d3
             SNV_ASSERT_FCN, _SNV_STR(expr));               \
Packit Service 96b5d3
    return;                                                 \
Packit Service 96b5d3
    }; } SNV_STMT_END
Packit Service 96b5d3
Packit Service 96b5d3
#define return_val_if_fail(expr, val)	freturn_val_if_fail(stderr, expr, val)
Packit Service 96b5d3
#define freturn_val_if_fail(stream, expr, val)  SNV_STMT_START {    \
Packit Service 96b5d3
    if (!(expr))  {                                                 \
Packit Service 96b5d3
    fprintf (stream, SNV_ASSERT_FMT, __FILE__, __LINE__,            \
Packit Service 96b5d3
             SNV_ASSERT_FCN, _SNV_STR(expr));                       \
Packit Service 96b5d3
    return val;                                                     \
Packit Service 96b5d3
    }; } SNV_STMT_END
Packit Service 96b5d3
Packit Service 96b5d3
#ifndef MAX
Packit Service 96b5d3
#define MAX(a,b)	((a) > (b) ? (a) : (b))
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifndef MIN
Packit Service 96b5d3
#define MIN(a,b)	((a) < (b) ? (a) : (b))
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
#ifndef ABS
Packit Service 96b5d3
#define ABS(a)		((a) < 0 ? -(a) : (a))
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
typedef SNV_LONG_DOUBLE snv_long_double;
Packit Service 96b5d3
Packit Service 96b5d3
#ifndef HAVE_STRTOUL
Packit Service 96b5d3
extern unsigned long
Packit Service 96b5d3
strtoul( const char *nptrm, char **endptr, register int base );
Packit Service 96b5d3
#endif
Packit Service 96b5d3
Packit Service 96b5d3
SNV_END_EXTERN_C
Packit Service 96b5d3
#endif /* SNPRINTFV_COMPAT_H */
Packit Service 96b5d3
Packit Service 96b5d3
/*
Packit Service 96b5d3
 * Local Variables:
Packit Service 96b5d3
 * mode: C
Packit Service 96b5d3
 * c-file-style: "gnu"
Packit Service 96b5d3
 * indent-tabs-mode: nil
Packit Service 96b5d3
 * End:
Packit Service 96b5d3
 * end of snprintfv/compat.h */