ディレクトリを開いてそのファイルをトラバースしようとすると、readdir を呼び出すたびに個々のファイルを取得できません。これは私のコードです:
Plugin* load_plugins(char * plugName) {
char ** pluginPaths = getPluginPaths();
Plugin ** plugins = malloc(0);
//char* env = getenv("PLUGIN_DIR");
DIR* dir = opendir("./plugins/"); //opens the directory specifying the available plugins
struct dirent* dr = readdir(dir);
int i = 0;
while ((dr = readdir(dir))) {
i++;
//everytime we add a plugin we allocate more space
plugins = realloc(plugins, i * sizeof(Plugin));
void *handle = dlopen(strcat("./plugins/", dr->d_name), RTLD_LAZY);
if (!handle) { exit(1); }
//do some stuff with the plugin here
}
return plugins;
}
何が間違っている可能性がありますか?readdir の最初の呼び出しは、d_name を持つ dirent* を返します: dirent 構造体