Skip to content

Commit aaefed2

Browse files
asjkdave
authored andcommitted
btrfs: add helper for string match ignoring leading/trailing whitespace
Add a generic helper to match the string in a given buffer, and ignore the leading and trailing whitespace. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> [ rename variables, add comments ] Signed-off-by: David Sterba <[email protected]>
1 parent 88090ad commit aaefed2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

fs/btrfs/sysfs.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,25 @@ static ssize_t btrfs_generation_show(struct kobject *kobj,
888888
}
889889
BTRFS_ATTR(, generation, btrfs_generation_show);
890890

891+
/*
892+
* Look for an exact string @string in @buffer with possible leading or
893+
* trailing whitespace
894+
*/
895+
static bool strmatch(const char *buffer, const char *string)
896+
{
897+
const size_t len = strlen(string);
898+
899+
/* Skip leading whitespace */
900+
buffer = skip_spaces(buffer);
901+
902+
/* Match entire string, check if the rest is whitespace or empty */
903+
if (strncmp(string, buffer, len) == 0 &&
904+
strlen(skip_spaces(buffer + len)) == 0)
905+
return true;
906+
907+
return false;
908+
}
909+
891910
static const struct attribute *btrfs_attrs[] = {
892911
BTRFS_ATTR_PTR(, label),
893912
BTRFS_ATTR_PTR(, nodesize),

0 commit comments

Comments
 (0)