This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Simplify strncat.


On 12/18/2014 06:37 AM, Wilco Dijkstra wrote:
char *
STRNCAT (char *s1, const char *s2, size_t n)
{
   char *s;
   n = strnlen (s2, n);
   s = s1 + strlen (s1);
   s[n] = '\0';
   memcpy (s, s2, n);
   return s1;
}

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]