make getfid() more robust and fixed gcc warning