diff options
Diffstat (limited to 'serial/storage.c')
-rw-r--r-- | serial/storage.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/serial/storage.c b/serial/storage.c index 110d8de7..6ea3eb41 100644 --- a/serial/storage.c +++ b/serial/storage.c @@ -25,6 +25,7 @@ #include <config.h> #endif +#include <errno.h> #include <stdlib.h> #include <termios.h> #include <unistd.h> @@ -133,3 +134,37 @@ done: return err; } + +int read_device_name(bdaddr_t *src, bdaddr_t *dst, char **name) +{ + char filename[PATH_MAX + 1], *str; + char src_addr[18], dst_addr[18]; + int len; + + ba2str(src, src_addr); + ba2str(dst, dst_addr); + + create_name(filename, PATH_MAX, STORAGEDIR, src_addr, "names"); + + str = textfile_get(filename, dst_addr); + if (!str) + return -ENOENT; + + len = strlen(str); + + /* Max remote device name */ + if (len < 248) { + *name = str; + return 0; + } + + *name = g_try_malloc0(248); + if (!*name) + return -ENOMEM; + + snprintf(*name, 248, "%s", str); + + free(str); + + return 0; +} |