[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <063D6719AE5E284EB5DD2968C1650D6DD006D878@AcuExch.aculab.com>
Date: Mon, 4 Sep 2017 14:49:20 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Phil Sutter' <phil@....cc>,
Stephen Hemminger <stephen@...workplumber.org>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: RE: [iproute PATCH 1/6] utils: Implement strlcpy() and strlcat()
From: Phil Sutter
> Sent: 01 September 2017 17:53
> By making use of strncpy(), both implementations are really simple so
> there is no need to add libbsd as additional dependency.
>
...
> +
> +size_t strlcpy(char *dst, const char *src, size_t size)
> +{
> + if (size) {
> + strncpy(dst, src, size - 1);
> + dst[size - 1] = '\0';
> + }
> + return strlen(src);
> +}
Except that isn't really strlcpy().
Better would be:
len = strlen(src) + 1;
if (len <= size)
memcpy(dst, src, len);
else if (size) {
dst[size - 1] = 0;
memcpy(dst, src, size - 1);
}
return len - 1;
WTF strlcpy() has that return value I don't know.
David
Powered by blists - more mailing lists