chipset/bcm: use tinydir instead of dirent

This commit is contained in:
Matthias Ringwald 2022-06-10 18:41:48 +02:00
parent bd68af28a3
commit 761802ccfc

View File

@ -55,8 +55,8 @@
#include "hci.h" #include "hci.h"
#ifdef HAVE_POSIX_FILE_IO #ifdef HAVE_POSIX_FILE_IO
#include "tinydir.h"
#include <ctype.h> #include <ctype.h>
#include <dirent.h>
#endif #endif
// assert outgoing and incoming hci packet buffers can hold max hci command resp. event packet // assert outgoing and incoming hci packet buffers can hold max hci command resp. event packet
@ -219,25 +219,28 @@ void btstack_chipset_bcm_set_device_name(const char * device_name){
log_info("chipset-bcm: looking for %s and %s", filename_short, filename_complete); log_info("chipset-bcm: looking for %s and %s", filename_short, filename_complete);
// find in folder // find in folder
DIR *dirp = opendir(hcd_folder_path); tinydir_dir dir = { 0 };
int match_short = 0; int res = tinydir_open(&dir, hcd_folder_path);
int match_complete = 0; if (res < 0){
if (!dirp){
log_error("chipset-bcm: could not get directory for %s", hcd_folder_path); log_error("chipset-bcm: could not get directory for %s", hcd_folder_path);
return; return;
} }
while (true){
struct dirent *dp = readdir(dirp); int match_short = 0;
if (!dp) break; int match_complete = 0;
if (equal_ignore_case(filename_complete, dp->d_name)){ while (dir.has_next) {
tinydir_file file;
tinydir_readfile(&dir, &file);
tinydir_next(&dir);
if (equal_ignore_case(filename_complete, file.name)){
match_complete = 1; match_complete = 1;
continue; continue;
} }
if (equal_ignore_case(filename_short, dp->d_name)){ if (equal_ignore_case(filename_short, file.name)){
match_short = 1; match_short = 1;
} }
} }
closedir(dirp); tinydir_close(&dir);
if (match_complete){ if (match_complete){
sprintf(matched_file, "%s/%s", hcd_folder_path, filename_complete); sprintf(matched_file, "%s/%s", hcd_folder_path, filename_complete);
hcd_file_path = matched_file; hcd_file_path = matched_file;