From 9d3567d9ce986237386476e915e82a8e746bd261 Mon Sep 17 00:00:00 2001 From: Jan Polensky Date: Fri, 29 Aug 2025 19:02:57 +0200 Subject: [PATCH] libutil/util_libc.c: Move remove_whitespace() to util_str_rm_whitespace() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Relocate remove_whitespace() from zdsfs to libutil/util_str.c, renaming it to util_str_rm_whitespace() to make the helper available project-wide. Acked-by: Thomas Richter Reviewed-by: Jan Höppner Signed-off-by: Jan Polensky Signed-off-by: Jan Höppner --- include/lib/util_str.h | 17 +++++++++++++++++ libutil/util_str.c | 33 +++++++++++++++++++++++++++++++++ zdsfs/zdsfs.c | 17 +++-------------- 3 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 include/lib/util_str.h create mode 100644 libutil/util_str.c diff --git a/include/lib/util_str.h b/include/lib/util_str.h new file mode 100644 index 00000000..c8a32deb --- /dev/null +++ b/include/lib/util_str.h @@ -0,0 +1,17 @@ +/** + * @defgroup util_str_h util_str: String functions + * @{ + * @brief Manipulate and work with strings + * + * Copyright IBM Corp. 2025 + * + * s390-tools is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#ifndef LIB_UTIL_STR_H +#define LIB_UTIL_STR_H + +void util_str_rm_whitespace(const char *src, char *dest); + +#endif /** LIB_UTIL_STR_H @} */ diff --git a/libutil/util_str.c b/libutil/util_str.c new file mode 100644 index 00000000..71f585e1 --- /dev/null +++ b/libutil/util_str.c @@ -0,0 +1,33 @@ +/* + * util - Utility function library + * + * Manipulate and work with strings + * + * Copyright IBM Corp. 2025 + * + * s390-tools is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#include + +#include "lib/util_str.h" + +/** + * Copy characters from \a src to \a dest, omitting all blank characters + * (spaces and tabs). The resulting string in \a dest will be NUL terminated. + * + * @param[in] src Source string + * @param[out] dest Destination buffer + */ +void util_str_rm_whitespace(const char *src, char *dest) +{ + while (*src != '\0') { + if (!isblank(*src)) { + *dest = *src; + dest++; + } + src++; + } + *dest = '\0'; +} diff --git a/zdsfs/zdsfs.c b/zdsfs/zdsfs.c index 5c66fb4d..4c7adb52 100644 --- a/zdsfs/zdsfs.c +++ b/zdsfs/zdsfs.c @@ -33,6 +33,7 @@ #include "lib/libzds.h" #include "lib/util_libc.h" +#include "lib/util_str.h" #include "lib/zt_common.h" #define COMP "zdsfs: " @@ -1369,18 +1370,6 @@ static void zdsfs_process_device_file(const char *devfile) free(buffer); } -void remove_whitespace(const char *s, char *t) -{ - while (*s != '\0') { - if (!isblank(*s)) { - *t = *s; - t++; - } - s++; - } - *t = '\0'; -} - static void zdsfs_process_config_file(const char *config) { char line[MAX_LINE_LENGTH]; @@ -1403,7 +1392,7 @@ static void zdsfs_process_config_file(const char *config) /* remove all whitespaces */ tmp = util_malloc(strlen(line) + 1); - remove_whitespace(line, tmp); + util_str_rm_whitespace(line, tmp); key = strtok(tmp, delimiter); if (strcmp(key, "restserver") == 0) { @@ -1496,7 +1485,7 @@ static int zdsfs_process_dataset_conf(const char *config) linecount++; /* remove all whitespaces */ tmp = util_malloc(strlen(line) + 1); - remove_whitespace(line, tmp); + util_str_rm_whitespace(line, tmp); /* skip empty lines */ if (*tmp == '\n' || *tmp == '#') { free(tmp);