X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=xmalloc.c;h=c2ca4a66e932a32d99716d851914b13ca05da6f0;hb=d31db10231e9ed89f64fdf6e0fb7cae182aa377e;hp=7436558601fe51c8bf405c2706242a7fe7435a7b;hpb=a12da4ee65e0d140bbbcb811eef1cba93785ce35;p=~andy%2Ffetchmail diff --git a/xmalloc.c b/xmalloc.c index 74365586..c2ca4a66 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -6,6 +6,7 @@ */ #include "config.h" +#include #include #include #include @@ -22,7 +23,7 @@ #endif XMALLOCTYPE * -xmalloc (int n) +xmalloc (size_t n) { XMALLOCTYPE *p; @@ -30,13 +31,13 @@ xmalloc (int n) if (p == (XMALLOCTYPE *) 0) { report(stderr, GT_("malloc failed\n")); - exit(PS_UNDEFINED); + abort(); } return(p); } XMALLOCTYPE * -xrealloc (XMALLOCTYPE *p, int n) +xrealloc (XMALLOCTYPE *p, size_t n) { if (p == 0) return xmalloc (n); @@ -44,7 +45,7 @@ xrealloc (XMALLOCTYPE *p, int n) if (p == (XMALLOCTYPE *) 0) { report(stderr, GT_("realloc failed\n")); - exit(PS_UNDEFINED); + abort(); } return p; } @@ -62,9 +63,22 @@ char *strdup(const char *s) { char *p; p = (char *) malloc(strlen(s)+1); - strcpy(p,s); + if (p) + strcpy(p,s); return p; } #endif /* !HAVE_STRDUP */ +char *xstrndup(const char *s, size_t len) +{ + char *p; + size_t l = strlen(s); + + if (len < l) l = len; + p = (char *)xmalloc(l + 1); + memcpy(p, s, l); + p[l] = '\0'; + return p; +} + /* xmalloc.c ends here */