[CRIU] [PATCHv2 1/3] util: Introduce STREQ and STRNEQ macros

Radostin Stoyanov rstoyanov1 at gmail.com
Tue Jan 29 16:11:19 MSK 2019


The function strcmp() is often used to check whether two strings are
equal. The macros STREQ and STRNEQ could be used instead to improve
readability of the source code.

- v2: surround the macro-variables with parenthesis (Thanks to Mike Rapoport)

Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 criu/include/util.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/criu/include/util.h b/criu/include/util.h
index d9a1ff0f5..ea0c757bb 100644
--- a/criu/include/util.h
+++ b/criu/include/util.h
@@ -200,6 +200,10 @@ extern int read_fd_link(int lfd, char *buf, size_t size);
 
 int vaddr_to_pfn(int fd, unsigned long vaddr, u64 *pfn);
 
+/* String equality tests */
+#define STREQ(a, b) (strcmp((a), (b)) == 0)
+#define STRNEQ(a, b) (strcmp((a), (b)) != 0)
+
 /*
  * Check whether @str starts with @sub and report the
  * next character of @str in @end
-- 
2.20.1



More information about the CRIU mailing list