Commit d8ef2b98 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Slight optimization: use strlcpy() to avoid calloc().

git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@891 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 927f85f0
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifndef HAVE_STRLCPY
#include "compat/strlcpy.h"
#endif
#include "compat/strndup.h" #include "compat/strndup.h"
char * char *
...@@ -16,8 +20,8 @@ strndup(const char *str, size_t len) ...@@ -16,8 +20,8 @@ strndup(const char *str, size_t len)
char *dup; char *dup;
/* wasteful if len is large and str is short */ /* wasteful if len is large and str is short */
if ((dup = calloc(len + 1, 1)) != NULL) if ((dup = malloc(len + 1)) != NULL)
strncpy(dup, str, len); strlcpy(dup, str, len + 1);
return (dup); return (dup);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment