estrndup.c (281B)
1 /* Written by Kris Maglione <maglione.k at Gmail> */ 2 /* Public domain */ 3 #include <string.h> 4 #include "util.h" 5 6 char* 7 estrndup(const char *str, uint len) { 8 char *ret; 9 10 len = min(len, strlen(str)); 11 ret = emalloc(len + 1); 12 memcpy(ret, str, len); 13 ret[len] = '\0'; 14 return ret; 15 }