1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* vasprintf and asprintf with out-of-memory checking.
4 Copyright (C) 1999, 2002-2004, 2006-2010 Free Software Foundation, Inc.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "xvasprintf.h"
31 /* Checked size_t computations. */
35 xstrcat (size_t argcount, va_list args)
43 /* Determine the total size. */
46 for (i = argcount; i > 0; i--)
48 const char *next = va_arg (ap, const char *);
49 totalsize = xsum (totalsize, strlen (next));
53 /* Test for overflow in the summing pass above or in (totalsize + 1) below.
54 Also, don't return a string longer than INT_MAX, for consistency with
56 if (totalsize == SIZE_MAX || totalsize > INT_MAX)
62 /* Allocate and fill the result string. */
63 result = XNMALLOC (totalsize + 1, char);
65 for (i = argcount; i > 0; i--)
67 const char *next = va_arg (args, const char *);
68 size_t len = strlen (next);
69 memcpy (p, next, len);
78 xvasprintf (const char *format, va_list args)
82 /* Recognize the special case format = "%s...%s". It is a frequently used
83 idiom for string concatenation and needs to be fast. We don't want to
84 have a separate function xstrcat() for this purpose. */
92 /* Recognized the special case of string concatenation. */
93 return xstrcat (argcount, args);
104 if (vasprintf (&result, format, args) < 0)