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

From: Alejandro Colomar

Date: Sat Nov 07 2026 - 02:33:38 EST


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;


Have a lovely day!
Alex

>
> Maciej

--
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature