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