[LTP] [PATCH v3 3/4] shell: add kconfig parse api

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Mon Jan 10 09:46:58 CET 2022


Hi Li
> On Mon, Jan 10, 2022 at 2:26 PM Yang Xu<xuyang2018.jy@fujitsu.com>  wrote:
>
>> +1.7 Parsing kernel .config
>> +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> +The shell library provides an implementation of the kconfig parsing interface
>> +compatible with the C version.
>
>   ^ consistent with the C version.
Yes.
>
>> +++ b/testcases/lib/tst_check_kconfigs.c
>> @@ -0,0 +1,54 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
>> +
>> +#include<stdio.h>
>> +#include<string.h>
>> +#include<limits.h>
>> +#include<stdlib.h>
>> +#include "tst_kconfig.h"
>> +
>> +int main(int argc, const char *argv[])
>> +{
>> +       char delim[2];
>> +       char str[PATH_MAX];
>> +       char *result = NULL;
>> +       char *next = NULL;
>> +       int i = 0, j = 0, ret = 0;
>> +
>> +       if (argc<  3) {
>> +               fprintf(stderr, "Please provide kernel kconfig list and delims\n");
>> +               return 1;
>> +       }
>> +
>> +       if (strlen(argv[2]) != 1) {
>> +               fprintf(stderr, "The delim must be a single character\n");
>> +               return 1;
>> +       }
>> +
>> +       strcpy(str, argv[1]);
>> +       strcpy(delim, argv[2]);
>> +
>> +       result = strtok_r(str, delim,&next);
>> +       for (i = 0; result != NULL; i++)
>> +               result = strtok_r(NULL, delim,&next);
>> +
>> +       strcpy(str, argv[1]);
>> +       char **kconfigs = (char **)malloc(++i * sizeof(char *));
>> +
>> +       result = strtok_r(str, delim,&next);
>> +       for (i = 0; result != NULL; i++) {
>> +               kconfigs[i] = (char *)malloc(sizeof(char) * strlen(result));
>> +               strcpy(kconfigs[i], result);
>
> I guess there is no need to allocate additional memory to do strcpy.
> As the kconfigs[i] is just a pointer, we can assign the 'result' to it directly.
>
> i.e.
>
>         for (i = 0; result != NULL; i++) {
>                 kconfigs[i] = result;
>                 result = strtok_r(NULL, delim,&next);
>         }
>
Yes, thanks for your review.

We can modify those when maintainer merges it.

Best Regard
Yang Xu
> Otherwise looks good.
> Reviewed-by: Li Wang<liwang@redhat.com>
>
> --
> Regards,
> Li Wang
>


More information about the ltp mailing list