<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem mit readdir_r]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>bisher hatte ich so eine Funktion um einen Ordner und alle Unterordner zu lesen:</p>
<pre><code class="language-cpp">Filelist::Filelist(const std::string path)
{
  DIR *dirHandle;
  struct dirent *dirEntry;

  // Open a folder
  dirHandle = opendir(path.c_str());

  do
  {
    dirEntry = readdir(dirHandle);
    if (dirEntry)
    {
      _filenameList.push_back(dirEntry-&gt;d_name);
    }
  } while (dirEntry);
  closedir(dirHandle);
}
</code></pre>
<p>Und das hat auch super funktioniert. Problem: Jetzt dürfen wir aber readdir nicht verwenden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Und nun bin ich dabei, diesselbe Funktion mit readdir_r zu schreiben, doch leider will es noch nicht ganz funktionieren. Könnt ihr mir da mal helfen ?</p>
<p>Das hab ich schon:</p>
<pre><code class="language-cpp">Filelist::Filelist(const std::string path)
{
  DIR *dirHandle;
  struct dirent dirEntry;
  struct dirent *dirResult;

  // Open a folder
  dirHandle = opendir(path.c_str());

  int x;
  do
  {
  //    dirEntry = readdir_r(dirHandle);
    x = readdir_r(dirHandle, &amp;dirEntry, &amp;dirResult);
    if (x == EOK)
    {
      _filenameList.push_back(dirEntry.d_name);
    }
  } while (x == EOK);
  closedir(dirHandle);
}
</code></pre>
<p>Dauernd gibt es ein Problem. Aktuell sieht meine Fehlerquote so aus, aber ich weiß ja noch nicht einmal, ob meine neue Funktion dasselbe macht wie meine alte ...</p>
<pre><code>Filelist.cpp: In constructor ‘Filelist::Filelist(std::string)’:
Filelist.cpp:30:14: error: ‘EOK’ was not declared in this scope
Filelist.cpp:34:12: error: could not convert ‘dirEntry’ to ‘bool’
make: *** [Filelist.o] Error 1
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/292593/problem-mit-readdir_r</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 20:03:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/292593.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Sep 2011 14:19:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit readdir_r on Tue, 13 Sep 2011 14:19:38 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>bisher hatte ich so eine Funktion um einen Ordner und alle Unterordner zu lesen:</p>
<pre><code class="language-cpp">Filelist::Filelist(const std::string path)
{
  DIR *dirHandle;
  struct dirent *dirEntry;

  // Open a folder
  dirHandle = opendir(path.c_str());

  do
  {
    dirEntry = readdir(dirHandle);
    if (dirEntry)
    {
      _filenameList.push_back(dirEntry-&gt;d_name);
    }
  } while (dirEntry);
  closedir(dirHandle);
}
</code></pre>
<p>Und das hat auch super funktioniert. Problem: Jetzt dürfen wir aber readdir nicht verwenden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Und nun bin ich dabei, diesselbe Funktion mit readdir_r zu schreiben, doch leider will es noch nicht ganz funktionieren. Könnt ihr mir da mal helfen ?</p>
<p>Das hab ich schon:</p>
<pre><code class="language-cpp">Filelist::Filelist(const std::string path)
{
  DIR *dirHandle;
  struct dirent dirEntry;
  struct dirent *dirResult;

  // Open a folder
  dirHandle = opendir(path.c_str());

  int x;
  do
  {
  //    dirEntry = readdir_r(dirHandle);
    x = readdir_r(dirHandle, &amp;dirEntry, &amp;dirResult);
    if (x == EOK)
    {
      _filenameList.push_back(dirEntry.d_name);
    }
  } while (x == EOK);
  closedir(dirHandle);
}
</code></pre>
<p>Dauernd gibt es ein Problem. Aktuell sieht meine Fehlerquote so aus, aber ich weiß ja noch nicht einmal, ob meine neue Funktion dasselbe macht wie meine alte ...</p>
<pre><code>Filelist.cpp: In constructor ‘Filelist::Filelist(std::string)’:
Filelist.cpp:30:14: error: ‘EOK’ was not declared in this scope
Filelist.cpp:34:12: error: could not convert ‘dirEntry’ to ‘bool’
make: *** [Filelist.o] Error 1
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2118760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2118760</guid><dc:creator><![CDATA[bluepeople12]]></dc:creator><pubDate>Tue, 13 Sep 2011 14:19:38 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit readdir_r on Tue, 13 Sep 2011 14:32:19 GMT]]></title><description><![CDATA[<p>Du verwendest einen Bezeichner, den es nicht gibt. Und da meckert der Compiler zu Recht. Vermutlich meintest du EOF (end of file) statt EOK.</p>
<p>Und zu deiner Funktion kann leider niemand was sagen, wenn du sie nicht postest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2118767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2118767</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Tue, 13 Sep 2011 14:32:19 GMT</pubDate></item></channel></rss>