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] daxctl: Replace basename() usage with strrchr()
Date: Thu, 15 Jan 2026 15:54:54 -0800	[thread overview]
Message-ID: <m2a4yee8j5.fsf@C02X38VBJHD2mac.jf.intel.com> (raw)
In-Reply-To: <20260115221630.528423-1-alison.schofield@intel.com> (Alison Schofield's message of "Thu, 15 Jan 2026 14:16:28 -0800")

Hi Alison,

Alison Schofield <alison.schofield@intel.com> writes:
>  	argc = parse_options(argc, argv, options, u, 0);
> -	if (argc > 0)
> -		device = basename(argv[0]);
> +	if (argc > 0) {
> +		device = strrchr(argv[0], '/');
> +		device = device ? device + 1 : argv[0];
> +	}
>  


1. I would add a one-line comment in both places, something like "This
is like basename but without the bugs and portability issues" because:

  1.a) It's much faster to read such a comment than understanding the code.
  1.b) Not everyone knows how much of GNU/POSIX disaster is "basename".
       You summarized it well in the commit message but it's unlikely
       anyone will fetch the commit message from git without such a comment.

  To avoid duplicating the comment, a small "my_basename()" inline
  function would not hurt while at it.


2. I believe this (unlike basename) returns an empty string when the
   argument has a trailing slash. Now, an argument with a trailing slash
   would probably be garbage and I'm OK with the "Garbage IN, garbage
   OUT" principle. BUT I also believe in the "Proportionate Response"
   principle, which means a small amount of garbage IN should IMHO not
   be punished by some utterly baffling error message or (much worse) a
   crash. Did you/could you test what happens with a trailing slash? If
   the resulting failure makes some kind of sense then don't change
   anything.

Note even when rare in interactive use, "Garbage IN" becomes more
frequent in automation. Then good luck making sense of a cryptic error
when you can't even reproduce the elaborate test configuration and test
bugs that trigger it.

  reply	other threads:[~2026-01-15 23:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-15 22:16 [ndctl PATCH] daxctl: Replace basename() usage with strrchr() Alison Schofield
2026-01-15 23:54 ` Marc Herbert [this message]
2026-01-16  3:17   ` Alison Schofield
2026-01-16  4:29     ` Alison Schofield
2026-01-16  2:33 ` dan.j.williams
2026-01-16  3:19   ` Alison Schofield

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=m2a4yee8j5.fsf@C02X38VBJHD2mac.jf.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.