From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XigTL-0008NT-9D for qemu-devel@nongnu.org; Mon, 27 Oct 2014 05:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XigTE-0005DP-Oy for qemu-devel@nongnu.org; Mon, 27 Oct 2014 05:20:19 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:60690 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XigTE-0005DG-Es for qemu-devel@nongnu.org; Mon, 27 Oct 2014 05:20:12 -0400 From: Peter Lieven Date: Mon, 27 Oct 2014 10:18:43 +0100 Message-Id: <1414401528-21884-2-git-send-email-pl@kamp.de> In-Reply-To: <1414401528-21884-1-git-send-email-pl@kamp.de> References: <1414401528-21884-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCHv6 1/6] util: introduce MIN_NON_ZERO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, benoit@irqsave.net, ronniesahlberg@gmail.com, Peter Lieven , armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com 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 --- 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.7.9.5