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

Reviewed-by: Marc Herbert <[email protected]>


Alison Schofield <[email protected]> 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 <[email protected]>
> ---
>
> 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 via email to