Added some guards in file utils.
Fixed a bug in emscripten file utils.