Moved some stuff around
Should check result of strdup for NULL
Fixed warning: control reaches end of non-void function
Fixed warning: implicit declaration of function ‘ftruncate’
Fixed invalid reads/writes
Removed comment