diff --git a/glnx-fdio.h b/glnx-fdio.h
index 8af54ff2366a1a8bb14c699077e31513cb93ac8d..c0a7cc1de847e0bc9ca2f1c3306eb413055701d7 100644
--- a/glnx-fdio.h
+++ b/glnx-fdio.h
@@ -29,6 +29,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <sys/xattr.h>
+// For dirname(), and previously basename()
+#include <libgen.h>
 
 #include <glnx-macros.h>
 #include <glnx-errors.h>
@@ -41,9 +43,7 @@ G_BEGIN_DECLS
 static inline
 const char *glnx_basename (const char *path)
 {
-  gchar *base;
-
-  base = strrchr (path, G_DIR_SEPARATOR);
+  gchar *base = strrchr (path, G_DIR_SEPARATOR);
 
   if (base)
     return base + 1;