[libromdata] IFst::readdir(): Return const DirEnt* instead of DirEnt*.

This ensures the caller won't modify the DirEnt.

Note that this doesn't match POSIX readdir(), but we don't need to
strictly match it. (We're also not returning `struct dirent*`; we're
returning a custom one.)
This commit is contained in:
David Korth 2025-06-07 15:47:30 -04:00
parent b884747254
commit 5ed38edbec
12 changed files with 20 additions and 20 deletions

View File

@ -1550,10 +1550,11 @@ int GameCube::loadFieldData(void)
// - 21.29: IOS version. (21.29 == v5405) // - 21.29: IOS version. (21.29 == v5405)
IFst::Dir *const dirp = d->updatePartition->opendir("/_sys/"); IFst::Dir *const dirp = d->updatePartition->opendir("/_sys/");
if (dirp) { if (dirp) {
IFst::DirEnt *dirent; const IFst::DirEnt *dirent;
while ((dirent = d->updatePartition->readdir(dirp)) != nullptr) { while ((dirent = d->updatePartition->readdir(dirp)) != nullptr) {
if (!dirent->name || dirent->type != DT_REG) if (!dirent->name || dirent->type != DT_REG) {
continue; continue;
}
// Check for a retail System Menu. // Check for a retail System Menu.
if (dirent->name[0] == 'R') { if (dirent->name[0] == 'R') {

View File

@ -447,7 +447,7 @@ IFst::Dir *GcnFst::opendir(const char *path)
* @return IFst::DirEnt*, or nullptr if end of directory or on error. * @return IFst::DirEnt*, or nullptr if end of directory or on error.
* (End of directory does not set lastError; an error does.) * (End of directory does not set lastError; an error does.)
*/ */
IFst::DirEnt *GcnFst::readdir(IFst::Dir *dirp) const IFst::DirEnt *GcnFst::readdir(IFst::Dir *dirp)
{ {
assert(dirp != nullptr); assert(dirp != nullptr);
assert(dirp->parent == this); assert(dirp->parent == this);

View File

@ -68,7 +68,7 @@ public:
* @return DirEnt*, or nullptr if end of directory or on error. * @return DirEnt*, or nullptr if end of directory or on error.
* (TODO: Add lastError()?) * (TODO: Add lastError()?)
*/ */
DirEnt *readdir(Dir *dirp) final; const DirEnt *readdir(Dir *dirp) final;
/** /**
* Close an opened directory. * Close an opened directory.

View File

@ -2,7 +2,7 @@
* ROM Properties Page shell extension. (libromdata) * * ROM Properties Page shell extension. (libromdata) *
* GcnPartition.cpp: GameCube partition reader. * * GcnPartition.cpp: GameCube partition reader. *
* * * *
* Copyright (c) 2016-2024 by David Korth. * * Copyright (c) 2016-2025 by David Korth. *
* SPDX-License-Identifier: GPL-2.0-or-later * * SPDX-License-Identifier: GPL-2.0-or-later *
***************************************************************************/ ***************************************************************************/
@ -217,7 +217,7 @@ IFst::Dir *GcnPartition::opendir(const char *path)
* @return IFst::DirEnt*, or nullptr if end of directory or on error. * @return IFst::DirEnt*, or nullptr if end of directory or on error.
* (TODO: Add lastError()?) * (TODO: Add lastError()?)
*/ */
IFst::DirEnt *GcnPartition::readdir(IFst::Dir *dirp) const IFst::DirEnt *GcnPartition::readdir(IFst::Dir *dirp)
{ {
RP_D(GcnPartition); RP_D(GcnPartition);
if (!d->fst) { if (!d->fst) {

View File

@ -2,7 +2,7 @@
* ROM Properties Page shell extension. (libromdata) * * ROM Properties Page shell extension. (libromdata) *
* GcnPartition.hpp: GameCube partition reader. * * GcnPartition.hpp: GameCube partition reader. *
* * * *
* Copyright (c) 2016-2023 by David Korth. * * Copyright (c) 2016-2025 by David Korth. *
* SPDX-License-Identifier: GPL-2.0-or-later * * SPDX-License-Identifier: GPL-2.0-or-later *
***************************************************************************/ ***************************************************************************/
@ -107,7 +107,7 @@ public:
* @return IFst::DirEnt, or nullptr if end of directory or on error. * @return IFst::DirEnt, or nullptr if end of directory or on error.
* (TODO: Add lastError()?) * (TODO: Add lastError()?)
*/ */
LibRpBase::IFst::DirEnt *readdir(LibRpBase::IFst::Dir *dirp) final; const LibRpBase::IFst::DirEnt *readdir(LibRpBase::IFst::Dir *dirp) final;
/** /**
* Close an opened directory. * Close an opened directory.

View File

@ -492,7 +492,7 @@ IFst::Dir *WiiUFst::opendir(const char *path)
* @return IFst::DirEnt*, or nullptr if end of directory or on error. * @return IFst::DirEnt*, or nullptr if end of directory or on error.
* (End of directory does not set lastError; an error does.) * (End of directory does not set lastError; an error does.)
*/ */
IFst::DirEnt *WiiUFst::readdir(IFst::Dir *dirp) const IFst::DirEnt *WiiUFst::readdir(IFst::Dir *dirp)
{ {
RP_D(WiiUFst); RP_D(WiiUFst);
assert(dirp != nullptr); assert(dirp != nullptr);

View File

@ -67,7 +67,7 @@ public:
* @return DirEnt*, or nullptr if end of directory or on error. * @return DirEnt*, or nullptr if end of directory or on error.
* (TODO: Add lastError()?) * (TODO: Add lastError()?)
*/ */
DirEnt *readdir(Dir *dirp) final; const DirEnt *readdir(Dir *dirp) final;
/** /**
* Close an opened directory. * Close an opened directory.

View File

@ -71,7 +71,7 @@ static int fstPrint(IFst *fst, ostream &os, const string &path,
} }
// Read the directory entries. // Read the directory entries.
IFst::DirEnt *dirent = fst->readdir(dirp); const IFst::DirEnt *dirent = fst->readdir(dirp);
while (dirent != nullptr) { while (dirent != nullptr) {
if (!dirent->name || dirent->name[0] == 0) { if (!dirent->name || dirent->name[0] == 0) {
// Empty name... // Empty name...
@ -79,8 +79,7 @@ static int fstPrint(IFst *fst, ostream &os, const string &path,
} }
// Print the tree lines. // Print the tree lines.
for (int i = 0; i < level; i++) for (int i = 0; i < level; i++) {
{
if (tree_lines[i]) { if (tree_lines[i]) {
// Directory tree exists for this segment. // Directory tree exists for this segment.
os << "\xE2\x94\x82 "; os << "\xE2\x94\x82 ";

View File

@ -357,7 +357,7 @@ void GcnFstTest::checkNoDuplicateFilenames(const char *subdir)
ASSERT_TRUE(dirp != nullptr) << ASSERT_TRUE(dirp != nullptr) <<
"Failed to open directory '" << subdir << "'."; "Failed to open directory '" << subdir << "'.";
IFst::DirEnt *dirent = m_fst->readdir(dirp); const IFst::DirEnt *dirent = m_fst->readdir(dirp);
while (dirent != nullptr) { while (dirent != nullptr) {
// Make sure we haven't seen this filename in // Make sure we haven't seen this filename in
// the current subdirectory yet. // the current subdirectory yet.

View File

@ -2,7 +2,7 @@
* ROM Properties Page shell extension. (librpbase) * * ROM Properties Page shell extension. (librpbase) *
* IFst.hpp: File System Table interface. * * IFst.hpp: File System Table interface. *
* * * *
* Copyright (c) 2016-2024 by David Korth. * * Copyright (c) 2016-2025 by David Korth. *
* SPDX-License-Identifier: GPL-2.0-or-later * * SPDX-License-Identifier: GPL-2.0-or-later *
***************************************************************************/ ***************************************************************************/
@ -95,7 +95,7 @@ public:
* @return DirEnt*, or nullptr if end of directory or on error. * @return DirEnt*, or nullptr if end of directory or on error.
* (TODO: Add lastError()?) * (TODO: Add lastError()?)
*/ */
virtual DirEnt *readdir(Dir *dirp) = 0; virtual const DirEnt *readdir(Dir *dirp) = 0;
/** /**
* Close an opened directory. * Close an opened directory.

View File

@ -2,7 +2,7 @@
* ROM Properties Page shell extension. (librpbase) * * ROM Properties Page shell extension. (librpbase) *
* IPartition.cpp: Partition reader interface. * * IPartition.cpp: Partition reader interface. *
* * * *
* Copyright (c) 2016-2024 by David Korth. * * Copyright (c) 2016-2025 by David Korth. *
* SPDX-License-Identifier: GPL-2.0-or-later * * SPDX-License-Identifier: GPL-2.0-or-later *
***************************************************************************/ ***************************************************************************/
@ -38,7 +38,7 @@ IFst::Dir *IPartition::opendir(const char *path)
* @return IFst::DirEnt, or nullptr if end of directory or on error. * @return IFst::DirEnt, or nullptr if end of directory or on error.
* (TODO: Add lastError()?) * (TODO: Add lastError()?)
*/ */
IFst::DirEnt *IPartition::readdir(IFst::Dir *dirp) const IFst::DirEnt *IPartition::readdir(IFst::Dir *dirp)
{ {
RP_UNUSED(dirp); RP_UNUSED(dirp);
assert(!"IFst wrapper functions are not implemented for this class!"); assert(!"IFst wrapper functions are not implemented for this class!");

View File

@ -2,7 +2,7 @@
* ROM Properties Page shell extension. (librpbase) * * ROM Properties Page shell extension. (librpbase) *
* IPartition.hpp: Partition reader interface. * * IPartition.hpp: Partition reader interface. *
* * * *
* Copyright (c) 2016-2024 by David Korth. * * Copyright (c) 2016-2025 by David Korth. *
* SPDX-License-Identifier: GPL-2.0-or-later * * SPDX-License-Identifier: GPL-2.0-or-later *
***************************************************************************/ ***************************************************************************/
@ -87,7 +87,7 @@ public:
* @return IFst::DirEnt, or nullptr if end of directory or on error. * @return IFst::DirEnt, or nullptr if end of directory or on error.
* (TODO: Add lastError()?) * (TODO: Add lastError()?)
*/ */
virtual IFst::DirEnt *readdir(IFst::Dir *dirp); virtual const IFst::DirEnt *readdir(IFst::Dir *dirp);
/** /**
* Close an opened directory. * Close an opened directory.