X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fxmalloc.c;h=4aa922c56dcefd01d3a86ee3d728feb697aae43b;hp=94a656572ad382466d85dfab1664996b0409948e;hb=3594baeb76423dcee4a138f54bc1d5b5b4477fe3;hpb=16ae6b899b1eb60c570650b7acc8e673531f5510 diff --git a/src/xmalloc.c b/src/xmalloc.c index 94a6565..4aa922c 100644 --- a/src/xmalloc.c +++ b/src/xmalloc.c @@ -341,6 +341,20 @@ void xfree_f(void *p, const char *file, int line) yaz_log (log_level, "%s:%d: xfree %p", file, line, p); xfree_d(p, file, line); } + +char *xstrndup_f(const char *s, size_t n, const char *file, int line) +{ + size_t l = strlen(s); + if (l < n) + return xstrdup_f(s, file, line); + { + char *a = xmalloc_f(n+1, file, line); + memcpy(a, s, n); + a[n] = '\0'; + return a; + } +} + /* * Local variables: * c-basic-offset: 4