Drop warnings

Fix 5 warnings.

The return value of those functions (chdir, read, write) wasn't checked. I added a warning/error message when the functions fails.