aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-03-19 16:15:27 -0400
committerNick Mathewson <nickm@torproject.org>2013-03-19 16:15:27 -0400
commit6f20a74d52741cce521cf03b8afee570e3cb367b (patch)
treec49d5aab8a038da07570612795861ea32bf6cb2d /src/common
parenta7b46336eb5f1f7f734ac2d978c7ab17d1c870c0 (diff)
parent18752bca5b57c11b6d843db671e1886ed0624848 (diff)
downloadtor-6f20a74d52741cce521cf03b8afee570e3cb367b.tar.gz
tor-6f20a74d52741cce521cf03b8afee570e3cb367b.zip
Merge branch 'bug8240_v2_squashed' into maint-0.2.4
Conflicts: doc/tor.1.txt src/or/circuitbuild.c src/or/config.c src/or/or.h
Diffstat (limited to 'src/common')
-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 fbf6d2bea4..712352b032 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. */