This doesn't feel like safe code to me...

if strrchr returns NULL, the behaviour will be pretty much undefined.