home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OS9000 / APPS / diff.lzh / diff / cmpbuf.c < prev    next >
Text File  |  1986-04-24  |  1KB  |  42 lines

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