On 5/3/07, Daniel Barkalow <barkalow@xxxxxxxxxxxx> wrote:
+static inline char *xstrndup(const char *str, int len) +{ + char *ret; + int i; + for (i = 0; i < len && str[i]; i++) + ; + ret = xmalloc(i + 1); + strncpy(ret, str, i); + ret[i] = '\0'; + return ret; +}
I'd suggest using platform-optimized memchr: static inline char *xstrndup(const char *s, int len) { char *p = memchr(s, 0, len); int n = p ? p - s: len; p = xmalloc(n + 1); memcpy(p, s, n); p[n] = '\0'; return p; } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html