misc ungetc fixes
Merge pull request #1370 from inolen/ungetc_fixes

misc ungetc fixes