lkml.org 
[lkml]   [2018]   [Dec]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3] string.h: Add str_has_prefix() helper
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?

-- Steve

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