return true;
}
+static bool test_get_user_string(const char *msg, char *buf, int buf_size)
+{
+ if (msg == NULL || buf == NULL || buf_size < 2)
+ return false;
+
+ int rv;
+ printf("%s\n", msg);
+ memset(buf, 0, buf_size);
+ rv = read(0, buf, buf_size - 1);
+
+ if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
+ buf[0] = '\0';
+ return false;
+ }
+
+ buf[rv-1] = '\0';
+ return true;
+}
+
static const char *__convert_tethering_type_to_str(const tethering_type_e type)
{
static char str_buf[COMMON_STR_BUF_LEN] = {0, };
static int test_tethering_wifi_set_ssid(void)
{
int ret;
- char ssid[100];
+ char ssid[100] = {0, };
- printf("Input SSID for Wi-Fi tethering: ");
- ret = scanf("%99s", ssid);
- if (ret < 0) {
- printf("scanf is failed!!\n");
+ if (test_get_user_string("Input SSID for Wi-Fi tethering:",
+ ssid, 100) == false) {
+ printf("Failed to read user input!!\n");
return -1;
}
static int test_tethering_wifi_set_passphrase(void)
{
int ret;
- char passphrase[100];
+ char passphrase[100] = {0, };
- printf("Input passphrase for Wi-Fi tethering: ");
- ret = scanf("%99s", passphrase);
- if (ret < 0) {
- printf("scanf is failed!!\n");
+ if (test_get_user_string("Input passphrase for Wi-Fi tethering:",
+ passphrase, 100) == false) {
+ printf("Failed to read user input!!\n");
return -1;
}
static int test_tethering_wifi_set_wps_pin(void)
{
int ret = 0;
- char wps_pin[128];
+ char wps_pin[128] = {0, };
- printf("Input WPS PIN: ");
- ret = scanf("%127s", wps_pin);
+ if (test_get_user_string("Input WPS PIN: ",
+ wps_pin, 128) == false) {
+ printf("Failed to read user input!!\n");
+ return -1;
+ }
ret = tethering_wifi_set_wps_pin(th, wps_pin);
if (__is_err(ret) == true) {