ppc64-diag/ppc64-diag-2.7.9-moving-trim_trail_space-function.patch

137 lines
3.9 KiB
Diff

commit c507319d1b5f0286d67e08a3598949ca4144f475
Author: Sathvika Vasireddy <sv@linux.ibm.com>
Date: Fri Sep 8 12:35:12 2023 +0530
ppc64-diag: Move trim_trail_space() function to common/utils.c
Currently, trim_trail_space() function is used in diags/diag_nvme.c file
to be able to trim trailing white spaces from a given location code. Allow
code reusability by moving the trim_trail_space() function from
diags/diag_nvme.c to common/utils.c.
Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.ibm.com>
diff --git a/common/utils.c b/common/utils.c
index 0312943..2349878 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -24,9 +24,34 @@
#include <fcntl.h>
#include <string.h>
#include <assert.h>
+#include <ctype.h>
#include "utils.h"
+/* trim_trail_space - Trim trailing white spaces from string
+ * @string - Null terminated string to remove white spaces from
+ *
+ * This function will alter the passed string by removing any trailing white spaces and null
+ * terminating it at that point.
+ */
+void trim_trail_space(char *string)
+{
+ char *end;
+ size_t length;
+
+ if (string == NULL)
+ return;
+
+ length = strlen(string);
+ if (length == 0)
+ return;
+
+ end = string + length - 1;
+ while (end >= string && isspace(*end))
+ end--;
+ *(end + 1) = '\0';
+}
+
static int process_child(char *argv[], int pipefd[])
{
int nullfd;
diff --git a/common/utils.h b/common/utils.h
index ec2072d..2459b5b 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -18,6 +18,7 @@
#ifndef UTILS_H
#define UTILS_H
+void trim_trail_space(char *string);
FILE *spopen(char **, pid_t *);
int spclose(FILE *, pid_t);
diff --git a/diags/Makefile.am b/diags/Makefile.am
index 4ac81b8..dea0a79 100644
--- a/diags/Makefile.am
+++ b/diags/Makefile.am
@@ -13,7 +13,8 @@ encl_led_h_files = diags/encl_led.h \
$(diag_common_h_files)
diag_nvme_h_files = diags/diag_nvme.h \
- common/platform.h
+ common/platform.h \
+ common/utils.h
sbin_PROGRAMS += diags/diag_encl diags/encl_led diags/diag_nvme
@@ -41,6 +42,7 @@ diags_encl_led_SOURCES = diags/encl_led.c \
diags_diag_nvme_SOURCES = diags/diag_nvme.c \
common/platform.c \
+ common/utils.c \
$(diag_nvme_h_files)
diags_diag_nvme_LDADD = -lservicelog -lm
diags_diag_nvme_CFLAGS = $(AM_CFLAGS) -Wno-stringop-truncation
diff --git a/diags/diag_nvme.c b/diags/diag_nvme.c
index 2a78034..2606f2c 100644
--- a/diags/diag_nvme.c
+++ b/diags/diag_nvme.c
@@ -27,6 +27,7 @@
#include <sys/utsname.h>
#include "diag_nvme.h"
#include "platform.h"
+#include "utils.h"
#define ITEM_DATA_LENGTH 255
#define MIN_HOURS_ON 720
@@ -71,7 +72,6 @@ static int raw_data_smart(unsigned char **raw_data, uint32_t *raw_data_len, stru
static int raw_data_vpd(unsigned char **raw_data, uint32_t *raw_data_len, struct nvme_ibm_vpd *vpd);
static int regex_controller(char *controller_name, char *device_name);
static void set_notify(struct notify *notify, struct dictionary *dict, int num_elements);
-static void trim_trail_space(char *string);
static long double uint128_to_long_double(uint8_t *data);
int main(int argc, char *argv[]) {
@@ -1426,28 +1426,6 @@ extern void set_vpd_pcie_field(const char *keyword, const char *vpd_data, struct
strncpy(vpd->firmware_level, vpd_data, sizeof(vpd->firmware_level));
}
-/* trim_trail_space - Trim trailing white spaces from string
- * @string - Null terminated string to remove white spaces from
- *
- * This function will alter the passed string by removing any trailing white spaces and null
- * terminating it at that point.
- */
-static void trim_trail_space(char *string) {
- char *end;
- size_t length;
-
- if (string == NULL)
- return;
-
- if ((length = strlen(string)) == 0)
- return;
-
- end = string + length - 1;
- while (end >= string && isspace(*end))
- end--;
- *(end + 1) = '\0';
-}
-
static long double uint128_to_long_double(uint8_t *data) {
int i;
long double value = 0;