diff options
-rw-r--r-- | include/bluetooth.h | 7 | ||||
-rw-r--r-- | src/bluetooth.c | 51 |
2 files changed, 56 insertions, 2 deletions
diff --git a/include/bluetooth.h b/include/bluetooth.h index a005c1c7..d7747996 100644 --- a/include/bluetooth.h +++ b/include/bluetooth.h @@ -36,9 +36,9 @@ extern "C" { #endif #include <stdint.h> +#include <string.h> #include <endian.h> #include <byteswap.h> -#include <string.h> #ifndef AF_BLUETOOTH #define AF_BLUETOOTH 31 @@ -129,6 +129,11 @@ char *batostr(const bdaddr_t *ba); int ba2str(const bdaddr_t *ba, char *str); int str2ba(const char *str, bdaddr_t *ba); +int baprintf(const char *format, ...); +int bafprintf(FILE *stream, const char *format, ...); +int basprintf(char *str, const char *format, ...); +int basnprintf(char *str, size_t size, const char *format, ...); + int bt_error(uint16_t code); char *bt_compidtostr(int id); diff --git a/src/bluetooth.c b/src/bluetooth.c index 110d65cd..484b263b 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -33,9 +33,10 @@ #endif #include <stdio.h> +#include <errno.h> +#include <stdarg.h> #include <stdlib.h> #include <string.h> -#include <errno.h> #include <sys/socket.h> #include <bluetooth/bluetooth.h> @@ -105,6 +106,54 @@ int str2ba(const char *str, bdaddr_t *ba) return 0; } +int baprintf(const char *format, ...) +{ + va_list ap; + int len; + + va_start(ap, format); + len = vprintf(format, ap); + va_end(ap); + + return len; +} + +int bafprintf(FILE *stream, const char *format, ...) +{ + va_list ap; + int len; + + va_start(ap, format); + len = vfprintf(stream, format, ap); + va_end(ap); + + return len; +} + +int basprintf(char *str, const char *format, ...) +{ + va_list ap; + int len; + + va_start(ap, format); + len = vsnprintf(str, (~0U) >> 1, format, ap); + va_end(ap); + + return len; +} + +int basnprintf(char *str, size_t size, const char *format, ...) +{ + va_list ap; + int len; + + va_start(ap, format); + len = vsnprintf(str, size, format, ap); + va_end(ap); + + return len; +} + /* Bluetooth error codes to Unix errno mapping */ int bt_error(uint16_t code) { |