ia64/xen-unstable

changeset 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 4613ee57e9b3
children 376940a942e9
files xen/arch/powerpc/of-devtree.c xen/arch/powerpc/of_handler/Makefile xen/arch/powerpc/of_handler/strlcpy.c xen/arch/powerpc/of_handler/strncpy.c
line diff
     1.1 --- a/xen/arch/powerpc/of-devtree.c	Wed Feb 07 18:53:33 2007 -0600
     1.2 +++ b/xen/arch/powerpc/of-devtree.c	Fri Feb 09 14:43:21 2007 -0600
     1.3 @@ -358,7 +358,7 @@ static ofdn_t ofd_node_create(
     1.4      n->on_io = 0;
     1.5      n->on_pathlen = pathlen;
     1.6      n->on_last = ofd_pathsplit_left(path, '/', pathlen);
     1.7 -    strlcpy(n->on_path, path, pathlen);
     1.8 +    strlcpy(n->on_path, path, pathlen + 1);
     1.9  
    1.10      return pos;
    1.11  }
     2.1 --- a/xen/arch/powerpc/of_handler/Makefile	Wed Feb 07 18:53:33 2007 -0600
     2.2 +++ b/xen/arch/powerpc/of_handler/Makefile	Fri Feb 09 14:43:21 2007 -0600
     2.3 @@ -27,5 +27,5 @@ obj-y += snprintf.o
     2.4  obj-y += strcmp.o
     2.5  obj-y += strlen.o
     2.6  obj-y += strncmp.o
     2.7 -obj-y += strncpy.o
     2.8 +obj-y += strlcpy.o
     2.9  obj-y += strnlen.o
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/xen/arch/powerpc/of_handler/strlcpy.c	Fri Feb 09 14:43:21 2007 -0600
     3.3 @@ -0,0 +1,58 @@
     3.4 +/*
     3.5 + * This program is free software; you can redistribute it and/or modify
     3.6 + * it under the terms of the GNU General Public License as published by
     3.7 + * the Free Software Foundation; either version 2 of the License, or
     3.8 + * (at your option) any later version.
     3.9 + *
    3.10 + * This program is distributed in the hope that it will be useful,
    3.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.13 + * GNU General Public License for more details.
    3.14 + *
    3.15 + * You should have received a copy of the GNU General Public License
    3.16 + * along with this program; if not, write to the Free Software
    3.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    3.18 + *
    3.19 + * Copyright IBM Corp. 2005, 2007
    3.20 + *
    3.21 + * Authors: Jimi Xenidis <jimix@watson.ibm.com>
    3.22 + *          Hollis Blanchard <hollisb@us.ibm.com>
    3.23 + */
    3.24 +
    3.25 +#include <xen/string.h>
    3.26 +
    3.27 +size_t
    3.28 +strlcpy(char *dest, const char *src, size_t n)
    3.29 +{
    3.30 +	size_t ret;
    3.31 +    char *dp;
    3.32 +
    3.33 +    /* cases to consider:
    3.34 +     *   dest is NULL, s is NULL;
    3.35 +     *   src is empty (0);
    3.36 +     *   src is not empty, less than n;
    3.37 +     *   src is not empty, equal to n;
    3.38 +     *   src is not empty, greater than n;
    3.39 +     */
    3.40 +
    3.41 +    if (n <= 0) {
    3.42 +        return 0;
    3.43 +    }
    3.44 +  
    3.45 +    dp = dest;
    3.46 +
    3.47 +    do {
    3.48 +        *dp++ = *src;
    3.49 +        --n;
    3.50 +        ++src;
    3.51 +    } while ((*src != '\0') && (n > 1));
    3.52 +
    3.53 +    ret = n;
    3.54 +  
    3.55 +    /* clear remainder of buffer (if any);  ANSI semantics */
    3.56 +    while (n > 0) {
    3.57 +        *dp++ = '\0';
    3.58 +        --n;
    3.59 +    }
    3.60 +    return ret;
    3.61 +}
     4.1 --- a/xen/arch/powerpc/of_handler/strncpy.c	Wed Feb 07 18:53:33 2007 -0600
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,54 +0,0 @@
     4.4 -/*
     4.5 - * This program is free software; you can redistribute it and/or modify
     4.6 - * it under the terms of the GNU General Public License as published by
     4.7 - * the Free Software Foundation; either version 2 of the License, or
     4.8 - * (at your option) any later version.
     4.9 - *
    4.10 - * This program is distributed in the hope that it will be useful,
    4.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.13 - * GNU General Public License for more details.
    4.14 - *
    4.15 - * You should have received a copy of the GNU General Public License
    4.16 - * along with this program; if not, write to the Free Software
    4.17 - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    4.18 - *
    4.19 - * Copyright (C) IBM Corp. 2005
    4.20 - *
    4.21 - * Authors: Jimi Xenidis <jimix@watson.ibm.com>
    4.22 - */
    4.23 -
    4.24 -#include <xen/string.h>
    4.25 -
    4.26 -char *
    4.27 -strncpy(char *dest, const char *src, size_t n)
    4.28 -{
    4.29 -    char *dp;
    4.30 -
    4.31 -    /* cases to consider:
    4.32 -     *   dest is NULL, s is NULL;
    4.33 -     *   src is empty (0);
    4.34 -     *   src is not empty, less than n;
    4.35 -     *   src is not empty, equal to n;
    4.36 -     *   src is not empty, greater than n;
    4.37 -     */
    4.38 -
    4.39 -    if (n <= 0) {
    4.40 -        return dest;
    4.41 -    }
    4.42 -  
    4.43 -    dp = dest;
    4.44 -
    4.45 -    do {
    4.46 -        *dp++ = *src;
    4.47 -        --n;
    4.48 -        ++src;
    4.49 -    } while ((*src != '\0') && (n > 0));
    4.50 -  
    4.51 -    /* clear remainder of buffer (if any);  ANSI semantics */
    4.52 -    while (n > 0) {
    4.53 -        *dp++ = '\0';
    4.54 -        --n;
    4.55 -    }
    4.56 -    return dest;
    4.57 -}