Re: [PATCH] kmod/depmod: explicitly include the header for basename()

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

 



On Tue, Apr 09, 2024 at 04:16:48PM +0000, Laurent Bercot wrote:
GNU should have named its own (admittedly better) version

agreed

differently; it's just less error-prone to have different symbols for
different things, and I don't think it's a good idea to tie a project to
this particular GNU bit of carelessness.

agreed, but that's not really up to each project. POSIX/libc should have
provided the better alternative, because the current one from libgen.h
makes no sense for what the function does. I understand why an
implementation of dirname() could modify the buffer passed in, but not
basename().

If musl provided a better one with a different name, I'd be happy to
alias basename to it.

If I cared enough, I'd request a "sane_basename() /
basename_dont_be_evil()" to be included in POSIX. I don't care enough,
but as I said it's surprising libc developers don't care neither and
instead we keep patching all code on earth to duplicate what should
really be the normal behavior of such a function from libc.

My problem with s/basename/gnu_basename/ is that eventually we will
forget and just use basename in future. And break musl again. And it may
even be just a silent error, modifying a buffer that shouldn't really be
modified.

given that so far we never needed dirname() from libgen.h, we could just
ban it. Something like:

diff --git a/Makefile.am b/Makefile.am
index e2e2411..6ca787a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,7 @@ export GCC_COLORS
AM_CPPFLAGS = \
        -include $(top_builddir)/config.h \
+       -I$(top_srcdir)/shared/missing \
        -I$(top_srcdir) \
        -DSYSCONFDIR=\""$(sysconfdir)"\" \
        -DDISTCONFDIR=\""$(distconfdir)"\" \
@@ -47,6 +48,7 @@ noinst_LTLIBRARIES = shared/libshared.la
 shared_libshared_la_SOURCES = \
        shared/macro.h \
        shared/missing.h \
+       shared/missing/libgen.h \
        shared/array.c \
        shared/array.h \
        shared/hash.c \
diff --git a/shared/missing/libgen.h b/shared/missing/libgen.h
new file mode 100644
index 0000000..3c78586
--- /dev/null
+++ b/shared/missing/libgen.h
@@ -0,0 +1 @@
+#error "libgen.h can't be included in this project. Did you mean to use string.h?"

at least on my system it seems libgen.h is never implicitely included.

Lucas De Marchi



There's a pending patch I need to review:
https://github.com/kmod-project/kmod/pull/32

does that fix it for you?

Absolutely, this patch is way better than mine and I should have thought
of looking for something similar before submitting mine. Please merge
Khem's patch. :)

--
Laurent





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux