libthingplugins/src/plugins.c (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <dirent.h>
#include <stdio.h>
#include <string.h>
int readplugins(void) {
struct dirent *de;
DIR *dr = opendir("/usr/share/thing/plugins/");
if (dr == NULL) {
printf("Could not open plugin capability directory "
"(/usr/share/thing/plugins/)");
return 1;
}
while ((de = readdir(dr)) != NULL) {
// if filename shorter than x.toml -> 6
if (sizeof(de->d_name) / sizeof(de->d_name[0]) - 1 < 6)
continue;
// if it ends with toml
char *ext = strrchr(de->d_name, '.');
if (!(strcmp(ext, ".toml")))
printf("%s\n", de->d_name);
}
closedir(dr);
return 0;
}
|