Implement C11 annex K?

Russ Allbery eagle@eyrie.org
Thu Aug 14 17:20:00 GMT 2014


Paul Eggert <eggert@cs.ucla.edu> writes:

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

Indeed, they did.

Hm.  For some reason, a malloc and free for every component felt really
heavy to me, even for code that wasn't performance-critical.  On further
inspection of that feeling, it's probably just premature optimization and
something I should just get over.

Thank you!

> 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.

Ah, indeed.  I had completely missed the existence of open_memstream.
Thank you for this as well!

-- 
Russ Allbery (eagle@eyrie.org)              <http://www.eyrie.org/~eagle/>



More information about the Libc-alpha mailing list