diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2005-01-02 03:58:21 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2005-01-02 03:58:21 +0000 |
commit | 83346830688525a287489cc791299cbc945d4fc4 (patch) | |
tree | 2d8fd94d497449f2ffe0b8f1a1ad507b03bca753 /utils | |
parent | 143d756fcf681c15b82f117f95a1c527389b0177 (diff) | |
download | netsurf-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')
-rw-r--r-- | utils/utils.c | 51 | ||||
-rw-r--r-- | utils/utils.h | 7 |
2 files changed, 15 insertions, 43 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; diff --git a/utils/utils.h b/utils/utils.h index 31ee01bf3..921662a26 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -19,15 +19,12 @@ void die(const char * const error); char * strip(char * const s); int whitespace(const char * str); -void * xcalloc(const size_t n, const size_t size); -void * xrealloc(void * p, const size_t size); -void xfree(void* p); -char * xstrdup(const char * const s); char * squash_whitespace(const char * s); char *cnv_space2nbsp(const char *s); char *cnv_local_enc_str(const char *s, size_t length); char *cnv_str_local_enc(const char *s); -char *cnv_strn_local_enc(const char *s, int length, const ptrdiff_t **back_mapPP); +char *cnv_strn_local_enc(const char *s, int length, + const ptrdiff_t **back_mapPP); bool is_dir(const char *path); void regcomp_wrapper(regex_t *preg, const char *regex, int cflags); void clean_cookiejar(void); |