Blame gl/vasprintf.c

Packit aea12f
/* Formatted output to strings.
Packit Service 991b93
   Copyright (C) 1999, 2002, 2006-2020 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   This program is free software; you can redistribute it and/or modify
Packit Service 991b93
   it under the terms of the GNU Lesser General Public License as published by
Packit Service 991b93
   the Free Software Foundation; either version 2.1, or (at your option)
Packit aea12f
   any later version.
Packit aea12f
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 991b93
   GNU Lesser General Public License for more details.
Packit aea12f
Packit Service 991b93
   You should have received a copy of the GNU Lesser General Public License along
Packit aea12f
   with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
#include <config.h>
Packit aea12f
Packit aea12f
/* Specification.  */
Packit aea12f
#ifdef IN_LIBASPRINTF
Packit aea12f
# include "vasprintf.h"
Packit aea12f
#else
Packit aea12f
# include <stdio.h>
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#include <errno.h>
Packit aea12f
#include <limits.h>
Packit aea12f
#include <stdlib.h>
Packit aea12f
Packit aea12f
#include "vasnprintf.h"
Packit aea12f
Packit aea12f
int
Packit aea12f
vasprintf (char **resultp, const char *format, va_list args)
Packit aea12f
{
Packit aea12f
  size_t length;
Packit aea12f
  char *result = vasnprintf (NULL, &length, format, args);
Packit aea12f
  if (result == NULL)
Packit aea12f
    return -1;
Packit aea12f
Packit aea12f
  if (length > INT_MAX)
Packit aea12f
    {
Packit aea12f
      free (result);
Packit aea12f
      errno = EOVERFLOW;
Packit aea12f
      return -1;
Packit aea12f
    }
Packit aea12f
Packit aea12f
  *resultp = result;
Packit aea12f
  /* Return the number of resulting bytes, excluding the trailing NUL.  */
Packit aea12f
  return length;
Packit aea12f
}