All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Herbert <marc.herbert@linux.intel.com>
To: Alison Schofield <alison.schofield@intel.com>
Cc: nvdimm@lists.linux.dev
Subject: Re: [ndctl PATCH v2] daxctl: replace basename() usage with new path_basename()
Date: Fri, 16 Jan 2026 11:41:35 -0800	[thread overview]
Message-ID: <m2qzrpe45s.fsf@linux.intel.com> (raw)
In-Reply-To: <20260116043056.542346-1-alison.schofield@intel.com> (Alison Schofield's message of "Thu, 15 Jan 2026 20:30:53 -0800")


Hearing the punishment for inputs with a trailing slash is not too
harsh:

Reviewed-by: Marc Herbert <marc.herbert@linux.intel.com>


Alison Schofield <alison.schofield@intel.com> writes:

> A user reports that ndctl fails to compile on MUSL systems:
>
> daxctl/device.c: In function 'parse_device_options':
> daxctl/device.c:377:26: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
>   377 |                 device = basename(argv[0]);
>       |                          ^~~~~~~~
>
> There are two versions of basename() with different behaviors:
> 	GNU basename() from <string.h>: doesn't modify its argument
> 	POSIX basename() from <libgen.h>: may modify its argument
>
> glibc provides both versions, while MUSL libc only provides the POSIX
> version. Previous code relied on the GNU extension without a header
> or used the POSIX version inconsistently.
>
> Introduce a new helper path_basename() that returns the portion of a
> path after the last '/', the full string if no '/' is present, and a
> trailing '/' returns an empty string. This avoids libc-specific
> basename() behavior and is safe for argv style and arbitrary paths.
>
> Closes: https://github.com/pmem/ndctl/issues/283
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> ---
>
> Changes in v2: 
> - Replace open coded strrchr() logic with new helper (Marc, Dan)
> - Comment that new helper (Marc)
> - Update commit msg
>
>
>  daxctl/device.c        |  4 ++--
>  daxctl/lib/libdaxctl.c |  7 ++++---
>  util/util.h            | 15 +++++++++++++++
>  3 files changed, 21 insertions(+), 5 deletions(-)
>

      reply	other threads:[~2026-01-16 19:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16  4:30 [ndctl PATCH v2] daxctl: replace basename() usage with new path_basename() Alison Schofield
2026-01-16 19:41 ` Marc Herbert [this message]

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=m2qzrpe45s.fsf@linux.intel.com \
    --to=marc.herbert@linux.intel.com \
    --cc=alison.schofield@intel.com \
    --cc=nvdimm@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.