check for directory in stat too and set st_mode appropriately