On Mon, Jul 28, 2025 at 02:21:50PM +0100, Frediano Ziglio wrote:
> On Sun, Jul 27, 2025 at 2:57 AM Alec Brown via Grub-devel 
> <grub-devel@gnu.org> wrote:
> >
> > Add the functions grub_strtok() and grub_strtok_r() to help parse strings 
> > into
> > tokens separated by characters in the 'delim' parameter. These functions are
> > present in gnulib but calling them directly from the gnulib code is quite
> > challenging since the call "#include <string.h>" would include the header 
> > file
> > grub-core/lib/posix_wrap/string.h instead of grub-core/lib/gnulib/string.h,
> > where strtok() and strtok_r() are declared. Since this overlap is quite
> > problematic, the simpler solution was to implement the code in the GRUB 
> > based
> > on gnulib's implementation. For more information on these functions, visit 
> > the
> > Linux Programmer's Manual("man strtok").
> >
> > Signed-off-by: Alec Brown <alec.r.br...@oracle.com>
> > ---
> >  grub-core/kern/misc.c | 62 +++++++++++++++++++++++++++++++++++++++++++
> >  include/grub/misc.h   |  3 +++
> >  2 files changed, 65 insertions(+)
> >
> > diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
> > index 2b7922393..258f91893 100644
> > --- a/grub-core/kern/misc.c
> > +++ b/grub-core/kern/misc.c
> > @@ -401,6 +401,68 @@ grub_strword (const char *haystack, const char *needle)
> >    return 0;
> >  }
> >
> > +char *
> > +grub_strtok_r (char *s, const char *delim, char **save_ptr)
> > +{
> > +  char *token;
> > +  const char *c;
> > +  bool is_delim;
> > +
> > +  if (s == NULL)
> > +    s = *save_ptr;
> > +
> > +  /* Scan leading delimiters. */
> > +  while (*s != '\0')
> > +    {
> > +      is_delim = false;
> > +      for (c = delim; *c != '\0'; c++)
> > +       {
> > +         if (*s == *c)
> > +           {
> > +             is_delim = true;
> > +             break;
> > +           }
> > +       }
> > +      if (is_delim == true)
> > +       s++;
> > +      else
> > +       break;
>
> Would it be sensible to replace the above loop with a
>
>   for ( ; *s != '\0'; ++s )
>     if ( grub_strchr(delim, *s) == NULL )
>         break;

Maybe it is sensible but we want bug to bug Gnulib compatible code here.
However, if you convince Gnulib maintainers to get that change I am more
than happy to get it to the GRUB too.

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to