Explicitly check for -1 return values from read and write instead of using < 0 checks.