[LTP] [PATCH v4 3/9] tst_supported_fs: Implement skip list

Petr Vorel pvorel@suse.cz
Fri Sep 9 12:02:20 CEST 2022


> > +			fs = optarg;
> > +			for (i = 0; i < cnt; i++)
> > +				skiplist[i] = strtok_r(fs, TST_TO_STR(SKIP_DELIMITER), &fs);
> > +			break;

> It may be a bit cleaner to put this part into a function i.e.

> 	skiplist = parse_skiplist(optarg);

Suppose code below is good enough (will be in v5).
Thanks for your review!

Kind regards,
Petr

char **parse_skiplist(char *fs)
{
	char **skiplist = NULL;
	int i, cnt = 1;

	for (i = 0; fs[i]; i++) {
		if (optarg[i] == SKIP_DELIMITER)
			cnt++;
	}

	skiplist = malloc(++cnt * sizeof(char *));
	if (!skiplist) {
		fprintf(stderr, "malloc() failed\n");
		return NULL;
	}

	for (i = 0; i < cnt; i++)
		skiplist[i] = strtok_r(fs, TST_TO_STR(SKIP_DELIMITER), &fs);

	return skiplist;
}

int main(int argc, char *argv[])
{
	const char *const *filesystems;
	int i, ret;
	char **skiplist = NULL;

	while ((ret = getopt(argc, argv, "hs:"))) {
		if (ret < 0)
			break;

		switch (ret) {
		case '?':
			usage();
			return 1;

		case 'h':
			usage();
			return 0;

		case 's':
			skiplist = parse_skiplist(optarg);
			if (!skiplist)
				return 1;
			break;
		}
	}
...


More information about the ltp mailing list