summaryrefslogtreecommitdiffstats
path: root/libopkg/opkg_utils.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/opkg_utils.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/opkg_utils.c')
-rw-r--r--libopkg/opkg_utils.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c
index ccc3496..20af4d5 100644
--- a/libopkg/opkg_utils.c
+++ b/libopkg/opkg_utils.c
@@ -70,20 +70,20 @@ char **read_raw_pkgs_from_stream(FILE *fp)
int count = 0;
size_t size = 512;
- buf = calloc (1, size);
+ buf = xcalloc(1, size);
while (fgets(buf, size, fp)) {
while (strlen (buf) == (size - 1)
&& buf[size-2] != '\n') {
size_t o = size - 1;
size *= 2;
- buf = realloc (buf, size);
+ buf = xrealloc (buf, size);
if (fgets (buf + o, size - o, fp) == NULL)
break;
}
if(!(count % 50))
- raw = realloc(raw, (count + 50) * sizeof(char *));
+ raw = xrealloc(raw, (count + 50) * sizeof(char *));
if((scout = strchr(buf, '\n')))
*scout = '\0';
@@ -91,7 +91,7 @@ char **read_raw_pkgs_from_stream(FILE *fp)
raw[count++] = xstrdup(buf);
}
- raw = realloc(raw, (count + 1) * sizeof(char *));
+ raw = xrealloc(raw, (count + 1) * sizeof(char *));
raw[count] = NULL;
free (buf);
@@ -105,11 +105,7 @@ char *trim_alloc(char *line)
char *new;
char *dest, *src, *end;
- new = calloc(1, strlen(line) + 1);
- if ( new == NULL ){
- fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
- return NULL;
- }
+ new = xcalloc(1, strlen(line) + 1);
dest = new, src = line, end = line + (strlen(line) - 1);
/* remove it from the front */
@@ -157,13 +153,7 @@ void push_error_list(char * msg)
{
struct errlist *e;
- e = calloc(1, sizeof(struct errlist));
- if (e == NULL) {
- fprintf(stderr, "%s: calloc: %s\n",
- __FUNCTION__, strerror(errno));
- return;
- }
-
+ e = xcalloc(1, sizeof(struct errlist));
e->errmsg = xstrdup(msg);
e->next = NULL;