Fix most warnings.

* A few missing function declarations, fix by adding includes, and by
  fixing one broken prototype (the shunget prototype accidentally was
  called shungetc. shgetc, otoh, is correct as is.)
* Add a few explicit casts for incompatible signedness / const warnings

Change-Id: I118738c3fcda52addab2c3dada54f6fc9890ad44