applied patch with jira issue 1510. Added !defined __APPLE__ to avoid build error on macos when checking for unistd.h