Move check for __GNU__ into .c file instead of header
Re-implement semaphores in the spirit of glibc
Miscellaneous cleanups