linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Bowler <nbowler@elliptictech.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, Joe Perches <joe@perches.com>,
	YAMANE Toshiaki <yamanetoshi@gmail.com>
Subject: Re: [PATCH 1/7] string: introduce helper to get base file name from given path
Date: Wed, 3 Oct 2012 14:39:21 -0400	[thread overview]
Message-ID: <20121003183921.GA3098@elliptictech.com> (raw)
In-Reply-To: <20121002181250.GA14042@kroah.com>

On 2012-10-02 11:12 -0700, Greg KH wrote:
> On Tue, Oct 02, 2012 at 08:52:05PM +0300, Andy Shevchenko wrote:
> > On Tue, Oct 2, 2012 at 8:34 PM, Greg KH <gregkh@linuxfoundation.org> wrote:
> > > On Tue, Oct 02, 2012 at 06:00:54PM +0300, Andy Shevchenko wrote:
[...]
> > >> +/**
> > >> + * 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;
> > >
> > > What happens if '/' is the last thing in the string?  You will then
> > > point to an empty string, which I don't think all callers of this
> > > function is assuming going to work properly (hint, the USB caller will
> > > not...)
> > Thanks for pointing to that. I think it's a usb specific case, so, I
> > assume your comment related to that patch.
> 
> Well, if you want your kbasename() function to work like the basename(3)
> function, you need to properly handle a trailing '/' character.

Specifically, POSIX basename trims trailing '/' characters, so

  char foo[] = "a/string/with/trailing/slashes///";
  basename(foo);

results in a string that compares equal to "slashes".  This implies that
it must either modify the provided string or copy it somewhere else
(POSIX admits either behaviour).

On the other hand, GNU basename does not trim trailing '/' characters
and returns the empty string in this case.  It's truly unfortunate that
glibc contains two different functions called basename, but regardless,
the behaviour of the function in this proposal is certainly not
unprecedented.

Cheers,
-- 
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)


  reply	other threads:[~2012-10-03 18:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-02 15:00 [PATCH 1/7] string: introduce helper to get base file name from given path Andy Shevchenko
2012-10-02 15:00 ` [PATCH 2/7] lib: dynamic_debug: reuse kbasename() Andy Shevchenko
2012-10-02 15:00 ` [PATCH 3/7] staging: rts_pstor: " Andy Shevchenko
2012-10-03  0:30   ` Ryan Mallon
2012-10-03  0:33     ` Ryan Mallon
2012-10-02 15:00 ` [PATCH 4/7] mm: reuse kbasename() functionality Andy Shevchenko
2012-10-02 15:00 ` [PATCH 5/7] procfs: " Andy Shevchenko
2012-10-02 15:00 ` [PATCH 6/7] usb: core: reuse kbasename() Andy Shevchenko
2012-10-03  8:27   ` Andy Shevchenko
2012-10-03 15:08     ` Greg Kroah-Hartman
2012-10-17  7:42       ` Andy Shevchenko
2012-10-02 15:01 ` [PATCH 7/7] trace: reuse kbasename() functionality Andy Shevchenko
2012-10-02 17:34 ` [PATCH 1/7] string: introduce helper to get base file name from given path Greg KH
2012-10-02 17:52   ` Andy Shevchenko
2012-10-02 18:12     ` Greg KH
2012-10-03 18:39       ` Nick Bowler [this message]
2012-10-04  8:19         ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121003183921.GA3098@elliptictech.com \
    --to=nbowler@elliptictech.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yamanetoshi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).