Compile fixes for building with musl libc

The musl libc library is an embedded libc that is gaining popularity. The following cleanups fix compile errors where musl does things differently from glibc, but within the specs. They should be safer on all platforms.