Re: [PATCH 32/43] tools lib: Adopt strim() from the kernel

From: Arnaldo Carvalho de Melo
Date: Tue Jul 02 2019 - 12:00:49 EST


Em Mon, Jul 01, 2019 at 11:33:20PM -0400, Andrà Goddard Rosa escreveu:
> On Mon, Jul 1, 2019 at 22:28 Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> wrote:
>
> > From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> >
> > Since we're working on moving stuff out of tools/perf/util/ to
> > tools/lib/, take the opportunity to adopt routines from the kernel that
> > are equivalent, so that tools/ code look more like the kernel.

<SNIP>

> > +char *strim(char *s)
> > +{
> > + size_t size;
> > + char *end;
> > +
> > + size = strlen(s);
> > + if (!size)
> > + return s;
> > +
> > + end = s + size - 1;
> > + while (end >= s && isspace(*end))
> > + end--;
> > + *(end + 1) = '\0';
> > +
> > + return skip_spaces(s);
> > +}
> > --
> > 2.20.1
>
>
> Small nit: could call skip_spaces() firstly and save its pointer to return
> later and then remove the trailing spaces. Thatâll make strlen() iterate
> over a smaller string.

Hey, this is just a copy of what is in the kernel sources, so as soon
as this gets improved there we'll grab a copy again can you do that for
the kernel first? :-)

- Arnaldo