[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20140923154046.1e57134bdb7e3143c0a5b6c9@linux-foundation.org>
Date: Tue, 23 Sep 2014 15:40:46 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se>
Cc: Grant Likely <grant.likely@...aro.org>,
Andi Kleen <ak@...ux.intel.com>,
Dan Carpenter <dan.carpenter@...cle.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] lib: string.c: Added a funktion function strzcpy
On Wed, 24 Sep 2014 00:13:36 +0200 Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se> wrote:
> +/**
> + * strzcpy - Copy a length-limited, C-string
> + * @dest: Where to copy the string to
> + * @src: Where to copy the string from
> + * @count: The maximum number of bytes to copy
> + *
> + * The result is %NUL-terminated,
> + * as long as count is greater than zero.
> + *
> + * In the case where the length of @src is less than that of
> + * count, the remainder of @dest will be padded with %NUL.
As far as I can tell, this sentence describes the only difference
between strzcpy() and strlcpy(). Only the sentence is wrong - the
implementation doesn't actually do that.
> + */
> +char *strzcpy(char *dest, const char *src, size_t count)
> +{
> + char *tmp = dest;
> +
> + while (count) {
> + if ((*tmp = *src) != 0)
> + src++;
> + tmp++;
> + count--;
> + }
> +
> + if (dest != tmp)
> + *--tmp = '\0';
> +
> + return dest;
> +}
> +EXPORT_SYMBOL(strzcpy);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists