strincr.c 862 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*====================================================================*
  2. *
  3. * signed strincr (void * memory, size_t extent, byte min, byte max);
  4. *
  5. * memory.h
  6. *
  7. * increment a multi-byte memory region; start at min and reset at
  8. * max; return -1 if all bytes are max;
  9. *
  10. * Motley Tools by Charles Maier;
  11. * Copyright (c) 2001-2006 by Charles Maier Associates;
  12. * Licensed under the Internet Software Consortium License;
  13. *
  14. *--------------------------------------------------------------------*/
  15. #ifndef STRINCR_SOURCE
  16. #define STRINCR_SOURCE
  17. #include "../tools/memory.h"
  18. signed strincr (void * memory, register size_t extent, register byte min, register byte max)
  19. {
  20. register byte * offset = (byte *)(memory);
  21. while (extent--)
  22. {
  23. if (++ offset [extent] <= max)
  24. {
  25. return (0);
  26. }
  27. offset [extent] = min;
  28. }
  29. return (-1);
  30. }
  31. #endif