dirname() is really terrible, because it modifies the argument so that it need another ugly copy of the original string. So no dirname(), please.

Is there any function like that but which is able to use safely?