Skip to content

Commit

Permalink
IOC Mediator: Replace strtok with strsep
Browse files Browse the repository at this point in the history
Replace strtok function with strsep function.

Tracked-On: #1401
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Shuo Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
  • Loading branch information
yliu80 authored and wenlingz committed Oct 10, 2018
1 parent 69edccc commit 25db6b7
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions devicemodel/hw/platform/ioc.c
Expand Up @@ -1548,27 +1548,37 @@ vm_resume_handler(void *arg)
int
ioc_parse(const char *opts)
{
char *tmp;
char *param = strdup(opts);
char *tmp, *str, *cpy;
int rc;

tmp = strtok(param, ",");
rc = snprintf(virtual_uart_path, sizeof(virtual_uart_path), "%s", param);
cpy = str = strdup(opts);
if (!cpy)
return -ENOMEM;

/*
* IOC mediator parameters format as below:
* <virtual_uart_path>[,<wakeup_reason>]
* For e.g. "/run/acrn/ioc_vm1,0x20"
*/
tmp = strsep(&str, ",");
if (!tmp)
goto exit;

rc = snprintf(virtual_uart_path, sizeof(virtual_uart_path), "%s", tmp);
if (rc < 0 || rc >= sizeof(virtual_uart_path))
WPRINTF("ioc gets incomplete virtual uart path:%s\r\n",
virtual_uart_path);
if (tmp != NULL) {
tmp = strtok(NULL, ",");
if (tmp != NULL) {
ioc_boot_reason = strtoul(tmp, 0, 0);

/*
* Mask invalid bits of wakeup reason for IOC mediator
*/
ioc_boot_reason &= CBC_WK_RSN_ALL;
}
}
free(param);

if (!str)
goto exit;

ioc_boot_reason = strtoul(str, 0, 0);

/* Mask invalid bits of wakeup reason for IOC mediator */
ioc_boot_reason &= CBC_WK_RSN_ALL;

exit:
free(cpy);
return 0;
}

Expand Down

0 comments on commit 25db6b7

Please sign in to comment.