Types.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* Types.h -- Basic types
  2. 2008-11-23 : Igor Pavlov : Public domain */
  3. #ifndef __7Z_TYPES_H
  4. #define __7Z_TYPES_H
  5. #include <stddef.h>
  6. #ifdef _WIN32
  7. #include <windows.h>
  8. #endif
  9. #define SZ_OK 0
  10. #define SZ_ERROR_DATA 1
  11. #define SZ_ERROR_MEM 2
  12. #define SZ_ERROR_CRC 3
  13. #define SZ_ERROR_UNSUPPORTED 4
  14. #define SZ_ERROR_PARAM 5
  15. #define SZ_ERROR_INPUT_EOF 6
  16. #define SZ_ERROR_OUTPUT_EOF 7
  17. #define SZ_ERROR_READ 8
  18. #define SZ_ERROR_WRITE 9
  19. #define SZ_ERROR_PROGRESS 10
  20. #define SZ_ERROR_FAIL 11
  21. #define SZ_ERROR_THREAD 12
  22. #define SZ_ERROR_ARCHIVE 16
  23. #define SZ_ERROR_NO_ARCHIVE 17
  24. typedef int SRes;
  25. #ifdef _WIN32
  26. typedef DWORD WRes;
  27. #else
  28. typedef int WRes;
  29. #endif
  30. #ifndef RINOK
  31. #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
  32. #endif
  33. typedef unsigned char Byte;
  34. typedef short Int16;
  35. typedef unsigned short UInt16;
  36. #ifdef _LZMA_UINT32_IS_ULONG
  37. typedef long Int32;
  38. typedef unsigned long UInt32;
  39. #else
  40. typedef int Int32;
  41. typedef unsigned int UInt32;
  42. #endif
  43. #ifdef _SZ_NO_INT_64
  44. /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
  45. NOTES: Some code will work incorrectly in that case! */
  46. typedef long Int64;
  47. typedef unsigned long UInt64;
  48. #else
  49. #if defined(_MSC_VER) || defined(__BORLANDC__)
  50. typedef __int64 Int64;
  51. typedef unsigned __int64 UInt64;
  52. #else
  53. typedef long long int Int64;
  54. typedef unsigned long long int UInt64;
  55. #endif
  56. #endif
  57. #ifdef _LZMA_NO_SYSTEM_SIZE_T
  58. typedef UInt32 SizeT;
  59. #else
  60. typedef size_t SizeT;
  61. #endif
  62. typedef int Bool;
  63. #define True 1
  64. #define False 0
  65. #ifdef _MSC_VER
  66. #if _MSC_VER >= 1300
  67. #define MY_NO_INLINE __declspec(noinline)
  68. #else
  69. #define MY_NO_INLINE
  70. #endif
  71. #define MY_CDECL __cdecl
  72. #define MY_STD_CALL __stdcall
  73. #define MY_FAST_CALL MY_NO_INLINE __fastcall
  74. #else
  75. #define MY_CDECL
  76. #define MY_STD_CALL
  77. #define MY_FAST_CALL
  78. #endif
  79. /* The following interfaces use first parameter as pointer to structure */
  80. typedef struct
  81. {
  82. SRes (*Read)(void *p, void *buf, size_t *size);
  83. /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
  84. (output(*size) < input(*size)) is allowed */
  85. } ISeqInStream;
  86. /* it can return SZ_ERROR_INPUT_EOF */
  87. SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
  88. SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
  89. SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
  90. typedef struct
  91. {
  92. size_t (*Write)(void *p, const void *buf, size_t size);
  93. /* Returns: result - the number of actually written bytes.
  94. (result < size) means error */
  95. } ISeqOutStream;
  96. typedef enum
  97. {
  98. SZ_SEEK_SET = 0,
  99. SZ_SEEK_CUR = 1,
  100. SZ_SEEK_END = 2
  101. } ESzSeek;
  102. typedef struct
  103. {
  104. SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
  105. SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
  106. } ISeekInStream;
  107. typedef struct
  108. {
  109. SRes (*Look)(void *p, void **buf, size_t *size);
  110. /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
  111. (output(*size) > input(*size)) is not allowed
  112. (output(*size) < input(*size)) is allowed */
  113. SRes (*Skip)(void *p, size_t offset);
  114. /* offset must be <= output(*size) of Look */
  115. SRes (*Read)(void *p, void *buf, size_t *size);
  116. /* reads directly (without buffer). It's same as ISeqInStream::Read */
  117. SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
  118. } ILookInStream;
  119. SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
  120. SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
  121. /* reads via ILookInStream::Read */
  122. SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
  123. SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
  124. #define LookToRead_BUF_SIZE (1 << 14)
  125. typedef struct
  126. {
  127. ILookInStream s;
  128. ISeekInStream *realStream;
  129. size_t pos;
  130. size_t size;
  131. Byte buf[LookToRead_BUF_SIZE];
  132. } CLookToRead;
  133. void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
  134. void LookToRead_Init(CLookToRead *p);
  135. typedef struct
  136. {
  137. ISeqInStream s;
  138. ILookInStream *realStream;
  139. } CSecToLook;
  140. void SecToLook_CreateVTable(CSecToLook *p);
  141. typedef struct
  142. {
  143. ISeqInStream s;
  144. ILookInStream *realStream;
  145. } CSecToRead;
  146. void SecToRead_CreateVTable(CSecToRead *p);
  147. typedef struct
  148. {
  149. SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
  150. /* Returns: result. (result != SZ_OK) means break.
  151. Value (UInt64)(Int64)-1 for size means unknown value. */
  152. } ICompressProgress;
  153. typedef struct
  154. {
  155. void *(*Alloc)(void *p, size_t size);
  156. void (*Free)(void *p, void *address); /* address can be 0 */
  157. } ISzAlloc;
  158. #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
  159. #define IAlloc_Free(p, a) (p)->Free((p), a)
  160. #endif