diff --git a/glnx-fdio.h b/glnx-fdio.h
index dc93b6877af251fb164cb91c36d462a827a988ce..8af54ff2366a1a8bb14c699077e31513cb93ac8d 100644
--- a/glnx-fdio.h
+++ b/glnx-fdio.h
@@ -29,12 +29,6 @@
 #include <string.h>
 #include <stdio.h>
 #include <sys/xattr.h>
-/* From systemd/src/shared/util.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 <glnx-macros.h>
 #include <glnx-errors.h>
@@ -47,7 +41,14 @@ G_BEGIN_DECLS
 static inline
 const char *glnx_basename (const char *path)
 {
-  return (basename) (path);
+  gchar *base;
+
+  base = strrchr (path, G_DIR_SEPARATOR);
+
+  if (base)
+    return base + 1;
+
+  return path;
 }
 
 /* Utilities for standard FILE* */