#### /contrib/cvs/diff/cmpbuf.c

C | 38 lines | 15 code | 6 blank | 17 comment | 4 complexity | 34844cce37cae63d77e476b540a91351 MD5 | raw file

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