pack.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* $MirOS: contrib/hosted/fwcf/pack.h,v 1.13 2007/03/09 21:10:29 tg Exp $ */
  2. /*
  3. * This file is part of the FreeWRT project. FreeWRT is copyrighted
  4. * material, please see the LICENCE file in the top-level directory
  5. * or at http://www.freewrt.org/licence for details.
  6. */
  7. #ifndef PACK_H
  8. #define PACK_H
  9. struct FTSF_ENTRY;
  10. #ifndef FTS_SUBS_H
  11. typedef struct FTSF_ENTRY ftsf_entry;
  12. #endif
  13. /* XXX use macros from minilzop.h */
  14. #define STOREB(x) do { \
  15. if (hdrleft < 1) \
  16. return (NULL); \
  17. *hdrptr++ = (x) & 0xFF; \
  18. --hdrleft; \
  19. } while (0)
  20. #define STOREW(x) do { \
  21. if (hdrleft < 2) \
  22. return (NULL); \
  23. *hdrptr++ = (x) & 0xFF; \
  24. *hdrptr++ = ((x) >> 8) & 0xFF; \
  25. hdrleft -= 2; \
  26. } while (0)
  27. #define STORET(x) do { \
  28. if (hdrleft < 3) \
  29. return (NULL); \
  30. *hdrptr++ = (x) & 0xFF; \
  31. *hdrptr++ = ((x) >> 8) & 0xFF; \
  32. *hdrptr++ = ((x) >> 16) & 0xFF; \
  33. hdrleft -= 3; \
  34. } while (0)
  35. #define STORED(x) do { \
  36. if (hdrleft < 4) \
  37. return (NULL); \
  38. *hdrptr++ = (x) & 0xFF; \
  39. *hdrptr++ = ((x) >> 8) & 0xFF; \
  40. *hdrptr++ = ((x) >> 16) & 0xFF; \
  41. *hdrptr++ = ((x) >> 24) & 0xFF; \
  42. hdrleft -= 4; \
  43. } while (0)
  44. #define LOADW(x) __extension__({ \
  45. uint8_t *lwbf = (uint8_t *)(x); \
  46. uint32_t res = 0; \
  47. res = (res << 8) | lwbf[1]; \
  48. res = (res << 8) | lwbf[0]; \
  49. res; \
  50. })
  51. #define LOADT(x) __extension__({ \
  52. uint8_t *lwbf = (uint8_t *)(x); \
  53. uint32_t res = 0; \
  54. res = (res << 8) | lwbf[2]; \
  55. res = (res << 8) | lwbf[1]; \
  56. res = (res << 8) | lwbf[0]; \
  57. res; \
  58. })
  59. #define LOADD(x) __extension__({ \
  60. uint8_t *lwbf = (uint8_t *)(x); \
  61. uint32_t res = 0; \
  62. res = (res << 8) | lwbf[3]; \
  63. res = (res << 8) | lwbf[2]; \
  64. res = (res << 8) | lwbf[1]; \
  65. res = (res << 8) | lwbf[0]; \
  66. res; \
  67. })
  68. __BEGIN_DECLS
  69. char *ft_pack(ftsf_entry *);
  70. char *ft_packm(void);
  71. char *mkheader(char *, size_t, uint32_t, uint32_t, uint8_t);
  72. char *mktrailer(char *, size_t);
  73. void ft_dump(char *);
  74. void ft_creatm(char *, const char *);
  75. char *fwcf_unpack(int, size_t *);
  76. char *fwcf_pack(char *, size_t, int, size_t *);
  77. char *fwcf_packm(const char *, int, size_t *);
  78. __END_DECLS
  79. #endif