Blame gl/vasnprintf.h

Packit 549fdc
/* vsprintf with automatic memory allocation.
Packit 549fdc
   Copyright (C) 2002-2004, 2007-2016 Free Software Foundation, Inc.
Packit 549fdc
Packit 549fdc
   This program is free software; you can redistribute it and/or modify
Packit 549fdc
   it under the terms of the GNU Lesser General Public License as published by
Packit 549fdc
   the Free Software Foundation; either version 2.1, or (at your option)
Packit 549fdc
   any later version.
Packit 549fdc
Packit 549fdc
   This program is distributed in the hope that it will be useful,
Packit 549fdc
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 549fdc
   GNU Lesser General Public License for more details.
Packit 549fdc
Packit 549fdc
   You should have received a copy of the GNU Lesser General Public License along
Packit 549fdc
   with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit 549fdc
Packit 549fdc
#ifndef _VASNPRINTF_H
Packit 549fdc
#define _VASNPRINTF_H
Packit 549fdc
Packit 549fdc
/* Get va_list.  */
Packit 549fdc
#include <stdarg.h>
Packit 549fdc
Packit 549fdc
/* Get size_t.  */
Packit 549fdc
#include <stddef.h>
Packit 549fdc
Packit 549fdc
/* The __attribute__ feature is available in gcc versions 2.5 and later.
Packit 549fdc
   The __-protected variants of the attributes 'format' and 'printf' are
Packit 549fdc
   accepted by gcc versions 2.6.4 (effectively 2.7) and later.
Packit 549fdc
   We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
Packit 549fdc
   gnulib and libintl do '#define printf __printf__' when they override
Packit 549fdc
   the 'printf' function.  */
Packit 549fdc
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
Packit 549fdc
# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
Packit 549fdc
#else
Packit 549fdc
# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
Packit 549fdc
#endif
Packit 549fdc
Packit 549fdc
#ifdef __cplusplus
Packit 549fdc
extern "C" {
Packit 549fdc
#endif
Packit 549fdc
Packit 549fdc
/* Write formatted output to a string dynamically allocated with malloc().
Packit 549fdc
   You can pass a preallocated buffer for the result in RESULTBUF and its
Packit 549fdc
   size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
Packit 549fdc
   If successful, return the address of the string (this may be = RESULTBUF
Packit 549fdc
   if no dynamic memory allocation was necessary) and set *LENGTHP to the
Packit 549fdc
   number of resulting bytes, excluding the trailing NUL.  Upon error, set
Packit 549fdc
   errno and return NULL.
Packit 549fdc
Packit 549fdc
   When dynamic memory allocation occurs, the preallocated buffer is left
Packit 549fdc
   alone (with possibly modified contents).  This makes it possible to use
Packit 549fdc
   a statically allocated or stack-allocated buffer, like this:
Packit 549fdc
Packit 549fdc
          char buf[100];
Packit 549fdc
          size_t len = sizeof (buf);
Packit 549fdc
          char *output = vasnprintf (buf, &len, format, args);
Packit 549fdc
          if (output == NULL)
Packit 549fdc
            ... error handling ...;
Packit 549fdc
          else
Packit 549fdc
            {
Packit 549fdc
              ... use the output string ...;
Packit 549fdc
              if (output != buf)
Packit 549fdc
                free (output);
Packit 549fdc
            }
Packit 549fdc
  */
Packit 549fdc
#if REPLACE_VASNPRINTF
Packit 549fdc
# define asnprintf rpl_asnprintf
Packit 549fdc
# define vasnprintf rpl_vasnprintf
Packit 549fdc
#endif
Packit 549fdc
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
Packit 549fdc
       _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4));
Packit 549fdc
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
Packit 549fdc
       _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0));
Packit 549fdc
Packit 549fdc
#ifdef __cplusplus
Packit 549fdc
}
Packit 549fdc
#endif
Packit 549fdc
Packit 549fdc
#endif /* _VASNPRINTF_H */