From eef46c372f64f40dd75415b2c504c73138719c8d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 11 Feb 2015 18:50:38 +0100 Subject: [PATCH] tree-wide: whenever we include libgen.h, immediately undefine basename() Also, document in adjacent comments and in CODING_STYLE why we do that. --- CODING_STYLE | 6 ++++++ src/libsystemd/sd-bus/bus-kernel.c | 7 ++++++- src/machine/machinectl.c | 5 +++++ src/shared/util.c | 6 +++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CODING_STYLE b/CODING_STYLE index 1d1d97049..557401348 100644 --- a/CODING_STYLE +++ b/CODING_STYLE @@ -202,3 +202,9 @@ b) socket() and socketpair() must get SOCK_CLOEXEC passed c) recvmsg() must get MSG_CMSG_CLOEXEC set d) F_DUPFD_CLOEXEC should be used instead of F_DUPFD, and so on + +- We never use the XDG version of basename(). glibc defines it in + libgen.h. The only reason to include that file is because dirname() + is needed. Everytime you need that please immediately undefine + basename(), and add a comment about it, so that no code ever ends up + using the XDG version! diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 1714188ff..b884074d9 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -25,10 +25,15 @@ #include #include -#include #include #include +/* When we include libgen.h because we need dirname() we immediately + * undefine basename() since libgen.h defines it as a macro to the XDG + * version which is really broken. */ +#include +#undef basename + #include "util.h" #include "strv.h" #include "memfd-util.h" diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 16ce2f424..9f8c68b18 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -31,8 +31,13 @@ #include #include #include + +/* When we include libgen.h because we need dirname() we immediately + * undefine basename() since libgen.h defines it as a macro to the XDG + * version which is really broken. */ #include #undef basename + #include "sd-bus.h" #include "log.h" #include "util.h" diff --git a/src/shared/util.c b/src/shared/util.c index c53f9cdb6..f5fcebebe 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -60,10 +60,14 @@ #include #include #include -#include #include #include #include + +/* When we include libgen.h because we need dirname() we immediately + * undefine basename() since libgen.h defines it as a macro to the XDG + * version which is really broken. */ +#include #undef basename #ifdef HAVE_SYS_AUXV_H -- 2.30.2