aboutsummaryrefslogtreecommitdiffstats
path: root/xen/common/string.c
diff options
context:
space:
mode:
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-01-29 16:04:43 +0000
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-01-29 16:04:43 +0000
commit71200ab6fb7c4af146ef3c73c6c3f99a08e55952 (patch)
tree811b98cc5a20ca469f53bac13a38bd8069a49f78 /xen/common/string.c
parent724873d5c42f051834b6a38a79b462879f95720c (diff)
downloadxen-71200ab6fb7c4af146ef3c73c6c3f99a08e55952.tar.gz
xen-71200ab6fb7c4af146ef3c73c6c3f99a08e55952.tar.bz2
xen-71200ab6fb7c4af146ef3c73c6c3f99a08e55952.zip
Remove strcat/strncat/strcmp/strncmp. Replaced with safer
alternatives (including a new implementation of strlcat). Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'xen/common/string.c')
-rw-r--r--xen/common/string.c97
1 files changed, 20 insertions, 77 deletions
diff --git a/xen/common/string.c b/xen/common/string.c
index df8874c298..562f6cb585 100644
--- a/xen/common/string.c
+++ b/xen/common/string.c
@@ -41,44 +41,6 @@ int strnicmp(const char *s1, const char *s2, size_t len)
}
#endif
-#ifndef __HAVE_ARCH_STRCPY
-/**
- * strcpy - Copy a %NUL terminated string
- * @dest: Where to copy the string to
- * @src: Where to copy the string from
- */
-char * strcpy(char * dest,const char *src)
-{
- char *tmp = dest;
-
- while ((*dest++ = *src++) != '\0')
- /* nothing */;
- return tmp;
-}
-#endif
-
-#ifndef __HAVE_ARCH_STRNCPY
-/**
- * strncpy - Copy a length-limited, %NUL-terminated string
- * @dest: Where to copy the string to
- * @src: Where to copy the string from
- * @count: The maximum number of bytes to copy
- *
- * Note that unlike userspace strncpy, this does not %NUL-pad the buffer.
- * However, the result is not %NUL-terminated if the source exceeds
- * @count bytes.
- */
-char * strncpy(char * dest,const char *src,size_t count)
-{
- char *tmp = dest;
-
- while (count-- && (*dest++ = *src++) != '\0')
- /* nothing */;
-
- return tmp;
-}
-#endif
-
#ifndef __HAVE_ARCH_STRLCPY
/**
* strlcpy - Copy a %NUL terminated string into a sized buffer
@@ -105,52 +67,33 @@ size_t strlcpy(char *dest, const char *src, size_t size)
EXPORT_SYMBOL(strlcpy);
#endif
-#ifndef __HAVE_ARCH_STRCAT
-/**
- * strcat - Append one %NUL-terminated string to another
- * @dest: The string to be appended to
- * @src: The string to append to it
- */
-char * strcat(char * dest, const char * src)
-{
- char *tmp = dest;
-
- while (*dest)
- dest++;
- while ((*dest++ = *src++) != '\0')
- ;
-
- return tmp;
-}
-#endif
-
-#ifndef __HAVE_ARCH_STRNCAT
+#ifndef __HAVE_ARCH_STRLCAT
/**
- * strncat - Append a length-limited, %NUL-terminated string to another
- * @dest: The string to be appended to
- * @src: The string to append to it
- * @count: The maximum numbers of bytes to copy
+ * strlcat - Append a %NUL terminated string into a sized buffer
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ * @size: size of destination buffer
*
- * Note that in contrast to strncpy, strncat ensures the result is
- * terminated.
+ * Compatible with *BSD: the result is always a valid
+ * NUL-terminated string that fits in the buffer (unless,
+ * of course, the buffer size is zero).
*/
-char * strncat(char *dest, const char *src, size_t count)
+size_t strlcat(char *dest, const char *src, size_t size)
{
- char *tmp = dest;
+ size_t slen = strlen(src);
+ size_t dlen = strnlen(dest, size);
+ char *p = dest + dlen;
- if (count) {
- while (*dest)
- dest++;
- while ((*dest++ = *src++)) {
- if (--count == 0) {
- *dest = '\0';
- break;
- }
- }
- }
+ while ((p - dest) < size)
+ if ((*p++ = *src++) == '\0')
+ break;
+
+ if (dlen < size)
+ *(p-1) = '\0';
- return tmp;
+ return slen + dlen;
}
+EXPORT_SYMBOL(strlcat);
#endif
#ifndef __HAVE_ARCH_STRCMP