From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGAN-0003iu-Dr for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:51:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlGAH-0008VS-2z for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:51:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36577) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGAG-0008VC-Rv for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:51:17 -0500 From: Stefan Hajnoczi Date: Mon, 3 Nov 2014 11:50:04 +0000 Message-Id: <1415015456-25086-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1415015456-25086-1-git-send-email-stefanha@redhat.com> References: <1415015456-25086-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 01/53] util: introduce MIN_NON_ZERO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Peter Lieven , Stefan Hajnoczi From: Peter Lieven at least in block layer we have the case of limits being defined for a BlockDriverState. However, in this context often zero (0) has the special meanining of undefined which means no limit. If two of those limits are combined and the minimum is needed the minimum function should only return zero if both parameters are zero. Signed-off-by: Peter Lieven Reviewed-by: Max Reitz Signed-off-by: Stefan Hajnoczi --- include/qemu/osdep.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 1565404..c032434 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -68,6 +68,12 @@ typedef signed int int_fast16_t; #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif +/* Minimum function that returns zero only iff both values are zero. + * Intended for use with unsigned values only. */ +#ifndef MIN_NON_ZERO +#define MIN_NON_ZERO(a, b) (((a) != 0 && (a) < (b)) ? (a) : (b)) +#endif + #ifndef ROUND_UP #define ROUND_UP(n,d) (((n) + (d) - 1) & -(d)) #endif -- 1.9.3