[LTP] [PATCH v4 3/5] shell: add kconfig parse api

Li Wang liwang@redhat.com
Thu Jan 13 10:42:08 CET 2022


> > The lastest code should be as below:
> >
> > int main(int argc, char *argv[])
> > {
> >           char *str = argv[1];
> >           char *delim = argv[2];
> >           unsigned int i, cnt = 1;
> >           int ret = 0;

The statement of ‘ret‘ can move up to unsigned int as well.
Otherwise, this version LGTM.

> >
> >           if (argc == 2) {
> >                   delim = ",";
> >           } else if (argc == 3) {
> >                   if (strlen(delim)>  1) {
> >                           fprintf(stderr, "The delim must be a single
> > character\n");
> >                           return 1;
> >                   }
> >           } else {
> >                   fprintf(stderr, "Please provide kernel kconfig list and
> > delim "
> >                                   "(optinal, default value is ',')\n");
> >                   return 1;
> >           }
> >
> >           for (i = 0; str[i]; i++) {
> >                   if (str[i] == delim[0])
> >                           cnt++;
> >           }
> >
> >           char **kconfigs = malloc(++cnt * sizeof(char *));
> >
> >           for (i = 0; i<  cnt; i++)
> >                   kconfigs[i] = strtok_r(str, delim,&str);
> >
> >           if (tst_kconfig_check((const char * const*)kconfigs))
> >                   ret = 1;
> >
> >           free(kconfigs);
> >           return ret;
> > }


-- 
Regards,
Li Wang



More information about the ltp mailing list