Fix dirname() and its tests