[Rebased] Fix compile errors under mingw-w64.

Rebased onto 9b6f871, because why not? But do try not to lose it this time.

Also, I may fix chkjson while I'm at it, but no guarantees -- not sure how much time I have right now.