Fix build on darwin (and various other improvements)

It wasn't defining `max_filepath` due to the fact that it was neither win32 nor linux.

EDIT: I am a fool – was missing a lot more than this. Updated.

EDIT 2: I have added some other fixes/improvements. Happy to submit in separate PRs if requested.