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 17:56:02 +0900
commit6ee9f36ec2bd2838cd05612bf588f3e0596535de (patch)
tree0303163c706de96f3802b0f9beea37f2a6005b99
parent1f86a0fa6f7641a865b09412c278312e755b7155 (diff)
downloaddevice-rpi-6ee9f36ec2bd2838cd05612bf588f3e0596535de.tar.gz
device-rpi-6ee9f36ec2bd2838cd05612bf588f3e0596535de.tar.bz2
device-rpi-6ee9f36ec2bd2838cd05612bf588f3e0596535de.zip
Modify to trim string in get_upgrade_state()accepted/tizen/8.0/unified/20240624.160042
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 91616cf..c396ff1 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;
}