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