char *test_plural_parts() { char **parts = NULL; int rc; rc = plural_parts("beli", &parts); mu_assert(rc == 1, "beli has 1 part"); mu_assert(strcmp("beli", parts[0]) == 0, "beli is returned in the parts"); free_parts(rc, &parts); rc = plural_parts("beli-beli", &parts); mu_assert(rc == 2, "beli-beli has 2 parts"); mu_assert(strcmp("beli", parts[0]) == 0, "beli-beli has 2 parts"); mu_assert(strcmp("beli", parts[1]) == 0, "beli-beli has 2 parts"); free_parts(rc, &parts); rc = plural_parts("beli-beli-ku", &parts); mu_assert(rc == 2, "beli-beli-ku has 2 parts"); mu_assert(strcmp("beli", parts[0]) == 0, "For beli-beli-ku, first part should be beli"); mu_assert(strcmp("beli-ku", parts[1]) == 0, "For beli-beli-ku, second part should be beli-ku"); free_parts(rc, &parts); return NULL; }
static int parse_cmdline(struct cmdline_parts **parts, const char *cmdline) { int ret; char *buf; char *pbuf; char *next; struct cmdline_parts **next_parts; *parts = NULL; next = pbuf = buf = strdup(cmdline); if (!buf) { DBG_MSG("Fail to dup cmdline, size=%d\n", strlen(cmdline)); return -ENOMEM; } next_parts = parts; while (next && *pbuf) { next = strchr(pbuf, ';'); if (next) *next = '\0'; ret = parse_parts(next_parts, pbuf); if (ret) goto fail; if (next) pbuf = ++next; next_parts = &(*next_parts)->next_parts; } if (!*parts) { DBG_MSG("cmdline partition has not valid partition."); ret = -EINVAL; goto fail; } ret = 0; done: free(buf); return ret; fail: free_parts(parts); goto done; }
static struct cmdline_parts *get_cmdline_parts(char *cmdline_string) { struct cmdline_parts *cmdline_parts = NULL; if (!cmdline_string) goto fail; if (parse_cmdline(&cmdline_parts, cmdline_string) || !cmdline_parts) goto fail; return cmdline_parts; fail: if (cmdline_parts) free_parts(&cmdline_parts); return NULL; }
static struct cmdline_parts *get_cmdline_parts(char *cmdline_string) { char *parts_string = NULL; struct cmdline_parts *tmp_cmdline_parts = NULL; if (!cmdline_string) { goto fail; } parts_string = strstr(cmdline_string, "mmcblk0:"); if (!parts_string) { goto fail; } if (parse_cmdline(&tmp_cmdline_parts, parts_string) || !tmp_cmdline_parts) goto fail; return tmp_cmdline_parts; fail: if (tmp_cmdline_parts) free_parts(&tmp_cmdline_parts); return NULL; }