Detect end-of-file not using ungetc

It seems that VMS have problems with this function.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>