diff options
author | Bruno Haible <bruno@clisp.org> | 2004-09-08 12:15:25 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2004-09-08 12:15:25 +0000 |
commit | 0f2c51f68bf088cd445a9625d19ed5d381aa0f80 (patch) | |
tree | c10ebd7a8954991f11d3cdc03c2974bf81f95161 /lib/xvasprintf.c | |
parent | 372b0b04326df8b7220d89c0ebe93b58befacf2b (diff) | |
download | gnulib-0f2c51f68bf088cd445a9625d19ed5d381aa0f80.tar.gz |
New module 'xvasprintf'.
Diffstat (limited to 'lib/xvasprintf.c')
-rw-r--r-- | lib/xvasprintf.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/xvasprintf.c b/lib/xvasprintf.c new file mode 100644 index 0000000000..89b5836334 --- /dev/null +++ b/lib/xvasprintf.c @@ -0,0 +1,42 @@ +/* vasprintf and asprintf with out-of-memory checking. + Copyright (C) 1999, 2002-2004 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/* Specification. */ +#include "xvasprintf.h" + +#include <errno.h> + +#include "vasprintf.h" + +char * +xvasprintf (const char *format, va_list args) +{ + char *result; + + if (vasprintf (&result, format, args) < 0) + { + if (errno == ENOMEM) + xmalloc_die(); + return NULL; + } + + return result; +} |