FreeTDM: Add ftdm_clamp_safe()

"Safer" version of ftdm_clamp(), that swaps min/max parameters if
vmin happens to be larger than vmax, making sure the output will
always satisfy vmin <= x <= vmax.

Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
This commit is contained in:
Stefan Knoblich 2012-09-22 01:06:34 +02:00
parent 90691b36c4
commit 1d605ef47b
1 changed files with 4 additions and 0 deletions

View File

@ -87,6 +87,10 @@ typedef uint64_t ftdm_time_t;
/*! \brief Get value that is in range [vmin,vmax] */
#define ftdm_clamp(val,vmin,vmax) ftdm_max(vmin,ftdm_min(val,vmax))
/*!< \brief Safer version of ftdm_clamp(), that swaps vmin/vmax parameters if vmin > vmax */
#define ftdm_clamp_safe(val,vmin,vmax) \
ftdm_clamp(val, ftdm_min(vmin,vmax), ftdm_max(vmin,vmax))
/*!
* \brief Get offset of member in structure
* \param[in] type Type of struct