[POWERPC][XEN] strlcpy() fallout.
authorHollis Blanchard <hollisb@us.ibm.com>
Fri, 9 Feb 2007 20:43:21 +0000 (14:43 -0600)
committerHollis Blanchard <hollisb@us.ibm.com>
Fri, 9 Feb 2007 20:43:21 +0000 (14:43 -0600)
- 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>
xen/arch/powerpc/of-devtree.c
xen/arch/powerpc/of_handler/Makefile
xen/arch/powerpc/of_handler/strlcpy.c [new file with mode: 0644]
xen/arch/powerpc/of_handler/strncpy.c [deleted file]

index 9296a4505ac13bc18bb1e6af1fafed87859bfe12..c437ef4569f4878469d02407d9524426ef75be8b 100644 (file)
@@ -358,7 +358,7 @@ static ofdn_t ofd_node_create(
     n->on_io = 0;
     n->on_pathlen = pathlen;
     n->on_last = ofd_pathsplit_left(path, '/', pathlen);
-    strlcpy(n->on_path, path, pathlen);
+    strlcpy(n->on_path, path, pathlen + 1);
 
     return pos;
 }
index 4954e374de2e43a1f446ba4b2d194288d6b8981d..3b2dfdbe1091dd082ca536a82781da8d0c59eb60 100644 (file)
@@ -27,5 +27,5 @@ obj-y += snprintf.o
 obj-y += strcmp.o
 obj-y += strlen.o
 obj-y += strncmp.o
-obj-y += strncpy.o
+obj-y += strlcpy.o
 obj-y += strnlen.o
diff --git a/xen/arch/powerpc/of_handler/strlcpy.c b/xen/arch/powerpc/of_handler/strlcpy.c
new file mode 100644 (file)
index 0000000..02f33e8
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright IBM Corp. 2005, 2007
+ *
+ * Authors: Jimi Xenidis <jimix@watson.ibm.com>
+ *          Hollis Blanchard <hollisb@us.ibm.com>
+ */
+
+#include <xen/string.h>
+
+size_t
+strlcpy(char *dest, const char *src, size_t n)
+{
+       size_t ret;
+    char *dp;
+
+    /* cases to consider:
+     *   dest is NULL, s is NULL;
+     *   src is empty (0);
+     *   src is not empty, less than n;
+     *   src is not empty, equal to n;
+     *   src is not empty, greater than n;
+     */
+
+    if (n <= 0) {
+        return 0;
+    }
+  
+    dp = dest;
+
+    do {
+        *dp++ = *src;
+        --n;
+        ++src;
+    } while ((*src != '\0') && (n > 1));
+
+    ret = n;
+  
+    /* clear remainder of buffer (if any);  ANSI semantics */
+    while (n > 0) {
+        *dp++ = '\0';
+        --n;
+    }
+    return ret;
+}
diff --git a/xen/arch/powerpc/of_handler/strncpy.c b/xen/arch/powerpc/of_handler/strncpy.c
deleted file mode 100644 (file)
index 76c5c71..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- * Copyright (C) IBM Corp. 2005
- *
- * Authors: Jimi Xenidis <jimix@watson.ibm.com>
- */
-
-#include <xen/string.h>
-
-char *
-strncpy(char *dest, const char *src, size_t n)
-{
-    char *dp;
-
-    /* cases to consider:
-     *   dest is NULL, s is NULL;
-     *   src is empty (0);
-     *   src is not empty, less than n;
-     *   src is not empty, equal to n;
-     *   src is not empty, greater than n;
-     */
-
-    if (n <= 0) {
-        return dest;
-    }
-  
-    dp = dest;
-
-    do {
-        *dp++ = *src;
-        --n;
-        ++src;
-    } while ((*src != '\0') && (n > 0));
-  
-    /* clear remainder of buffer (if any);  ANSI semantics */
-    while (n > 0) {
-        *dp++ = '\0';
-        --n;
-    }
-    return dest;
-}