On 2026-02-19T01:53:01+0100, Alejandro Colomar wrote:
> On 2026-02-18T23:21:34+0100, Alejandro Colomar wrote:
> > Hi Crystal,
> > 
> > On 2026-02-18T21:58:24+0000, Crystal Kolipe via Mutt-dev wrote:
> > > On Wed, Feb 18, 2026 at 03:29:57PM +0100, Alejandro Colomar via Mutt-dev 
> > > wrote:
> > > > BTW, with the macros shown above, one could implement:
> > > > 
> > > >         #define streq(a,b)  (strcmp(a,b) == 0)
> > > > 
> > > >         #define isspace_c(c)            
> > > > (!streq(strchrnul(MUTT_CTYPE_SPACE_C, c), ""))
> > > >         #define isspace_rfc5322_fws(c)  
> > > > (!streq(strchrnul(MUTT_CTYPE_RFC5322_FWS, c), ""))
> > > > 
> > > > Although, in general, using the strspn(3) family of functions directly
> > > > seems more ergonomic.
> > > 
> > > Note that strchrnul() is not available natively on OpenBSD.
> > 
> > D'oh!  Well, I guess we could add it as a fallback there.
> > I hope POSIX takes this API eventually.
> > 
> > Here's a naive definition:
> > 
> >     char *
> >     strchrnul(const char *s, int c)
> >     {
> >             char  *p;
> > 
> >             p = strchr(s, c);
> >             if (p == NULL)
> >                     return (char *) s + strlen(s);
> >             return p;
> 
> This can be compacted into a one-liner:
> 
>               return strchr(s, c) ?: (char *) s + strlen(s);

And avoiding the cast:

        #define strnul(s)  strchr(s, '\0')

        char *
        strchrnul(const char *s, int c)
        {
                return strchr(s, c) ?: strnul(s);
        }

> 
> All compilers that I know, support '?:'.  It will be discussed for
> standardization next month.
> 
> >     }
> > 
> > Here's another one, which might be more or less readable:
> > 
> >     char *
> >     strchrnul(const char *s, int c)
> >     {
> >             char  r[2] = {c, '\0'};
> > 
> >             return (char *) s + strcspn(s, r);
> >     }
> > 
> > Disclaimer: I haven't tested these yet.
> > 
> > 
> > Have a lovely night!
> > Alex
> > 
> > -- 
> > <https://www.alejandro-colomar.es>
> 
> 
> 
> -- 
> <https://www.alejandro-colomar.es>



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

Attachment: signature.asc
Description: PGP signature

Reply via email to