Here you are throwing if stat != ES_ERROR - the original code just returned ES_NORMAL... Thus, this should only throw is stat != ES_ERROR.