ia64/xen-unstable

view xen/arch/powerpc/of_handler/strlcpy.c @ 13950:272291dacad4

[POWERPC][XEN] strlcpy() fallout.
- Implement strlcpy() for the dom0 firmware.
- Remove strncpy() from dom0 firmware.
- Correct buffer length in device tree copying.
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author Hollis Blanchard <hollisb@us.ibm.com>
date Fri Feb 09 14:43:21 2007 -0600 (2007-02-09)
parents
children
line source
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 *
16 * Copyright IBM Corp. 2005, 2007
17 *
18 * Authors: Jimi Xenidis <jimix@watson.ibm.com>
19 * Hollis Blanchard <hollisb@us.ibm.com>
20 */
22 #include <xen/string.h>
24 size_t
25 strlcpy(char *dest, const char *src, size_t n)
26 {
27 size_t ret;
28 char *dp;
30 /* cases to consider:
31 * dest is NULL, s is NULL;
32 * src is empty (0);
33 * src is not empty, less than n;
34 * src is not empty, equal to n;
35 * src is not empty, greater than n;
36 */
38 if (n <= 0) {
39 return 0;
40 }
42 dp = dest;
44 do {
45 *dp++ = *src;
46 --n;
47 ++src;
48 } while ((*src != '\0') && (n > 1));
50 ret = n;
52 /* clear remainder of buffer (if any); ANSI semantics */
53 while (n > 0) {
54 *dp++ = '\0';
55 --n;
56 }
57 return ret;
58 }