[PATCH BlueZ v1 1/4] util: Add UTIL_IOV_INIT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

This adds UTIL_IOV_INIT macro which can be used to init elements of
struct iovec with a byte array.
---
 src/shared/lc3.h  | 24 ++++++++----------------
 src/shared/util.h |  8 ++++++++
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/shared/lc3.h b/src/shared/lc3.h
index e6b043699bc1..3a8c6f7b5841 100644
--- a/src/shared/lc3.h
+++ b/src/shared/lc3.h
@@ -7,14 +7,6 @@
  *
  */
 
-#define data(args...) ((const unsigned char[]) { args })
-
-#define LC3_IOV(args...) \
-	{ \
-		.iov_base = (void *)data(args), \
-		.iov_len = sizeof(data(args)), \
-	}
-
 #define LC3_ID			0x06
 
 #define LC3_BASE		0x01
@@ -53,11 +45,11 @@
 #define LC3_FRAME_COUNT		(LC3_BASE + 4)
 
 #define LC3_CAPABILITIES(_freq, _duration, _chan_count, _len_min, _len_max) \
-	LC3_IOV(0x02, LC3_FREQ, _freq, _freq >> 8, \
-		0x02, LC3_DURATION, _duration, \
-		0x02, LC3_CHAN_COUNT, _chan_count, \
-		0x05, LC3_FRAME_LEN, _len_min, _len_min >> 8, \
-		_len_max, _len_max >> 8)
+	UTIL_IOV_INIT(0x02, LC3_FREQ, _freq, _freq >> 8, \
+			0x02, LC3_DURATION, _duration, \
+			0x02, LC3_CHAN_COUNT, _chan_count, \
+			0x05, LC3_FRAME_LEN, _len_min, _len_min >> 8, \
+			_len_max, _len_max >> 8)
 
 #define LC3_CONFIG_BASE		0x01
 
@@ -80,9 +72,9 @@
 #define LC3_CONFIG_FRAME_LEN	(LC3_CONFIG_BASE + 3)
 
 #define LC3_CONFIG(_freq, _duration, _len) \
-	LC3_IOV(0x02, LC3_CONFIG_FREQ, _freq, \
-		0x02, LC3_CONFIG_DURATION, _duration, \
-		0x03, LC3_CONFIG_FRAME_LEN, _len, _len >> 8)
+	UTIL_IOV_INIT(0x02, LC3_CONFIG_FREQ, _freq, \
+			0x02, LC3_CONFIG_DURATION, _duration, \
+			0x03, LC3_CONFIG_FRAME_LEN, _len, _len >> 8)
 
 #define LC3_CONFIG_8(_duration, _len) \
 	LC3_CONFIG(LC3_CONFIG_FREQ_8KHZ, _duration, _len)
diff --git a/src/shared/util.h b/src/shared/util.h
index 596663b8519c..6322b13d612a 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -151,6 +151,14 @@ ssize_t util_getrandom(void *buf, size_t buflen, unsigned int flags);
 uint8_t util_get_uid(uint64_t *bitmap, uint8_t max);
 void util_clear_uid(uint64_t *bitmap, uint8_t id);
 
+#define util_data(args...) ((const unsigned char[]) { args })
+
+#define UTIL_IOV_INIT(args...) \
+{ \
+	.iov_base = (void *)util_data(args), \
+	.iov_len = sizeof(util_data(args)), \
+}
+
 struct iovec *util_iov_dup(const struct iovec *iov, size_t cnt);
 int util_iov_memcmp(const struct iovec *iov1, const struct iovec *iov2);
 void util_iov_memcpy(struct iovec *iov, void *src, size_t len);
-- 
2.43.0





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux