minor code cleanups

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