From: Anand Jain Date: Wed, 28 Oct 2020 13:14:45 +0000 (+0800) Subject: btrfs: add helper for string match ignoring leading/trailing whitespace X-Git-Tag: accepted/tizen/unified/20230118.172025~7911^2~203 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aaefed207875a0f0c46c4a50dcd0aca0d56b9062;p=platform%2Fkernel%2Flinux-rpi.git 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 Signed-off-by: Anand Jain Reviewed-by: David Sterba [ rename variables, add comments ] Signed-off-by: David Sterba --- diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index fcd6c7a..b2f653e 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -888,6 +888,25 @@ static ssize_t btrfs_generation_show(struct kobject *kobj, } BTRFS_ATTR(, generation, btrfs_generation_show); +/* + * Look for an exact string @string in @buffer with possible leading or + * trailing whitespace + */ +static bool strmatch(const char *buffer, const char *string) +{ + const size_t len = strlen(string); + + /* Skip leading whitespace */ + buffer = skip_spaces(buffer); + + /* Match entire string, check if the rest is whitespace or empty */ + if (strncmp(string, buffer, len) == 0 && + strlen(skip_spaces(buffer + len)) == 0) + return true; + + return false; +} + static const struct attribute *btrfs_attrs[] = { BTRFS_ATTR_PTR(, label), BTRFS_ATTR_PTR(, nodesize),