[PATCH] lib: string.c: Added a funktion function strzcpy

From: Rickard Strandqvist
Date: Tue Sep 23 2014 - 18:12:21 EST


I've added a feature strzcpy to make it easier to not do wrong
when you use the function strncpy.
By not have to add a guaranteed trailing null character:
strncpy(to, src, c);
to[c - 1] = '\0';


This arose after a discussion with Dan Carpenter:

https://lkml.org/lkml/2014/9/15/74

And I was thinking of making it with the return value corresponding
to strlen, but could not make any neat/optimal solution.
But if we are to add this maybe it's worth thinking about whether
we can use the return value to something sensible.


Rickard Strandqvist (1):
lib: string.c: Added a funktion function strzcpy

include/linux/string.h | 1 +
lib/string.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/