code: def path2fsn(path):
      
  
      # allow mbcs str on py2+win and bytes on py3
      if PY2:
          if is_win:
              if isinstance(path, bytes):
                  path = path.decode(_encoding)
          else:
              if isinstance(path, text_type):
                  path = path.encode(_encoding)
          if "\x00" in path:
              raise ValueError("embedded null")
      else:
          path = getattr(os, "fspath", lambda x: x)(path)
          if isinstance(path, bytes):
              if b"\x00" in path:
                  raise ValueError("embedded null")
              path = path.decode(_encoding, "surrogateescape")
          elif is_unix and isinstance(path, str):
              # make sure we can encode it and this is not just some random
              # unicode string
              data = path.encode(_encoding, "surrogateescape")
              if b"\x00" in data:
                  raise ValueError("embedded null")
              path = fsn2norm(path)
          else:
              if u"\x00" in path:
                  raise ValueError("embedded null")
              path = fsn2norm(path)
  
      if not isinstance(path, fsnative_type):
          raise TypeError("path needs to be %s", fsnative_type.__name__)
  
      return path
docs: Args:
          path (pathlike): The path to convert
      Returns:
          `fsnative`
      Raises:
          TypeError: In case the type can't be converted to a `fsnative`
          ValueError: In case conversion fails
  
      Returns a `fsnative` path for a `pathlike`.