Re: [PATCH v2 08/17] linux: string: Port kbasename()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 11, 2018 at 1:31 AM Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> wrote:
>
> On Tue, Oct 09, 2018 at 10:37:56AM -0700, Andrey Smirnov wrote:
> > Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
> > ---
> >  include/linux/string.h | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/include/linux/string.h b/include/linux/string.h
> > index 3418b4fbe..c9823dab8 100644
> > --- a/include/linux/string.h
> > +++ b/include/linux/string.h
> > @@ -111,6 +111,18 @@ extern char *strim(char *);
> >
> >  void *memchr_inv(const void *start, int c, size_t bytes);
> >
> > +/**
> > + * kbasename - return the last part of a pathname.
> > + *
> > + * @path: path to extract the filename from.
> > + */
> > +static inline const char *kbasename(const char *path)
> > +{
> > +     const char *tail = strrchr(path, '/');
> > +     return tail ? tail + 1 : path;
> > +}
>
> We already have basename() and posix_basename().

Sorry, forgot to check if something like that existed.

> How does this one differ or could this be an alias for one of them?
>

AFAICT, kbasename() implements the same algorithm as basename() we
already have, except it relies on strrchr() to do all of the work
instead of explicitly coding reverse string traversal. Aliasing would
be difficult since kbasename() operates on and returns "const char *"
and basename doesn't, but I'll change the patch to convert basename()
to use kbasename() internally in v3.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux