X-Git-Url: https://git.deb.at/w?p=pkg%2Fabook.git;a=blobdiff_plain;f=xmalloc.c;h=3a34e1ce187a864a029c434a221a4c4fd2fbe0db;hp=2b7fda6b666f2b0d715050b3ad486ff19a74c773;hb=aa2211628a295b85990dbfd8af031d152b583f07;hpb=781c0d657fffe80e45d0fda6ed5ddbf5f796fefb diff --git a/xmalloc.c b/xmalloc.c index 2b7fda6..3a34e1c 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -36,12 +36,13 @@ #include #include #include +#include "gettext.h" #include "xmalloc.h" static void xmalloc_default_error_handler(int err) { - fprintf(stderr, "Memory allocation failure: %s\n", strerror(err)); + fprintf(stderr, _("Memory allocation failure: %s\n"), strerror(err)); exit(EXIT_FAILURE); } @@ -148,3 +149,21 @@ xstrdup(const char *s) return (char *)memcpy(new, s, len + 1); } +char * +xstrndup(const char *s, size_t len) +{ + char *new; + size_t n = strlen(s); + + if(n > len) + n = len; + + new = xmalloc_inc(n, 1); + if(new == NULL) + return NULL; + + memcpy(new, s, n); + new[n] = '\0'; + + return new; +}