Back to index

nagios-plugins  1.4.16
vasprintf.c
Go to the documentation of this file.
00001 /* Formatted output to strings.
00002    Copyright (C) 1999, 2002, 2006-2010 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 3, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License along
00015    with this program; if not, write to the Free Software Foundation,
00016    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00017 
00018 #include <config.h>
00019 
00020 /* Specification.  */
00021 #ifdef IN_LIBASPRINTF
00022 # include "vasprintf.h"
00023 #else
00024 # include <stdio.h>
00025 #endif
00026 
00027 #include <errno.h>
00028 #include <limits.h>
00029 #include <stdlib.h>
00030 
00031 #include "vasnprintf.h"
00032 
00033 int
00034 vasprintf (char **resultp, const char *format, va_list args)
00035 {
00036   size_t length;
00037   char *result = vasnprintf (NULL, &length, format, args);
00038   if (result == NULL)
00039     return -1;
00040 
00041   if (length > INT_MAX)
00042     {
00043       free (result);
00044       errno = EOVERFLOW;
00045       return -1;
00046     }
00047 
00048   *resultp = result;
00049   /* Return the number of resulting bytes, excluding the trailing NUL.  */
00050   return length;
00051 }