Fix handling of strtol

errno needs to be checked after calling it. This makes the error messages
less verbose but I think that mg can live with that.