As I can see ```p``` should be incremented only ```if (vim_ispathsep(*p))```. For example ```dir_name``` can be ```foo/bar``` or ```foo/bar/``` and file_name is ```foo/bar/baz```. In these two cases result must be ```baz```. But in the current realisation in the second case result will be ```az```.
I think it would be great to add such unit test.