Add compat headers, move some things to them.

This is groundwork for landing musl includes which remove
some of the deprecated functions or very old BSDisms.
Merge pull request #1529 from waywardmonkeys/compat-headers

Compat headers