From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:36854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UWqMc-0003HE-I8 for qemu-devel@nongnu.org; Mon, 29 Apr 2013 11:51:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UWqMW-0005Qh-46 for qemu-devel@nongnu.org; Mon, 29 Apr 2013 11:51:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4887) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UWqMV-0005Qd-Rw for qemu-devel@nongnu.org; Mon, 29 Apr 2013 11:51:32 -0400 Date: Mon, 29 Apr 2013 18:51:21 +0300 From: "Michael S. Tsirkin" Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] [PATCH 1/3] range: add structure to pass ranges around List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aliguori@us.ibm.com, qemu-devel@nongnu.org, lersek@redhat.com, kevin@koconnor.net Convenient structure to pass ranges around, and calculate length avoiding 64 bit overlap issues. Signed-off-by: Michael S. Tsirkin --- include/qemu/range.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/qemu/range.h b/include/qemu/range.h index 3502372..aeef1fb 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -1,6 +1,30 @@ #ifndef QEMU_RANGE_H #define QEMU_RANGE_H +#include + +struct Range { + uint64_t min; + uint64_t max; +}; +typedef struct Range Range; + +/* max <= min means not valid */ +static inline bool range_valid(Range *r) +{ + return r->max > r->min; +} + +static inline uint64_t range_len(Range *r) +{ + return range_valid(r) ? r->max - r->min + 1 : 0; +} + +static inline uint64_t range_start(Range *r) +{ + return r->min; +} + /* Get last byte of a range from offset + length. * Undefined for ranges that wrap around 0. */ static inline uint64_t range_get_last(uint64_t offset, uint64_t len) -- MST