Revert "strcpy -> strlcpy."
[elinks.git] / src / util / math.h
blob0d5c0f3a15bd4201d1e45fb026986b97afba28a8
1 #ifndef EL__UTIL_MATH_H
2 #define EL__UTIL_MATH_H
5 /* It's evil to include this directly, elinks.h includes it for you
6 * at the right time. */
9 /* These macros will evaluate twice their arguments.
10 * Ie. MIN(a+b, c+d) will do 3 additions...
11 * Please prefer to use int_min() and int_max() if possible. */
13 /* FreeBSD needs this. */
14 #ifdef MIN
15 #undef MIN
16 #endif
18 #ifdef MAX
19 #undef MAX
20 #endif
22 #define MIN(x, y) ((x) < (y) ? (x) : (y))
23 #define MAX(x, y) ((x) > (y) ? (x) : (y))
26 static inline int
27 int_min(register int x, register int y)
29 if (x < y) return x;
30 return y;
33 static inline int
34 int_max(register int x, register int y)
36 if (x > y) return x;
37 return y;
41 /** Limit @a what pointed value to upper bound @a limit. */
42 static inline void
43 int_upper_bound(register int *what, register int limit)
45 if (*what > limit) *what = limit;
48 /** Limit @a what pointed value to lower bound @a limit. */
49 static inline void
50 int_lower_bound(register int *what, register int limit)
52 if (*what < limit) *what = limit;
55 /** Limit @a what pointed value to lower bound @a lower_limit and to
56 * upper bound @a upper_limit. */
57 static inline void
58 int_bounds(register int *what, register int lower_limit,
59 register int upper_limit)
61 if (*what < lower_limit)
62 *what = lower_limit;
63 else if (*what > upper_limit)
64 *what = upper_limit;
68 /** Swap values @a a and @a b, both of type @a type.
69 * This is supposed to evaluate at compile time, giving no performance hit. */
70 #define swap_values(type, a, b) \
71 do { \
72 type swap_register_ = (a); \
73 (a) = (b); \
74 (b) = (swap_register_); \
75 } while (0)
77 #endif