[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190214125347.GU9224@smile.fi.intel.com>
Date: Thu, 14 Feb 2019 14:53:47 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Xiang Xiao <xiaoxiang781216@...il.com>
Cc: rdunlap@...radead.org, gregkh@...uxfoundation.org,
alexander.shishkin@...ux.intel.com, ohad@...ery.com,
bjorn.andersson@...aro.org, wendy.liang@...inx.com,
arnaud.pouliquen@...com, kumar.gala@...aro.org,
linux-remoteproc@...r.kernel.org, linux-kernel@...r.kernel.org,
Xiang Xiao <xiaoxiang@...omi.com>
Subject: Re: [PATCH V2 1/2] lib/string: add memrchr function
On Thu, Feb 14, 2019 at 02:02:37PM +0800, Xiang Xiao wrote:
> Here is the detailed description for memrchr:
>
> void *memrchr(const void *s, int c, size_t n);
>
> The memrchr() function is like the memchr() function, except
> that it searches backward from the end of the n bytes pointed
> to by s instead of forward from the beginning.
>
> The memrchr() functions return a pointer to the matching byte
> or NULL if the character does not occur in the given memory
> area.
> +void *memrchr(const void *s, int c, size_t n)
> +{
> + const unsigned char *p = s + n;
> +
> + while (n-- != 0) {
Simple:
while (n--) {
> + if ((unsigned char)c == *--p)
> + return (void *)p;
> + }
> + return NULL;
> +}
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists