Date: Thu, 20 Mar 2025 19:53:55 GMT From: =?utf-8?Q?Jean-S=C3=A9bastien?= =?utf-8?Q?P=C3=A9dron?= <dumbbell@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 039eac2463d7 - main - linuxkpi: Add `strim()` Message-ID: <202503201953.52KJrtMZ063911@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=039eac2463d7b0b1b863a57c78cb2e054c210197 commit 039eac2463d7b0b1b863a57c78cb2e054c210197 Author: Jean-Sébastien Pédron <dumbbell@FreeBSD.org> AuthorDate: 2025-02-24 23:30:11 +0000 Commit: Jean-Sébastien Pédron <dumbbell@FreeBSD.org> CommitDate: 2025-03-20 19:43:44 +0000 linuxkpi: Add `strim()` This function trims whitespaces at the end of a string and returns a pointer to the first non-whitespace character. Reviewed by: emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49374 --- sys/compat/linuxkpi/common/include/linux/string.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h index 32470312b78b..f7b64560d254 100644 --- a/sys/compat/linuxkpi/common/include/linux/string.h +++ b/sys/compat/linuxkpi/common/include/linux/string.h @@ -161,6 +161,24 @@ skip_spaces(const char *str) return (__DECONST(char *, str)); } +/* + * This function trims whitespaces at the end of a string and returns a pointer + * to the first non-whitespace character. + */ +static inline char * +strim(char *str) +{ + char *end; + + end = str + strlen(str); + while (end >= str && (*end == '\0' || isspace(*end))) { + *end = '\0'; + end--; + } + + return (skip_spaces(str)); +} + static inline void * memchr_inv(const void *start, int c, size_t length) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202503201953.52KJrtMZ063911>