Add #include <errno.h> where necessary for the following commits.
#include <errno.h>
It's very likely this does not account for all the places where the include should be, but this is enough for the code to build.