lkml.org 
[lkml]   [2018]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v3] string.h: Add str_has_prefix() helper
From
Date
On Fri, 2018-12-21 at 19:06 -0500, Steven Rostedt wrote:
> On Fri, 21 Dec 2018 18:13:16 -0500
> Steven Rostedt <rostedt@goodmis.org> wrote:
>
> > +static __always_inline int str_has_prefix(const char *str, const char *prefix)
>
> I'm thinking it is cleaner to have two helper functions and have them
> both return bool.
>
> static __always_inline bool str_has_prefix(const char *str, const char *prefix)
> {
> return !strncmp(str, prefix, strlen(prefix));
> }
>
> ( I still like to keep the __always_inline, it doesn't hurt )
>
> And I'll make a separate patch that adds:
>
> static __always_inline bool
> str_has_prefix_len(const char *str, const char *prefix, unsigned int *len)
> {
> *len = strlen(prefix);
> return !strncmp(str, prefix, *len) ? *len : 0;
> }
>
> Everyone OK with that?

I guess so as you're the one doing all the work.

Trivia:

Shouldn't the latter function use __kernel_size_t
as that's the actual return type of strlen?

Thanks for keeping at it.

\
 
 \ /
  Last update: 2018-12-22 01:23    [W:0.044 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site