aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index 5efafed3d6b6..b19b87af65a3 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -493,6 +493,33 @@ char *strsep(char **s, const char *ct)
493EXPORT_SYMBOL(strsep); 493EXPORT_SYMBOL(strsep);
494#endif 494#endif
495 495
496/**
497 * sysfs_streq - return true if strings are equal, modulo trailing newline
498 * @s1: one string
499 * @s2: another string
500 *
501 * This routine returns true iff two strings are equal, treating both
502 * NUL and newline-then-NUL as equivalent string terminations. It's
503 * geared for use with sysfs input strings, which generally terminate
504 * with newlines but are compared against values without newlines.
505 */
506bool sysfs_streq(const char *s1, const char *s2)
507{
508 while (*s1 && *s1 == *s2) {
509 s1++;
510 s2++;
511 }
512
513 if (*s1 == *s2)
514 return true;
515 if (!*s1 && *s2 == '\n' && !s2[1])
516 return true;
517 if (*s1 == '\n' && !s1[1] && !*s2)
518 return true;
519 return false;
520}
521EXPORT_SYMBOL(sysfs_streq);
522
496#ifndef __HAVE_ARCH_MEMSET 523#ifndef __HAVE_ARCH_MEMSET
497/** 524/**
498 * memset - Fill a region of memory with the given value 525 * memset - Fill a region of memory with the given value