mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 15:22:20 +02:00
Merge branch 'snprintf' into 'master'
at.c: use snprintf(3) See merge request mobian1/devices/eg25-manager!28
This commit is contained in:
23
src/at.c
23
src/at.c
@@ -58,15 +58,28 @@ gboolean at_send_command(struct EG25Manager *manager)
|
||||
|
||||
/* Send AT command */
|
||||
if (at_cmd->subcmd == NULL && at_cmd->value == NULL && at_cmd->expected == NULL)
|
||||
len = sprintf(command, "AT+%s\r\n", at_cmd->cmd);
|
||||
len = snprintf(command, sizeof(command), "AT+%s\r\n", at_cmd->cmd);
|
||||
else if (at_cmd->subcmd == NULL && at_cmd->value == NULL)
|
||||
len = sprintf(command, "AT+%s?\r\n", at_cmd->cmd);
|
||||
len = snprintf(command, sizeof(command), "AT+%s?\r\n", at_cmd->cmd);
|
||||
else if (at_cmd->subcmd == NULL && at_cmd->value)
|
||||
len = sprintf(command, "AT+%s=%s\r\n", at_cmd->cmd, at_cmd->value);
|
||||
len = snprintf(command, sizeof(command),"AT+%s=%s\r\n", at_cmd->cmd, at_cmd->value);
|
||||
else if (at_cmd->subcmd && at_cmd->value == NULL)
|
||||
len = sprintf(command, "AT+%s=\"%s\"\r\n", at_cmd->cmd, at_cmd->subcmd);
|
||||
len = snprintf(command, sizeof(command), "AT+%s=\"%s\"\r\n", at_cmd->cmd, at_cmd->subcmd);
|
||||
else if (at_cmd->subcmd && at_cmd->value)
|
||||
len = sprintf(command, "AT+%s=\"%s\",%s\r\n", at_cmd->cmd, at_cmd->subcmd, at_cmd->value);
|
||||
len = snprintf(command, sizeof(command), "AT+%s=\"%s\",%s\r\n", at_cmd->cmd, at_cmd->subcmd, at_cmd->value);
|
||||
|
||||
if (len < 0) {
|
||||
g_warning("snprintf(3) failed");
|
||||
at_next_command(manager);
|
||||
return FALSE;
|
||||
}
|
||||
else if (len >= sizeof(command)) {
|
||||
g_warning("AT command does not fit into buffer "
|
||||
"(%d bytes required, %zu available)", len, sizeof(command));
|
||||
at_next_command(manager);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
manager->at_callback = at_cmd->callback;
|
||||
|
||||
ret = write(manager->at_fd, command, len);
|
||||
|
Reference in New Issue
Block a user