summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2008-08-20 17:44:35 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2008-08-20 17:46:54 +0200
commitbcb049a7027f4e22d9ebb0e84514f1eb86cad65e (patch)
tree1900f25fb4d055eaaa7c97b83f79b1851c942da4
parent7163d8fd2dfe656baf68f2a94d633073c979b45c (diff)
downloadbarebox-bcb049a7027f4e22d9ebb0e84514f1eb86cad65e.tar.gz
barebox-bcb049a7027f4e22d9ebb0e84514f1eb86cad65e.tar.xz
string: add typechecking for strchr, strrchr, strstr
These functions offered an excellent possibility to bypass compiler type checking. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/linux/string.h18
-rw-r--r--lib/string.c8
2 files changed, 19 insertions, 7 deletions
diff --git a/include/linux/string.h b/include/linux/string.h
index 427509b592..20b0829609 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -15,6 +15,18 @@ extern char * strsep(char **,const char *);
extern __kernel_size_t strspn(const char *,const char *);
+#define strchr(s, c) ({ \
+ (typeof(&(s)[0]))(_strchr((s), c)); \
+ })
+
+#define strrchr(s, c) ({ \
+ (typeof(&(s)[0]))(_strrchr((s), c)); \
+ })
+
+#define strstr(s1, s2) ({ \
+ (typeof(&(s1)[0]))(_strstr((s1), (s2))); \
+ })
+
/*
* Include machine specific inline routines
*/
@@ -39,13 +51,13 @@ extern int strcmp(const char *,const char *);
extern int strncmp(const char *,const char *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRCHR
-extern char * strchr(const char *,int);
+extern char * _strchr(const char *,int);
#endif
#ifndef __HAVE_ARCH_STRRCHR
-extern char * strrchr(const char *,int);
+extern char * _strrchr(const char *,int);
#endif
#ifndef __HAVE_ARCH_STRSTR
-extern char * strstr(const char *,const char *);
+extern char * _strstr(const char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRLEN
extern __kernel_size_t strlen(const char *);
diff --git a/lib/string.c b/lib/string.c
index c0716df526..520eb74f12 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -160,7 +160,7 @@ EXPORT_SYMBOL(strncmp);
* @s: The string to be searched
* @c: The character to search for
*/
-char * strchr(const char * s, int c)
+char * _strchr(const char * s, int c)
{
for(; *s != (char) c; ++s)
if (*s == '\0')
@@ -168,7 +168,7 @@ char * strchr(const char * s, int c)
return (char *) s;
}
#endif
-EXPORT_SYMBOL(strchr);
+EXPORT_SYMBOL(_strchr);
#ifndef __HAVE_ARCH_STRRCHR
/**
@@ -176,7 +176,7 @@ EXPORT_SYMBOL(strchr);
* @s: The string to be searched
* @c: The character to search for
*/
-char * strrchr(const char * s, int c)
+char * _strrchr(const char * s, int c)
{
const char *p = s + strlen(s);
do {
@@ -522,7 +522,7 @@ EXPORT_SYMBOL(memscan);
* @s1: The string to be searched
* @s2: The string to search for
*/
-char * strstr(const char * s1,const char * s2)
+char * _strstr(const char * s1,const char * s2)
{
int l1, l2;