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: Implement C11 annex K?


Russ Allbery wrote:
I would really like ... for someone to explain to me why I'm wrong
in the form of more readable and maintainable code
that doesn't use strlcpy/strlcat.

It seems that our emails crossed; please take a look at
https://sourceware.org/ml/libc-alpha/2014-08/msg00226.html

Here's another (untested) way to skin the cat, also considerably nicer than the strlcpy+strlcat version:

 char *
 vector_join(const struct vector *vector, const char *sep)
 {
   char *string;
   size_t size;
   FILE *f = xopen_memstream(&string, &size);
   for (size_t i = 0; i < vector->count; i++)
     xfprintf(f, "%s%s", i ? sep : "", vector->strings[i]);
   xfclose(f);
   return string;
 }

This may help to explain why POSIX didn't standardize strlcpy.


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