12286d8edStholo /* Buffer primitives for comparison operations.
22286d8edStholo Copyright (C) 1993 Free Software Foundation, Inc.
32286d8edStholo
42286d8edStholo This program is free software; you can redistribute it and/or modify
52286d8edStholo it under the terms of the GNU General Public License as published by
62286d8edStholo the Free Software Foundation; either version 2, or (at your option)
72286d8edStholo any later version.
82286d8edStholo
92286d8edStholo This program is distributed in the hope that it will be useful,
102286d8edStholo but WITHOUT ANY WARRANTY; without even the implied warranty of
112286d8edStholo MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
122286d8edStholo GNU General Public License for more details.
132286d8edStholo
14*c71bc7e2Stholo */
152286d8edStholo
162286d8edStholo #include "system.h"
172286d8edStholo #include "cmpbuf.h"
182286d8edStholo
192286d8edStholo /* Least common multiple of two buffer sizes A and B. */
202286d8edStholo
212286d8edStholo size_t
buffer_lcm(a,b)222286d8edStholo buffer_lcm (a, b)
232286d8edStholo size_t a, b;
242286d8edStholo {
252286d8edStholo size_t m, n, r;
262286d8edStholo
272286d8edStholo /* Yield reasonable values if buffer sizes are zero. */
282286d8edStholo if (!a)
292286d8edStholo return b ? b : 8 * 1024;
302286d8edStholo if (!b)
312286d8edStholo return a;
322286d8edStholo
332286d8edStholo /* n = gcd (a, b) */
342286d8edStholo for (m = a, n = b; (r = m % n) != 0; m = n, n = r)
352286d8edStholo continue;
362286d8edStholo
372286d8edStholo return a/n * b;
382286d8edStholo }
39