summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSangYoun Kwak <sy.kwak@samsung.com>2024-06-20 17:56:02 +0900
committerSangYoun Kwak <sy.kwak@samsung.com>2024-06-20 18:08:50 +0900
commit7e5138a23dcf6a087a8d78e86c8f3906fde66eee (patch)
treecbf65eb6c71f4604896e940bb238a58731176789
parent174d0d81f7fb18741922db683c8b33fefa2ad6b4 (diff)
downloaddevice-rpi-7e5138a23dcf6a087a8d78e86c8f3906fde66eee.tar.gz
device-rpi-7e5138a23dcf6a087a8d78e86c8f3906fde66eee.tar.bz2
device-rpi-7e5138a23dcf6a087a8d78e86c8f3906fde66eee.zip
To make upgrade state getter work even if there are whitespaces before and after the upgrade state string. Change-Id: I5aa08651110891a0dce3b5fbdaf72cfe427c7d3a Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
-rw-r--r--hw/board/board.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/hw/board/board.c b/hw/board/board.c
index e96f4d5..caa213e 100644
--- a/hw/board/board.c
+++ b/hw/board/board.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
+#include <ctype.h>
#include </hal/include/device/hal-backend-common.h>
#include <libsyscommon/file.h>
@@ -291,6 +292,34 @@ static int set_upgrade_state(char *state)
return sys_set_str(UPGRADE_STATE_PATH, state);
}
+static void trim_str(char *str)
+{
+ if (str == NULL)
+ return;
+
+ size_t str_len = strlen(str);
+ if (str_len == 0)
+ return;
+
+ size_t start_index = 0;
+ size_t end_index = str_len;
+
+ while (start_index < end_index && isspace(str[start_index]))
+ ++start_index;
+ while (start_index < end_index && isspace(str[end_index - 1]))
+ --end_index;
+
+ if (start_index == 0) {
+ str[end_index] = '\0';
+ return;
+ }
+
+ for (int i = 0; (start_index + i) < end_index; ++i)
+ str[i] = str[start_index + i];
+
+ str[end_index - start_index] = '\0';
+}
+
static int get_upgrade_state(char *buffer, const int max_len)
{
int ret = 0;
@@ -305,6 +334,8 @@ static int get_upgrade_state(char *buffer, const int max_len)
if (ret < 0)
return ret;
+ trim_str(buffer);
+
return 0;
}