hexoffset.c 954 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*====================================================================*
  2. *
  3. * char * hexoffset (char buffer [], size_t length, off_t offset);
  4. *
  5. * memory.h
  6. *
  7. * encode buffer with with a NUL terminated string containing the
  8. * hexadecimal representation of a memory offset; the result will
  9. * be padded with leading zeros;
  10. *
  11. * Motley Tools by Charles Maier;
  12. * Copyright (c) 2001-2006 by Charles Maier Associates;
  13. * Licensed under the Internet Software Consortium License;
  14. *
  15. *--------------------------------------------------------------------*/
  16. #ifndef HEXOFFSET_SOURCE
  17. #define HEXOFFSET_SOURCE
  18. #include <memory.h>
  19. #include "../tools/number.h"
  20. #include "../tools/memory.h"
  21. char * hexoffset (char buffer [], size_t length, off_t offset)
  22. {
  23. char * string = buffer + length - 1;
  24. memset (buffer, 0, length);
  25. while (string > buffer)
  26. {
  27. *--string = DIGITS_HEX [offset & 0x0F];
  28. offset >>= 4;
  29. }
  30. return (buffer);
  31. }
  32. #endif