cmpbuf.c 1.2 KB

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