Blame src/estream-printf.h

Packit fc043f
/* estream-printf.h - Versatile mostly C-99 compliant printf formatting.
Packit fc043f
 * Copyright (C) 2007, 2010, 2012 g10 Code GmbH
Packit fc043f
 *
Packit fc043f
 * This file is part of Libestream.
Packit fc043f
 *
Packit fc043f
 * Libestream is free software; you can redistribute it and/or modify
Packit fc043f
 * it under the terms of the GNU Lesser General Public License as
Packit fc043f
 * published by the Free Software Foundation; either version 2.1 of
Packit fc043f
 * the License, or (at your option) any later version.
Packit fc043f
 *
Packit fc043f
 * Libestream is distributed in the hope that it will be useful, but
Packit fc043f
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit fc043f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit fc043f
 * Lesser General Public License for more details.
Packit fc043f
 *
Packit fc043f
 * You should have received a copy of the GNU Lesser General Public
Packit fc043f
 * License along with Libestream; if not, see <https://www.gnu.org/licenses/>.
Packit fc043f
 *
Packit fc043f
 * ALTERNATIVELY, Libestream may be distributed under the terms of the
Packit fc043f
 * following license, in which case the provisions of this license are
Packit fc043f
 * required INSTEAD OF the GNU General Public License. If you wish to
Packit fc043f
 * allow use of your version of this file only under the terms of the
Packit fc043f
 * GNU General Public License, and not to allow others to use your
Packit fc043f
 * version of this file under the terms of the following license,
Packit fc043f
 * indicate your decision by deleting this paragraph and the license
Packit fc043f
 * below.
Packit fc043f
 *
Packit fc043f
 * Redistribution and use in source and binary forms, with or without
Packit fc043f
 * modification, are permitted provided that the following conditions
Packit fc043f
 * are met:
Packit fc043f
 * 1. Redistributions of source code must retain the above copyright
Packit fc043f
 *    notice, and the entire permission notice in its entirety,
Packit fc043f
 *    including the disclaimer of warranties.
Packit fc043f
 * 2. Redistributions in binary form must reproduce the above copyright
Packit fc043f
 *    notice, this list of conditions and the following disclaimer in the
Packit fc043f
 *    documentation and/or other materials provided with the distribution.
Packit fc043f
 * 3. The name of the author may not be used to endorse or promote
Packit fc043f
 *    products derived from this software without specific prior
Packit fc043f
 *    written permission.
Packit fc043f
 *
Packit fc043f
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
Packit fc043f
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit fc043f
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit fc043f
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
Packit fc043f
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Packit fc043f
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit fc043f
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit fc043f
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
Packit fc043f
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit fc043f
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
Packit fc043f
 * OF THE POSSIBILITY OF SUCH DAMAGE.
Packit fc043f
 */
Packit fc043f
Packit fc043f
#ifndef ESTREAM_PRINTF_H
Packit fc043f
#define ESTREAM_PRINTF_H
Packit fc043f
Packit fc043f
#include <stdarg.h>
Packit fc043f
#include <stdio.h>
Packit fc043f
Packit fc043f
/* To use this file with libraries the following macro is useful:
Packit fc043f
Packit fc043f
     #define _ESTREAM_EXT_SYM_PREFIX _foo_
Packit fc043f
Packit fc043f
       This prefixes all external symbols with "_foo_".
Packit fc043f
Packit fc043f
   For the implementation of the code (estream-printf.c) the following
Packit fc043f
   macros may be used to tune the implementation for certain systems:
Packit fc043f
Packit fc043f
     #define _ESTREAM_PRINTF_REALLOC foo_realloc
Packit fc043f
Packit fc043f
       Make estream_asprintf and estream_vasprintf use foo_realloc
Packit fc043f
       instead of the standard realloc to allocate memory returned to
Packit fc043f
       the caller.  Note that foo_realloc needs to be C-90 compliant:
Packit fc043f
       foo_realloc (NULL,n) is the same as a call to malloc(n) and
Packit fc043f
       foo_realloc (a, 0) is the same as a call to free (a).
Packit fc043f
Packit fc043f
     #define  _ESTREAM_PRINTF_EXTRA_INCLUDE "foo.h"
Packit fc043f
Packit fc043f
       This includes the file "foo.h" which may provide prototypes for
Packit fc043f
       the custom memory allocation functions.
Packit fc043f
 */
Packit fc043f
Packit fc043f
Packit fc043f
#ifdef _ESTREAM_EXT_SYM_PREFIX
Packit fc043f
#ifndef _ESTREAM_PREFIX
Packit fc043f
#define _ESTREAM_PREFIX1(x,y)  x ## y
Packit fc043f
#define _ESTREAM_PREFIX2(x,y) _ESTREAM_PREFIX1(x,y)
Packit fc043f
#define _ESTREAM_PREFIX(x)    _ESTREAM_PREFIX2(_ESTREAM_EXT_SYM_PREFIX,x)
Packit fc043f
#endif /*_ESTREAM_PREFIX*/
Packit fc043f
#define estream_printf_out_t  _ESTREAM_PREFIX(estream_printf_out_t)
Packit fc043f
#define estream_format        _ESTREAM_PREFIX(estream_format)
Packit fc043f
#define estream_printf        _ESTREAM_PREFIX(estream_printf)
Packit fc043f
#define estream_fprintf       _ESTREAM_PREFIX(estream_fprintf)
Packit fc043f
#define estream_vfprintf      _ESTREAM_PREFIX(estream_vfprintf)
Packit fc043f
#define estream_snprintf      _ESTREAM_PREFIX(estream_snprintf)
Packit fc043f
#define estream_vsnprintf     _ESTREAM_PREFIX(estream_vsnprintf)
Packit fc043f
#define estream_asprintf      _ESTREAM_PREFIX(estream_asprintf)
Packit fc043f
#define estream_vasprintf     _ESTREAM_PREFIX(estream_vasprintf)
Packit fc043f
#endif /*_ESTREAM_EXT_SYM_PREFIX*/
Packit fc043f
Packit fc043f
#ifndef _ESTREAM_GCC_A_PRINTF
Packit fc043f
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4 )
Packit fc043f
#  define _ESTREAM_GCC_A_PRINTF( f, a ) \
Packit fc043f
                               __attribute__ ((format (__gnu_printf__,f,a)))
Packit fc043f
# elif __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
Packit fc043f
#  define _ESTREAM_GCC_A_PRINTF( f, a ) \
Packit fc043f
                               __attribute__ ((format (printf,f,a)))
Packit fc043f
# else
Packit fc043f
#  define _ESTREAM_GCC_A_PRINTF( f, a )
Packit fc043f
# endif
Packit fc043f
#endif /*_ESTREAM_GCC_A_PRINTF*/
Packit fc043f
Packit fc043f
Packit fc043f
#ifdef __cplusplus
Packit fc043f
extern "C"
Packit fc043f
{
Packit fc043f
#if 0
Packit fc043f
}
Packit fc043f
#endif
Packit fc043f
#endif
Packit fc043f
Packit fc043f
Packit fc043f
typedef int (*estream_printf_out_t)
Packit fc043f
     (void *outfncarg,  const char *buf, size_t buflen);
Packit fc043f
Packit fc043f
int _gpgrt_estream_format (estream_printf_out_t outfnc, void *outfncarg,
Packit fc043f
                           const char *format, va_list vaargs)
Packit fc043f
     _ESTREAM_GCC_A_PRINTF(3,0);
Packit fc043f
int _gpgrt_estream_printf (const char *format, ...)
Packit fc043f
     _ESTREAM_GCC_A_PRINTF(1,2);
Packit fc043f
int _gpgrt_estream_fprintf (FILE *fp, const char *format, ... )
Packit fc043f
     _ESTREAM_GCC_A_PRINTF(2,3);
Packit fc043f
int _gpgrt_estream_vfprintf (FILE *fp, const char *format, va_list arg_ptr)
Packit fc043f
     _ESTREAM_GCC_A_PRINTF(2,0);
Packit fc043f
int _gpgrt_estream_snprintf (char *buf, size_t bufsize, const char *format, ...)
Packit fc043f
     _ESTREAM_GCC_A_PRINTF(3,4);
Packit fc043f
int _gpgrt_estream_vsnprintf (char *buf,size_t bufsize,
Packit fc043f
                              const char *format, va_list arg_ptr)
Packit fc043f
     _ESTREAM_GCC_A_PRINTF(3,0);
Packit fc043f
int _gpgrt_estream_asprintf (char **bufp, const char *format, ...)
Packit fc043f
     _ESTREAM_GCC_A_PRINTF(2,3);
Packit fc043f
int _gpgrt_estream_vasprintf (char **bufp, const char *format, va_list arg_ptr)
Packit fc043f
     _ESTREAM_GCC_A_PRINTF(2,0);
Packit fc043f
char *_gpgrt_estream_bsprintf (const char *format, ...)
Packit fc043f
       _ESTREAM_GCC_A_PRINTF(1,2);
Packit fc043f
Packit fc043f
Packit fc043f
#ifdef __cplusplus
Packit fc043f
}
Packit fc043f
#endif
Packit fc043f
#endif /*ESTREAM_PRINTF_H*/