]> Pileus Git - ~andy/fetchmail/blobdiff - xmalloc.c
Complete Dominik's name.
[~andy/fetchmail] / xmalloc.c
index 7436558601fe51c8bf405c2706242a7fe7435a7b..c2ca4a66e932a32d99716d851914b13ca05da6f0 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -6,6 +6,7 @@
  */
 
 #include "config.h"
+#include <sys/types.h>
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
@@ -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 */