]> diplodocus.org Git - nmh/commit
Add trunccpy(), and the convenience TRUNCCPY().
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 30 Oct 2016 13:45:40 +0000 (13:45 +0000)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 30 Oct 2016 15:17:27 +0000 (15:17 +0000)
commit603cc061a9c1fa18ab765024491aeeda18686901
tree99d0aae764ca131d3bcd98c6dca8a8b0a95e4fa6
parent1af5da59464f700ce154b26d88a402e3c51301e8
Add trunccpy(), and the convenience TRUNCCPY().

truncpy copies at most size - 1 chars from non-NULL src to non-NULL
dst, and ensures dst is NUL terminated.  If size is zero then it
aborts as dst cannot be NUL terminated.

It's to be used when truncation is intended and correct, e.g.
reporting a possibly very long external string back to the user.  One
of its advantages over strncpy(3) is it doesn't pad in the common
case of no truncation.
h/utils.h
sbr/utils.c