More OS X support.

Fixed a problem with double exits.
Fixed system calls for exiting the program on OS X.