check scanf return values and errno

Signed-off-by: Sami Kerola <kerolasa@iki.fi>