/contrib/cvs/diff/cmpbuf.c

https://bitbucket.org/freebsd/freebsd-head/ · 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. 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. */
  12. #include "system.h"
  13. #include "cmpbuf.h"
  14. /* Least common multiple of two buffer sizes A and B. */
  15. size_t
  16. buffer_lcm (a, b)
  17. size_t a, b;
  18. {
  19. size_t m, n, r;
  20. /* Yield reasonable values if buffer sizes are zero. */
  21. if (!a)
  22. return b ? b : 8 * 1024;
  23. if (!b)
  24. return a;
  25. /* n = gcd (a, b) */
  26. for (m = a, n = b; (r = m % n) != 0; m = n, n = r)
  27. continue;
  28. return a/n * b;
  29. }