Hi, The following code can be optimized to use memcpy(3), since the length of the copy is known (we've just called strnlen(3), and discarded the possibility of truncated lengths).
$ cat strxcpy.c #include <stddef.h> #include <string.h> #include <sys/types.h> ssize_t strxcpy(char *restrict dst, const char *restrict src, size_t dsize) { if (strnlen(src, dsize) == dsize) return -1; return stpcpy(dst, src) - dst; } This compiles to stpcpy(3). Similar code written with strcpy(3) also keeps strcpy(3). But they could be optimized with mempcpy(3) or memcpy(3). Thanks, Alex -- <https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature