summaryrefslogtreecommitdiff
path: root/utils/utils.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2005-01-02 03:58:21 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2005-01-02 03:58:21 +0000
commit83346830688525a287489cc791299cbc945d4fc4 (patch)
tree2d8fd94d497449f2ffe0b8f1a1ad507b03bca753 /utils/utils.c
parent143d756fcf681c15b82f117f95a1c527389b0177 (diff)
downloadnetsurf-83346830688525a287489cc791299cbc945d4fc4.tar.gz
netsurf-83346830688525a287489cc791299cbc945d4fc4.tar.bz2
[project @ 2005-01-02 03:58:20 by jmb]
xcalloc/xrealloc/xstrdup-purge - Lose remaining calls (and purge the relevant functions from utils.c) svn path=/import/netsurf/; revision=1419
Diffstat (limited to 'utils/utils.c')
-rw-r--r--utils/utils.c51
1 files changed, 13 insertions, 38 deletions
diff --git a/utils/utils.c b/utils/utils.c
index 5f5647bf9..35e3b1c7e 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -46,40 +46,6 @@ int whitespace(const char * str)
return 1;
}
-void * xcalloc(const size_t n, const size_t size)
-{
- void * p = calloc(n, size);
- if (p == 0) die("Out of memory in xcalloc()");
- return p;
-}
-
-void * xrealloc(void * p, const size_t size)
-{
- p = realloc(p, size);
- if (p == 0) die("Out of memory in xrealloc()");
- return p;
-}
-
-void xfree(void* p)
-{
- if (p == 0)
- fprintf(stderr, "Attempt to free NULL pointer\n");
- else
- free(p);
-}
-
-char * xstrdup(const char * const s)
-{
- char *c;
- if (s == NULL)
- fprintf(stderr, "Attempt to strdup() NULL pointer\n");
- c = malloc(((s == NULL) ? 0 : strlen(s)) + 1);
- if (c == NULL) die("Out of memory in xstrdup()");
- strcpy(c, (s == NULL) ? "" : s);
- return c;
-}
-
-
/**
* Replace consecutive whitespace with a single space.
*
@@ -223,13 +189,22 @@ char *cnv_strn_local_enc(const char *s, int length, const ptrdiff_t **back_mapPP
/* Buffer at d & back_mapP can be overdimentioned but is certainly
* big enough to carry the end result.
*/
- char *d = xcalloc(length + 1, sizeof(char));
- ptrdiff_t *back_mapP = (back_mapPP != NULL) ? xcalloc(length + 1, sizeof(ptrdiff_t)) : NULL;
- char *d0 = d;
+ char *d, *d0;
const char * const s0 = s;
+ ptrdiff_t *back_mapP = NULL;
- if (back_mapPP != NULL)
+ if (back_mapPP != NULL) {
+ back_mapP = calloc(length + 1, sizeof(ptrdiff_t));
+ if (!back_mapP)
+ return NULL;
*back_mapPP = back_mapP;
+ }
+
+ d = calloc(length + 1, sizeof(char));
+ if (!d)
+ return NULL;
+
+ d0 = d;
while (length != 0) {
int u, chars;