smbconv.c 973 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "headers.h"
  10. uint16_t
  11. smbnhgets(uint8_t *p)
  12. {
  13. return p[0] | (p[1] << 8);
  14. }
  15. uint32_t
  16. smbnhgetl(uint8_t *p)
  17. {
  18. return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
  19. }
  20. void
  21. smbhnputs(uint8_t *p, uint16_t v)
  22. {
  23. p[0] = v;
  24. p[1] = v >> 8;
  25. }
  26. void
  27. smbhnputl(uint8_t *p, uint32_t v)
  28. {
  29. p[0] = v;
  30. p[1] = v >> 8;
  31. p[2] = v >> 16;
  32. p[3] = v >> 24;
  33. }
  34. void
  35. smbhnputv(uint8_t *p, int64_t v)
  36. {
  37. smbhnputl(p, v);
  38. smbhnputl(p + 4, (v >> 32) & 0xffffffff);
  39. }
  40. int64_t
  41. smbnhgetv(uint8_t *p)
  42. {
  43. return (int64_t)smbnhgetl(p) | ((int64_t)smbnhgetl(p + 4) << 32);
  44. }