minor code cleanups

These attempt to improve robustness and portability by correcting build errors encountered when using musl libc.