[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1452242596.30729.425.camel@linux.intel.com>
Date: Fri, 08 Jan 2016 10:43:16 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Cc: Tejun Heo <tj@...nel.org>,
Linus Walleij <linus.walleij@...aro.org>,
Dmitry Eremin-Solenikov <dbaryshkov@...il.com>,
linux-kernel@...r.kernel.org, linux-pm@...r.kernel.org,
"David S. Miller" <davem@...emloft.net>,
David Airlie <airlied@...ux.ie>,
Andrew Morton <akpm@...ux-foundation.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: Re: [PATCH v1 1/8] lib/string: introduce match_string() helper
On Fri, 2016-01-08 at 09:13 +0900, Sergey Senozhatsky wrote:
> On (01/07/16 14:06), Andy Shevchenko wrote:
> >
> > From time to time we have to match a string in an array. Make a
> > simple helper
> > for that purpose.
> >
>
> Hello,
>
> strncmp() case seems to be quite common.
Like I answered to Rasmus, please, provide real examples.
>
> > +int match_string(const char * const *array, size_t len, const char
> > *string)
> ^^^^^^^
> a nitpick, [to me] `len' looks a bit confusing, usually it's array
> 'size'.
Agreed. I would change it to plain 'n'.
>
> > +{
> > + int index = 0;
> > + const char *item;
> > +
> > + do {
> > + item = array[index];
> > + if (!item)
> > + break;
> > + if (!strcmp(item, string))
> > + return index;
> > + } while (++index < len || !len);
> > +
> > + return -ENODATA;
> > +}
>
>
> do you want to do something like this:
>
> /*
> * hm, how to name this thing... nmatch_string() or
> match_nstring()...
> * nmatch_string() _probably_ better, match_nstring() is totally
> cryptic.
> */
> int nmatch_string(array, array_size, string, string_len)
> {
> do {
> strncmp();
> } while ();
> }
>
> int match_string(array, array_size, string)
> {
> return nmatch_string(array, array_size, string,
> strlen(string));
> }
See above.
--
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Intel Finland Oy
Powered by blists - more mailing lists