Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwpl.git;a=commitdiff;h=286f4cc1be419de01950c4cca36d649325693975
commit 286f4cc1be419de01950c4cca36d649325693975 Author: James Buren <[email protected]> Date: Sat Sep 19 22:09:48 2009 -0500 utility.c * new function diff --git a/src/utility.c b/src/utility.c index 065e31d..97a8115 100644 --- a/src/utility.c +++ b/src/utility.c @@ -37,6 +37,31 @@ char *xstrdup(const char *str1) { return str; } +char *xstrndup(const char *str1,size_t num) { + char *str; + size_t size; + + assert(str1 and num); + + size = strlen(str1); + + if(size > num) + size = num; + + size = (size + 1) * sizeof(*str); + + str = xmalloc(size); + + memcpy(str,str1,size); + + --size; + + if(str[size]) + str[size] = '\0'; + + return str; +} + char *xstrcmb(const char *str1,const char *str2) { char *str; size_t size; _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
