#include #include #include #include int readplugins(char **plugins) { struct dirent *de; DIR *dr = opendir("/usr/share/thing/plugins/"); if (dr == NULL) { perror("Could not open plugin capability directory " "(/usr/share/thing/plugins/)"); return 1; } int i = 0; // plugin counter while ((de = readdir(dr)) != NULL) { // find actual name end, as d_name is fixed length 256 bytes char *nend = strchr(de->d_name, '\0'); if (nend - de->d_name < 7) continue; // only match toml files char ext[6]; strncpy(ext, nend - 5, 6); if ((strcmp(ext, ".toml"))) continue; // retrieve only plugin name from filename // add it to plugins[] int nlen = nend - de->d_name - 5; plugins[i] = malloc(nlen); strncpy(plugins[i], de->d_name, nlen); i++; } closedir(dr); // add end signal if (i < 256) plugins[i] = ""; return 0; }