diff --git a/src/tool_metalink.c b/src/tool_metalink.c
index 1dfe32783d7175b6df6ded60bff407a8a682cdcb..8909397b7830e1d35ec29ff68980ceb205ac0f71 100644
--- a/src/tool_metalink.c
+++ b/src/tool_metalink.c
@@ -23,6 +23,16 @@
 
 #ifdef USE_METALINK
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
+#include <sys/stat.h>
+
+#ifdef HAVE_FCNTL_H
+#  include <fcntl.h>
+#endif
+
 #include <metalink/metalink_parser.h>
 
 #ifdef USE_SSLEAY