util: add macro for iterating through all prefixes of a path

Syntactic sugar in a macro PATH_FOREACH_PREFIX.