diff --git a/src/adapter.c b/src/adapter.c
index 602c2fd..60c0261 100644
--- a/src/adapter.c
+++ b/src/adapter.c
return addr_type;
}
-static unsigned char dirent_type(const char *parent, const char *name)
-{
- char filename[PATH_MAX];
- struct stat st;
-
- snprintf(filename, sizeof(filename), "%s/%s", parent, name);
- if (lstat(filename, &st) == 0 && S_ISDIR(st.st_mode))
- return DT_DIR;
-
- return DT_UNKNOWN;
-}
-
static void load_devices(struct btd_adapter *adapter)
{
char dirname[PATH_MAX];
uint8_t bdaddr_type;
if (entry->d_type == DT_UNKNOWN)
- entry->d_type = dirent_type(dirname, entry->d_name);
+ entry->d_type = util_get_dt(dirname, entry->d_name);
if (entry->d_type != DT_DIR || bachk(entry->d_name) < 0)
continue;
diff --git a/src/device.c b/src/device.c
index 31d6d0b..3f74b2c 100644
--- a/src/device.c
+++ b/src/device.c
#include "log.h"
+#include "src/shared/util.h"
#include "btio/btio.h"
#include "lib/uuid.h"
#include "lib/mgmt.h"
g_str_equal(entry->d_name, ".."))
continue;
+ if (entry->d_type == DT_UNKNOWN)
+ entry->d_type = util_get_dt(dirname, entry->d_name);
+
snprintf(filename, PATH_MAX, "%s/%s", dirname, entry->d_name);
if (entry->d_type == DT_DIR)
diff --git a/src/shared/util.c b/src/shared/util.c
index eb90ecb..8530440 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
#include "src/shared/util.h"
function(str, user_data);
}
}
+
+/* Helper for getting the dirent type in case readdir returns DT_UNKNOWN */
+unsigned char util_get_dt(const char *parent, const char *name)
+{
+ char filename[PATH_MAX];
+ struct stat st;
+
+ snprintf(filename, sizeof(filename), "%s/%s", parent, name);
+ if (lstat(filename, &st) == 0 && S_ISDIR(st.st_mode))
+ return DT_DIR;
+
+ return DT_UNKNOWN;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 4bc77a1..04c600f 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
void util_hexdump(const char dir, const unsigned char *buf, size_t len,
util_debug_func_t function, void *user_data);
+unsigned char util_get_dt(const char *parent, const char *name);
+
static inline void bswap_128(const void *src, void *dst)
{
const uint8_t *s = src;