On Fri, Dec 21, 2018 at 11:40 AM Steven Rostedt <[email protected]> wrote:
>
> OK, what about if we just use strlen() and say that this macro is not
> safe for parameters with side effects.
I think gcc follows simple assignments just fine, and does the
optimized strlen() for them too.
So why not just do
#define have_prefix(str,prefix) ({ \
const char *__pfx = prefix; \
size_t __pfxlen = strlen(__pfx); \
strncmp(str, __pfx, __pfxlen) ? 0 : __pfxlen); })
and be done with it safely?
The above is ENTIRELY untested.
Linus