]> git.ipfire.org Git - thirdparty/shadow.git/commit
strlcpy.[ch]: Add strlcpy_()
authorAlejandro Colomar <alx@kernel.org>
Sat, 26 Aug 2023 13:28:24 +0000 (15:28 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Fri, 1 Sep 2023 07:39:23 +0000 (09:39 +0200)
commit3bf8d68f10f2426eda2dd27a21cc0f2a996d5693
tree32f690fe3e3ce073bb47c015aa7083090c039c40
parente7a292ed4f69bd2d5b97dd25cfdeccdde5319512
strlcpy.[ch]: Add strlcpy_()

This function is like strlcpy(3), but returns -1 on truncation, which
makes it much easier to test.  strlcpy(3) is useful in two cases:

-  We don't care if the output is truncated.  strlcpy(3) is fine for
   those, and the return value can be ignored.

-  Truncation is bad.  In that case, we just want to signal truncation,
   and the length of the original string is quite useless.  Return the
   length iff no truncation so that we can use it if necessary.

This simplifies the definition of the STRLCPY() macro.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/strlcpy.c [new file with mode: 0644]
lib/strlcpy.h