- /* Recursively walk directory */
- while (!readdir_r(directory, entry, &result) && result) {
- struct stat st;
- int stat_ret;
- size_t file_name_len;
-
- if (result->d_name[0] == '.') {
- /* Skip hidden files, . and .. */
- continue;
- }
-
- file_name_len = strlen(result->d_name);
-
- if (path_len + file_name_len >= PATH_MAX) {
- continue;
- }
-
- strncpy(file_path + path_len, result->d_name, file_name_len);
- file_path[path_len + file_name_len] = '\0';
- stat_ret = stat(file_path, &st);
- if (stat_ret < 0) {
- /* Continue to next file / directory. */
- printf_perror("Failed to stat() plugin file\n");
- continue;
- }
-
- if (S_ISDIR(st.st_mode) && recurse) {
- ret = bt_plugin_create_append_all_from_dir(plugins,
- file_path, true);
- if (ret < 0) {
- goto end;
- }
- } else if (S_ISREG(st.st_mode)) {
- struct bt_plugin **plugins_from_file =
- bt_plugin_create_all_from_file(file_path);
-
- if (plugins_from_file) {
- struct bt_plugin **plugin;
-
- for (plugin = plugins_from_file; *plugin; plugin++) {
- /* Transfer ownership to array */
- g_ptr_array_add(plugins, *plugin);
- }
-
- free(plugins_from_file);
- }
- }
- }