public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: string.c:  Added a funktion function strzcpy
@ 2014-09-23 22:13 Rickard Strandqvist
  2014-09-23 22:13 ` Rickard Strandqvist
  0 siblings, 1 reply; 13+ messages in thread
From: Rickard Strandqvist @ 2014-09-23 22:13 UTC (permalink / raw)
  To: Rickard Strandqvist, Grant Likely
  Cc: Andrew Morton, Andi Kleen, Dan Carpenter, linux-kernel

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-09-24 22:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-23 22:13 [PATCH] lib: string.c: Added a funktion function strzcpy Rickard Strandqvist
2014-09-23 22:13 ` Rickard Strandqvist
2014-09-23 22:40   ` Andrew Morton
2014-09-24  1:17   ` Andi Kleen
2014-09-24  7:52     ` Dan Carpenter
2014-09-24 14:14       ` Lennart Sorensen
2014-09-24 14:35       ` Andi Kleen
     [not found]         ` <CAFo99gZUfFUB9xX0GYW=hJMNouiU-M9apZ8KtPg9MW3x7gxZcg@mail.gmail.com>
2014-09-24 14:58           ` Andi Kleen
2014-09-24 15:41         ` Dan Carpenter
2014-09-24 20:51           ` Rickard Strandqvist
2014-09-24 21:26             ` Andrew Morton
2014-09-24 21:49               ` Rickard Strandqvist
2014-09-24 22:55                 ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox