[PATCH 1/2] Add buf_eq() function to check buffers for equality
Stefan Tomanek
stefan.tomanek
Sun Jan 11 02:14:36 PST 2015
A common task is to compare two buffers of variable size; this change adds a
common function to achieve this goal.
Signed-off-by: Stefan Tomanek <stefan.tomanek at wertarbyte.de>
---
src/utils/common.c | 11 +++++++++++
src/utils/common.h | 2 ++
2 files changed, 13 insertions(+)
diff --git a/src/utils/common.c b/src/utils/common.c
index 93f1722..87ed90f 100644
--- a/src/utils/common.c
+++ b/src/utils/common.c
@@ -595,6 +595,17 @@ const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len)
return ssid_txt;
}
+/**
+ * buf_eq - Check two buffers for equality
+ * @buf_a: first buffer
+ * @len_a: Length of first buffer
+ * @buf_b: second buffer
+ * @len_b: Length of second buffer
+ * Returns: 1 on equality, 0 otherwise
+ */
+int buf_eq(const void *buf_a, size_t len_a, const void *buf_b, size_t len_b) {
+ return (len_a == len_b) && (os_memcmp(buf_a, buf_b, len_a) == 0);
+}
void * __hide_aliasing_typecast(void *foo)
{
diff --git a/src/utils/common.h b/src/utils/common.h
index 82a51e5..a6ca61c 100644
--- a/src/utils/common.h
+++ b/src/utils/common.h
@@ -499,6 +499,8 @@ size_t printf_decode(u8 *buf, size_t maxlen, const char *str);
const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
+int buf_eq(const void *buf_a, size_t len_a, const void *buf_b, size_t len_b);
+
char * wpa_config_parse_string(const char *value, size_t *len);
int is_hex(const u8 *data, size_t len);
size_t merge_byte_arrays(u8 *res, size_t res_len,
--
2.1.3
More information about the Hostap
mailing list