Upgrade netcat a lot. Make -e able to take the rest of the command line as
[oweals/busybox.git] / libbb / bb_asprintf.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Copyright (C) 2002,2005 Vladimir Oleynik <dzo@simtreas.ru>
4  *
5  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
6  */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <stdarg.h>
11 #include "libbb.h"
12
13 char *bb_xasprintf(const char *format, ...)
14 {
15         va_list p;
16         int r;
17         char *string_ptr;
18
19 #ifdef HAVE_GNU_EXTENSIONS
20         va_start(p, format);
21         r = vasprintf(&string_ptr, format, p);
22         va_end(p);
23 #else
24         va_start(p, format);
25         r = vsnprintf(NULL, 0, format, p);
26         va_end(p);
27         string_ptr = xmalloc(r+1);
28         va_start(p, format);
29         r = vsnprintf(string_ptr, r+1, format, p);
30         va_end(p);
31 #endif
32
33         if (r < 0) {
34                 bb_perror_msg_and_die("bb_xasprintf");
35         }
36         return string_ptr;
37 }