io: implement split

Feedback is appreciated. I'd like to be sure that this code doesn't do lots of allocations.

I plan to use this function in dirname and basename.