summaryrefslogtreecommitdiffstats
path: root/libopkg/sprintf_alloc.c
diff options
context:
space:
mode:
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-11-04 23:20:09 (EST)
committer graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-11-04 23:20:09 (EST)
commit480538737a8a9be074a1848f2e52cf2d1ff4709f (patch)
treee24d32dc46e0b83600aaa02a33ecaa6779765d9b /libopkg/sprintf_alloc.c
parentacd905996191df6ab59050bd179a5ed11e6f72a4 (diff)
s/malloc/xmalloc/ s/calloc/xcalloc/ s/realloc/realloc/
And redundant error checking removed from the places where allocation failures were actually checked. git-svn-id: http://opkg.googlecode.com/svn/trunk@259 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg/sprintf_alloc.c')
-rw-r--r--libopkg/sprintf_alloc.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/libopkg/sprintf_alloc.c b/libopkg/sprintf_alloc.c
index 30ab033..7989493 100644
--- a/libopkg/sprintf_alloc.c
+++ b/libopkg/sprintf_alloc.c
@@ -19,11 +19,11 @@
#include <stdarg.h>
#include "sprintf_alloc.h"
+#include "libbb/libbb.h"
int sprintf_alloc(char **str, const char *fmt, ...)
{
va_list ap;
- char *new_str;
int n, size = 100;
if (!str) {
@@ -44,13 +44,11 @@ int sprintf_alloc(char **str, const char *fmt, ...)
/* ripped more or less straight out of PRINTF(3) */
- if ((new_str = calloc(1, size)) == NULL)
- return -1;
+ *str = xcalloc(1, size);
- *str = new_str;
while(1) {
va_start(ap, fmt);
- n = vsnprintf (new_str, size, fmt, ap);
+ n = vsnprintf (*str, size, fmt, ap);
va_end(ap);
/* If that worked, return the size. */
if (n > -1 && n < size)
@@ -60,13 +58,7 @@ int sprintf_alloc(char **str, const char *fmt, ...)
size = n+1; /* precisely what is needed */
else /* glibc 2.0 */
size *= 2; /* twice the old size */
- new_str = realloc(new_str, size);
- if (new_str == NULL) {
- free(new_str);
- *str = NULL;
- return -1;
- }
- *str = new_str;
+ *str = xrealloc(*str, size);
}
return -1; /* Just to be correct - it probably won't get here */