move the ENOSYS check out to its own function
remove duplicate -1 check.
simplify, by breaking up if and inverting checks to reduce nesting