Add unistd header for id types

Required for FreeBSD.
Add explicit cast to malloc return

Required to build on FreeBSD