Improved POSIX compliance.

Should now be completely POSIX compliant (needs critique and comments).

Signed-off-by: necrophcodr <tcg.thegamer@gmail.com>