uint32.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: Marcus Boerger <helly@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. /* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/
  17. #ifdef HAVE_CONFIG_H
  18. #include "config.h"
  19. #endif
  20. #include "php.h"
  21. #include "uint32.h"
  22. /* {{{ uint32_pack */
  23. void uint32_pack(char *out, uint32 in)
  24. {
  25. out[0] = in&0xff; in>>=8;
  26. out[1] = in&0xff; in>>=8;
  27. out[2] = in&0xff; in>>=8;
  28. out[3] = in&0xff;
  29. }
  30. /* }}} */
  31. /* {{{ uint32_unpack */
  32. void uint32_unpack(const char *in, uint32 *out)
  33. {
  34. *out = (((uint32)(unsigned char)in[3])<<24) |
  35. (((uint32)(unsigned char)in[2])<<16) |
  36. (((uint32)(unsigned char)in[1])<<8) |
  37. (((uint32)(unsigned char)in[0]));
  38. }
  39. /* }}} */