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

Submitted by Radostin Stoyanov on Jan. 27, 2019, 10:18 p.m.

Details

Message ID 20190127221859.29335-1-rstoyanov1@gmail.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Radostin Stoyanov Jan. 27, 2019, 10:18 p.m.
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.

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

Patch hide | download patch | download mbox

diff --git a/criu/include/util.h b/criu/include/util.h
index d9a1ff0f5..427fd5105 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

Comments

Mike Rapoport Jan. 28, 2019, 3:03 p.m.
On Sun, Jan 27, 2019 at 10:18:57PM +0000, Radostin Stoyanov wrote:
> 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.
 
> Signed-off-by: Radostin Stoyanov <rstoyanov1@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..427fd5105 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)

strcmp((a), (b))

> +#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
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
>