def splitext(p):
    """Split a path into root and extension.
    The extension is everything starting at the first dot in the last
    pathname component; the root is everything before that.
    It is always true that root + ext == p."""

    root, ext = '', ''
    for c in p:
        if c in '/\\':
            root, ext = root + ext + c, ''
        elif c == '.' or ext:
            ext = ext + c
        else:
            root = root + c
    return root, ext