On 4/6/23 23:21, Alejandro Colomar wrote: > strlcat(3) is a slow call that shouldn't be emitted by an optimizing > compiler (similar to how GCC optimizes strcat(3) to stpcpy(3)). > > With that in mind, do we really want all this code? Or maybe we just > want to implement it in the simplest possible way? > > I suggest the following alternative: > > > size_t > strlcat(char *restrict dst, const char *restrict src, size_t dsize) > { > size_t dlen = strlen(dst); This needs to be strnlen(dst, dsize), to avoid passing a huge size to strlcpy(3). This seems a good reason for having defined behavior for strlcpy(x, y, 0). > > return strlcpy(dst + dlen, src, dsize - dlen) + dlen; > } > > > In fact, that's the code I would expect that GCC should emit instead > of calls to the actual strlcat(3). > > (Disclaimer: I didn't test the code; it may likely have bugs) > -- GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5