Repository: xbmc/xbmc
File: xbmc/platform/posix/filesystem/SMBDirectory.cpp (C++)

Code before:
    else
    {
      std::shared_ptr<CFileItem> item(new CFileItem(name));
      item->SetPath(strRoot + fi->name);
      item->SetFolder(false);
      item->SetSize(size);
      item->SetDateTime(localTime);
      if (hidden)
        item->SetProperty("file:hidden", true);
      items.Add(item);
    }
  }

  // No results from smbc_readdirplus2() suggests server or share browsing.
  // Use smbclient's legacy API for this.
  if (!atLeastOneEntry)
  {
    smbc_lseekdir(fd, 0);

    struct smbc_dirent* dirent;
    while ((dirent = smbc_readdir(fd)))
    {
      if (dirent->smbc_type != SMBC_FILE_SHARE && dirent->smbc_type != SMBC_SERVER)
        continue;

      std::shared_ptr<CFileItem> item(new CFileItem(dirent->name));
      std::string path(strRoot);
      // needed for network / workgroup browsing
      // skip if root if we are given a server
      if (dirent->smbc_type == SMBC_SERVER)
      {
        /* create url with same options, user, pass.. but no filename or host*/
        CURL rooturl(strRoot);
        rooturl.SetFileName("");
        rooturl.SetHostName("");
        path = smb.URLEncode(rooturl);
      }
      path = URIUtils::AddFileToFolder(path, dirent->name);
      URIUtils::AddSlashAtEnd(path);
      item->SetPath(path);
      item->SetFolder(true);
      items.Add(item);
    }
  }

  smbc_closedir(fd);
  lock.unlock();

  auto end = std::chrono::steady_clock::now();
  std::cout << "Done reading directory, duration: "
            << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()

Review comment (suggestion):
```suggestion
      const auto item = std::make_shared<CFileItem>(dirent->name);
```

Code after:
  // No results from smbc_readdirplus2() suggests server or share browsing.
  // Use smbclient's legacy API for this.
  if (!atLeastOneEntry)
  {
    if (smbc_lseekdir(fd, 0) < 0)
    {
      CLog::LogF(LOGERROR, "Unable to seek directory : '{}'\nunix_err:'{:x}' error: '{}'",
                 CURL::GetRedacted(strAuth), errno, strerror(errno));
      return false;
    }

    struct smbc_dirent* dirent;
    while ((dirent = smbc_readdir(fd)))
    {
      if (dirent->smbc_type != SMBC_FILE_SHARE && dirent->smbc_type != SMBC_SERVER)
        continue;

      const auto item = std::make_shared<CFileItem>(dirent->name);
      std::string path(strRoot);
      // needed for network / workgroup browsing
      // skip if root if we are given a server
      if (dirent->smbc_type == SMBC_SERVER)
      {
        /* create url with same options, user, pass.. but no filename or host*/
        CURL rooturl(strRoot);
        rooturl.SetFileName("");
        rooturl.SetHostName("");
        path = smb.URLEncode(rooturl);
      }
      path = URIUtils::AddFileToFolder(path, dirent->name);
      URIUtils::AddSlashAtEnd(path);
      item->SetPath(path);
      item->SetFolder(true);
      items.Add(item);
    }
  }

  if (smbc_closedir(fd) < 0)
  {
    CLog::LogF(LOGERROR, "Unable to close directory : '{}'\nunix_err:'{:x}' error: '{}'",
               CURL::GetRedacted(strAuth), errno, strerror(errno));
    return true; // we already got our listing
  }

  return true;
}

int CSMBDirectory::Open(const CURL &url)
{
  smb.Init();
  std::string strAuth;