Browse Source

qcacmn: Add qdf_str_eq() API

strcmp() is regularly used to compare two strings for equality. However,
reading source code using strcmp in this manner can be prone to errors
because the return values are not obvious from the function's name. In
the best case, this leads to referring to the strcmp documentation more
often than one would like. In the worst case, this leads to difficult to
spot bugs. Add a thin wrapper for this use case to make intentions
abundantly clear to future readers. This wrapper is effectively sugar
for 'strcmp(left, right) == 0'.

For example:
	if (!strcmp(left, right))
	/* reads: if not string compare: left, right */

Becomes:
	if (qdf_str_eq(left, right))
	/* reads: if string equal: left, right */

Change-Id: Iabcb7c7e9f37dcb6cf1bdf5d7cc6c69ea926ba5c
CRs-Fixed: 2194508
Dustin Brown 7 years ago
parent
commit
64740289bc
1 changed files with 14 additions and 0 deletions
  1. 14 0
      qdf/inc/qdf_mem.h

+ 14 - 0
qdf/inc/qdf_mem.h

@@ -275,6 +275,20 @@ static inline int32_t qdf_str_cmp(const char *str1, const char *str2)
 	return __qdf_str_cmp(str1, str2);
 }
 
+/**
+ * qdf_str_eq - compare two null-terminated strings for equality
+ * @left: the string left of the equality
+ * @right: the string right of the equality
+ *
+ * This is a thin wrapper over `if (strcmp(left, right) == 0)` for clarity.
+ *
+ * Return: true if strings are equal
+ */
+static inline bool qdf_str_eq(const char *left, const char *right)
+{
+	return qdf_str_cmp(left, right) == 0;
+}
+
 /**
  * qdf_str_lcopy - Copy from one string to another
  * @dest: destination string