Fix many compilation warnings

This fixes many compilation warnings.  These were generated with CFLAGS="-Wall -Wextra -Werror -Wno-sign-compare -Wno-unused -Wunused-result -Wno-strict-aliasing".  Strict aliasing was skipped because it's simply a fact of life, and trying to fix all of them is a pain in the ass.  Also skipped all warnings about unused items, except unused return values from functions with warn_unused_result.  Signed to unsigned comparison was skipped as fixing one of the occurrences would require a large break in the libratbox ABI, which I didn't want to deal with.

These fixes have been compile-tested, but should get a good sanity check with another set of eyes, as my C is a bit rusty as of late.