Copied function from other BSD to prevent undefined name error