chiark / gitweb /
tree-wide: whenever we include libgen.h, immediately undefine basename()
authorLennart Poettering <lennart@poettering.net>
Wed, 11 Feb 2015 17:50:38 +0000 (18:50 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Feb 2015 17:50:38 +0000 (18:50 +0100)
Also, document in adjacent comments and in CODING_STYLE why we do that.

CODING_STYLE
src/libsystemd/sd-bus/bus-kernel.c
src/machine/machinectl.c
src/shared/util.c

index 1d1d97049257332671706b1810169feabc1000c4..557401348789e0322ea45a1d699d56430da329eb 100644 (file)
   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!
index 1714188ffdf51d2ffca61deefee8111da2e1f597..b884074d95cd85e14d742684402e1cfe9263af4b 100644 (file)
 
 #include <fcntl.h>
 #include <malloc.h>
-#include <libgen.h>
 #include <sys/mman.h>
 #include <sys/prctl.h>
 
+/* 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 <libgen.h>
+#undef basename
+
 #include "util.h"
 #include "strv.h"
 #include "memfd-util.h"
index 16ce2f424b9fd8158250ac00504183b07b36ec42..9f8c68b184f5b79ef4d589a19777d7a1dca49dff 100644 (file)
 #include <arpa/inet.h>
 #include <net/if.h>
 #include <sys/mount.h>
+
+/* 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 <libgen.h>
 #undef basename
+
 #include "sd-bus.h"
 #include "log.h"
 #include "util.h"
index c53f9cdb6acb1c3cd055bd7698d18b03a97c7082..f5fcebebe7a1c26028593ebd93446e5eefb2d4ad 100644 (file)
 #include <locale.h>
 #include <sys/personality.h>
 #include <sys/xattr.h>
-#include <libgen.h>
 #include <sys/statvfs.h>
 #include <sys/file.h>
 #include <linux/fs.h>
+
+/* 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 <libgen.h>
 #undef basename
 
 #ifdef HAVE_SYS_AUXV_H