From: SangYoun Kwak Date: Thu, 20 Jun 2024 08:56:02 +0000 (+0900) Subject: Modify to trim string in get_upgrade_state() X-Git-Tag: accepted/tizen/8.0/unified/20240624.160042^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ee9f36ec2bd2838cd05612bf588f3e0596535de;p=platform%2Fhal%2Fbackend%2Frpi%2Fdevice-rpi.git Modify to trim string in get_upgrade_state() 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 --- 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 #include #include +#include #include #include @@ -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; }