[CRIU] [PATCHv2 1/3] util: Introduce STREQ and STRNEQ macros
Andrei Vagin
avagin at gmail.com
Tue Jan 29 20:24:34 MSK 2019
On Tue, Jan 29, 2019 at 01:11:19PM +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.
It is an arguable question. If I read code, I know what strcmp does, but
STREQ is just a macros and I need to look what is inside of it.
And when a code contains a lot of such macroses it is hard to develop
something, especially when it is a new developer who are not familiar
with a code base.
>
> - 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
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list