summaryrefslogtreecommitdiff
path: root/src/common/util.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-03-19 16:15:39 -0400
committerNick Mathewson <nickm@torproject.org>2013-03-19 16:15:39 -0400
commitc547502ecbe3f9ddfcca90b5c70887e300493cc1 (patch)
treefbaf1b31f4239b91432a7ee0b41a40889e6996f1 /src/common/util.h
parentacbfc9c8cc2c24adb610d391cb2b83d7cbc11719 (diff)
parent6f20a74d52741cce521cf03b8afee570e3cb367b (diff)
downloadtor-c547502ecbe3f9ddfcca90b5c70887e300493cc1.tar.gz
tor-c547502ecbe3f9ddfcca90b5c70887e300493cc1.zip
Merge remote-tracking branch 'origin/maint-0.2.4'
Diffstat (limited to 'src/common/util.h')
-rw-r--r--src/common/util.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/common/util.h b/src/common/util.h
index 4b923bf845..0dd6da3a57 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -172,6 +172,17 @@ int n_bits_set_u8(uint8_t v);
* overflow. */
#define CEIL_DIV(a,b) (((a)+(b)-1)/(b))
+/* Return <b>v</b> if it's between <b>min</b> and <b>max</b>. Otherwise
+ * return <b>min</b> if <b>v</b> is smaller than <b>min</b>, or <b>max</b> if
+ * <b>b</b> is larger than <b>max</b>.
+ *
+ * Requires that <b>min</b> is no more than <b>max</b>. May evaluate any of
+ * its arguments more than once! */
+#define CLAMP(min,v,max) \
+ ( ((v) < (min)) ? (min) : \
+ ((v) > (max)) ? (max) : \
+ (v) )
+
/* String manipulation */
/** Allowable characters in a hexadecimal string. */