code: def _get_userdir(user=None):
      
  
      if user is not None and not isinstance(user, fsnative):
          raise TypeError
  
      if is_win:
          if "HOME" in environ:
              path = environ["HOME"]
          elif "USERPROFILE" in environ:
              path = environ["USERPROFILE"]
          elif "HOMEPATH" in environ and "HOMEDRIVE" in environ:
              path = os.path.join(environ["HOMEDRIVE"], environ["HOMEPATH"])
          else:
              return
  
          if user is None:
              return path
          else:
              return os.path.join(os.path.dirname(path), user)
      else:
          import pwd
  
          if user is None:
              if "HOME" in environ:
                  return environ["HOME"]
              else:
                  try:
                      return path2fsn(pwd.getpwuid(os.getuid()).pw_dir)
                  except KeyError:
                      return
          else:
              try:
                  return path2fsn(pwd.getpwnam(user).pw_dir)
              except KeyError:
                  return
docs: Returns the user dir or None