+static void scan_plugins(void)
+{
+ char fname[MAXPATHLEN];
+ struct dirent *ent;
+ int gpu_i, spu_i;
+ char *p;
+ DIR *dir;
+
+ gpu_plugins[0] = "builtin_gpu";
+ spu_plugins[0] = "builtin_spu";
+ gpu_i = spu_i = 1;
+
+ snprintf(fname, sizeof(fname), "%s/", Config.PluginsDir);
+ dir = opendir(fname);
+ if (dir == NULL) {
+ perror("scan_plugins opendir");
+ return;
+ }
+
+ while (1) {
+ void *h, *tmp;
+
+ errno = 0;
+ ent = readdir(dir);
+ if (ent == NULL) {
+ if (errno != 0)
+ perror("readdir");
+ break;
+ }
+ p = strstr(ent->d_name, ".so");
+ if (p == NULL)
+ continue;
+
+ snprintf(fname, sizeof(fname), "%s/%s", Config.PluginsDir, ent->d_name);
+ h = dlopen(fname, RTLD_LAZY | RTLD_LOCAL);
+ if (h == NULL) {
+ fprintf(stderr, "%s\n", dlerror());
+ continue;
+ }
+
+ // now what do we have here?
+ tmp = dlsym(h, "GPUinit");
+ if (tmp) {
+ dlclose(h);
+ if (gpu_i < ARRAY_SIZE(gpu_plugins) - 1)
+ gpu_plugins[gpu_i++] = strdup(ent->d_name);
+ continue;
+ }
+
+ tmp = dlsym(h, "SPUinit");
+ if (tmp) {
+ dlclose(h);
+ if (spu_i < ARRAY_SIZE(spu_plugins) - 1)
+ spu_plugins[spu_i++] = strdup(ent->d_name);
+ continue;
+ }
+
+ fprintf(stderr, "ignoring unidentified plugin: %s\n", fname);
+ dlclose(h);
+ }
+
+ closedir(dir);
+}
+