Files
Aerofoil/UnixCompat/UnixCompat.cpp
Diomendius 9266b4402a Add UnixCompat
Provides drop-in replacements for some functions from
WindowsUnicodeToolShim and the Windows API which are used by some of the
tools that come with Aerofoil, so that these tools can be built on
Unix-like systems with minimal modifications to their code.
2024-07-31 20:23:34 +12:00

59 lines
1014 B
C++

#include <cstring>
#include <string>
#include <vector>
#include <dirent.h>
void ScanDirectoryForExtension
(
std::vector<std::string> &outPaths,
const char *path,
const char *ending,
bool recursive
) {
DIR *dir = opendir(path);
if (!dir)
{
return;
}
size_t endingLen = strlen(ending);
dirent *ent;
while ((ent = readdir(dir)))
{
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
else if (recursive && ent->d_type == DT_DIR)
{
std::string tmpPath(path);
tmpPath.append("/");
tmpPath.append(ent->d_name);
ScanDirectoryForExtension(
outPaths,
tmpPath.c_str(),
ending,
recursive
);
}
else
{
size_t nameLen = strlen(ent->d_name);
if (endingLen <= nameLen && memcmp
(
ent->d_name + nameLen - endingLen,
ending,
endingLen
) == 0
) {
std::string tmpPath(path);
tmpPath.append("/");
tmpPath.append(ent->d_name);
outPaths.push_back(std::move(tmpPath));
}
}
}
closedir(dir);
}