path: Refactor set_extension and contains_nul

Also some minor cleanup in Path related to this.