Fixed some undefined behavior when creating files with the same name.