X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=xmalloc.c;h=3a34e1ce187a864a029c434a221a4c4fd2fbe0db;hb=b1c882049db5d6d7d5770134cd93e14934ace6c1;hp=78ba89ba2f9b0a61dce73d722292ba4c60ec6d6f;hpb=0dd1d38a222a5e2e95879ab2397a83d4108d3379;p=pkg%2Fabook.git diff --git a/xmalloc.c b/xmalloc.c index 78ba89b..3a34e1c 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -1,5 +1,5 @@ /* - * $Id: xmalloc.c,v 1.5 2005/08/13 10:49:25 jheinonen Exp $ + * $Id$ * * Common xmalloc memory allocation routines * @@ -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; +}