1*86d7f5d3SJohn Marino /* Buffer primitives for comparison operations.
2*86d7f5d3SJohn Marino Copyright (C) 1993 Free Software Foundation, Inc.
3*86d7f5d3SJohn Marino
4*86d7f5d3SJohn Marino This program is free software; you can redistribute it and/or modify
5*86d7f5d3SJohn Marino it under the terms of the GNU General Public License as published by
6*86d7f5d3SJohn Marino the Free Software Foundation; either version 2, or (at your option)
7*86d7f5d3SJohn Marino any later version.
8*86d7f5d3SJohn Marino
9*86d7f5d3SJohn Marino This program is distributed in the hope that it will be useful,
10*86d7f5d3SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of
11*86d7f5d3SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*86d7f5d3SJohn Marino GNU General Public License for more details.
13*86d7f5d3SJohn Marino
14*86d7f5d3SJohn Marino */
15*86d7f5d3SJohn Marino
16*86d7f5d3SJohn Marino #include "system.h"
17*86d7f5d3SJohn Marino #include "cmpbuf.h"
18*86d7f5d3SJohn Marino
19*86d7f5d3SJohn Marino /* Least common multiple of two buffer sizes A and B. */
20*86d7f5d3SJohn Marino
21*86d7f5d3SJohn Marino size_t
buffer_lcm(a,b)22*86d7f5d3SJohn Marino buffer_lcm (a, b)
23*86d7f5d3SJohn Marino size_t a, b;
24*86d7f5d3SJohn Marino {
25*86d7f5d3SJohn Marino size_t m, n, r;
26*86d7f5d3SJohn Marino
27*86d7f5d3SJohn Marino /* Yield reasonable values if buffer sizes are zero. */
28*86d7f5d3SJohn Marino if (!a)
29*86d7f5d3SJohn Marino return b ? b : 8 * 1024;
30*86d7f5d3SJohn Marino if (!b)
31*86d7f5d3SJohn Marino return a;
32*86d7f5d3SJohn Marino
33*86d7f5d3SJohn Marino /* n = gcd (a, b) */
34*86d7f5d3SJohn Marino for (m = a, n = b; (r = m % n) != 0; m = n, n = r)
35*86d7f5d3SJohn Marino continue;
36*86d7f5d3SJohn Marino
37*86d7f5d3SJohn Marino return a/n * b;
38*86d7f5d3SJohn Marino }
39