memincr.c 892 B

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