it's nicer for the function that doesn't use errno to be independent, and have the other one call it. saves some time and avoids clobbering errno.
it must return errno, not -1, and should reject invalud values for how.