Re: [PATCH v2 1/2] string: Add strprefix(), and deprecate str_has_prefix()

From: Maciej W. Rozycki

Date: Sun Nov 08 2026 - 06:06:18 EST


On Sat, 7 Nov 2026, Alejandro Colomar wrote:

> Hi Maciej,
>
> > Date: 2026-11-07 02:44:23+0000
> > From: "Maciej W. Rozycki" <macro@xxxxxxxxxxx>
> >
> > On Thu, 5 Nov 2026, Alejandro Colomar wrote:
> >
> > > Do you think strafterprefix() would be better? Do you have any other
> > > suggestions?
> >
> > FWIW strsuffix() seems an obvious choice to me. After all what the API
> > does is request the string's suffix beyond the specified leading part.
>
> Actually, strsuffix() is something else:
>
> char *
> strsuffix_(const char *str, const char *suffix)
> {
> ptrdiff_t off;
>
> off = strlen(str) - strlen(suffix);
> if (off < 0)
> return NULL;
>
> if (!streq(str + off, suffix))
> return NULL;
>
> return str + off;
> }
>
> It finds the start of a suffix in a string. That is:
>
> strcmp(strsuffix("foobar", "bar"), "bar") == 0;

Hmm, I'd have called that strskipto(). If that's not possible for some
reason (I can't see it used in Linux), then strskip() or strskipover()
could be used for this API.

FWIW,

Maciej