X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstring.c;h=b19b87af65a3553a0650d679cabfac9fecd4eb3b;hb=325dcfdc81f124812a7b692354996ef7fe5b90ed;hp=5efafed3d6b65df9e56f968e32fb012f4cd13c65;hpb=afc2e82c0851317931a9bfdb98271253371825c6;p=linux-2.6-omap-h63xx.git diff --git a/lib/string.c b/lib/string.c index 5efafed3d6b..b19b87af65a 100644 --- a/lib/string.c +++ b/lib/string.c @@ -493,6 +493,33 @@ char *strsep(char **s, const char *ct) EXPORT_SYMBOL(strsep); #endif +/** + * sysfs_streq - return true if strings are equal, modulo trailing newline + * @s1: one string + * @s2: another string + * + * This routine returns true iff two strings are equal, treating both + * NUL and newline-then-NUL as equivalent string terminations. It's + * geared for use with sysfs input strings, which generally terminate + * with newlines but are compared against values without newlines. + */ +bool sysfs_streq(const char *s1, const char *s2) +{ + while (*s1 && *s1 == *s2) { + s1++; + s2++; + } + + if (*s1 == *s2) + return true; + if (!*s1 && *s2 == '\n' && !s2[1]) + return true; + if (*s1 == '\n' && !s1[1] && !*s2) + return true; + return false; +} +EXPORT_SYMBOL(sysfs_streq); + #ifndef __HAVE_ARCH_MEMSET /** * memset - Fill a region of memory with the given value