unix, windows: map ERANGE errno

This is a backport of 2f58bb6 from the master branch