Replaced -1 error code to posix error code