This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] Simplify strncat.
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Wilco Dijkstra <wdijkstr at arm dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 19 Dec 2014 12:02:59 -0800
- Subject: Re: [PATCH] Simplify strncat.
- Authentication-results: sourceware.org; auth=none
- References: <000f01d01ad0$17e381d0$47aa8570$ at com>
On 12/18/2014 06:37 AM, Wilco Dijkstra wrote:
STRNCAT (char *s1, const char *s2, size_t n)
n = strnlen (s2, n);
s = s1 + strlen (s1);
s[n] = '\0';
memcpy (s, s2, n);
I originally wrote it the above way first, but rewrote it to use mempcpy
because that made strncat simpler and its executable code smaller, and
since nobody in their right mind ever uses strncat I figured simpler and
smaller was better for glibc users overall even if it might be
unmeasurably slower for the few crazies who actually use strncat.
It's not a big deal either way, of course. Either version is fine.