This patch introduce a new macro to return a value clamped to a given range. Signed-off-by: Dongsheng Yang <yangds.fnst@xxxxxxxxxxxxxx> --- src/util/virutil.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util/virutil.h b/src/util/virutil.h index 2bb74e2..e8536d8 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -37,6 +37,12 @@ # ifndef MAX # define MAX(a, b) ((a) > (b) ? (a) : (b)) # endif +# ifndef CLAMP +# define CLAMP(v, min, max) ({ \ + typeof(v) _v = v; \ + _v = _v < min ? min: _v; \ + _v > max ? max: _v; }) +# endif int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK; int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK; -- 1.8.2.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list