msgb: Add helper macro to decide if a segment is incomplete

This helps avoid common logical fallacies that that happen
quickly during coding (i.e. giving a false logical condition)
for a condition any segmentation callback will need.

Related: OS#5753
Change-Id: Ifc7cf0629e93864bfb3e36c64143d4ccc777e4b6
diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h
index 5c58c84..372b85b 100644
--- a/include/osmocom/core/msgb.h
+++ b/include/osmocom/core/msgb.h
@@ -773,4 +773,11 @@
 	return osmo_hexdump((const unsigned char*) msgb_l4(msg), msgb_l4len(msg));
 }
 
+/*! Macro for checking a simple condition (to avoid accidental bugs)
+ *  \param[in] msg Target 'struct msg *'
+ *  \param[in] len_from_msg_metadata Length of data as expected from metadata of msg
+ *  \returns boolean indicating if the data segment starting at msg->data is incomplete
+ */
+#define msgb_segment_is_incomplete(len_from_msg_metadata, msg)\
+	(len_from_msg_metadata > (msg)->len)
 /*! @} */