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.