Types.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* Types.h -- Basic types
  2. 2010-10-09 : 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. #define UINT64_CONST(n) n
  53. #else
  54. typedef long long int Int64;
  55. typedef unsigned long long int UInt64;
  56. #define UINT64_CONST(n) n ## ULL
  57. #endif
  58. #endif
  59. #ifdef _LZMA_NO_SYSTEM_SIZE_T
  60. typedef UInt32 SizeT;
  61. #else
  62. typedef size_t SizeT;
  63. #endif
  64. typedef int Bool;
  65. #define True 1
  66. #define False 0
  67. #ifdef _MSC_VER
  68. #if _MSC_VER >= 1300
  69. #define MY_NO_INLINE __declspec(noinline)
  70. #else
  71. #define MY_NO_INLINE
  72. #endif
  73. #define MY_CDECL __cdecl
  74. #define MY_FAST_CALL __fastcall
  75. #else
  76. #define MY_CDECL
  77. #define MY_FAST_CALL
  78. #endif
  79. /* The following interfaces use first parameter as pointer to structure */
  80. typedef struct
  81. {
  82. Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
  83. } IByteIn;
  84. typedef struct
  85. {
  86. void (*Write)(void *p, Byte b);
  87. } IByteOut;
  88. typedef struct
  89. {
  90. SRes (*Read)(void *p, void *buf, size_t *size);
  91. /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
  92. (output(*size) < input(*size)) is allowed */
  93. } ISeqInStream;
  94. /* it can return SZ_ERROR_INPUT_EOF */
  95. SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
  96. SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
  97. SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
  98. typedef struct
  99. {
  100. size_t (*Write)(void *p, const void *buf, size_t size);
  101. /* Returns: result - the number of actually written bytes.
  102. (result < size) means error */
  103. } ISeqOutStream;
  104. typedef enum
  105. {
  106. SZ_SEEK_SET = 0,
  107. SZ_SEEK_CUR = 1,
  108. SZ_SEEK_END = 2
  109. } ESzSeek;
  110. typedef struct
  111. {
  112. SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
  113. SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
  114. } ISeekInStream;
  115. typedef struct
  116. {
  117. SRes (*Look)(void *p, const void **buf, size_t *size);
  118. /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
  119. (output(*size) > input(*size)) is not allowed
  120. (output(*size) < input(*size)) is allowed */
  121. SRes (*Skip)(void *p, size_t offset);
  122. /* offset must be <= output(*size) of Look */
  123. SRes (*Read)(void *p, void *buf, size_t *size);
  124. /* reads directly (without buffer). It's same as ISeqInStream::Read */
  125. SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
  126. } ILookInStream;
  127. SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
  128. SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
  129. /* reads via ILookInStream::Read */
  130. SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
  131. SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
  132. #define LookToRead_BUF_SIZE (1 << 14)
  133. typedef struct
  134. {
  135. ILookInStream s;
  136. ISeekInStream *realStream;
  137. size_t pos;
  138. size_t size;
  139. Byte buf[LookToRead_BUF_SIZE];
  140. } CLookToRead;
  141. void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
  142. void LookToRead_Init(CLookToRead *p);
  143. typedef struct
  144. {
  145. ISeqInStream s;
  146. ILookInStream *realStream;
  147. } CSecToLook;
  148. void SecToLook_CreateVTable(CSecToLook *p);
  149. typedef struct
  150. {
  151. ISeqInStream s;
  152. ILookInStream *realStream;
  153. } CSecToRead;
  154. void SecToRead_CreateVTable(CSecToRead *p);
  155. typedef struct
  156. {
  157. SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
  158. /* Returns: result. (result != SZ_OK) means break.
  159. Value (UInt64)(Int64)-1 for size means unknown value. */
  160. } ICompressProgress;
  161. typedef struct
  162. {
  163. void *(*Alloc)(void *p, size_t size);
  164. void (*Free)(void *p, void *address); /* address can be 0 */
  165. } ISzAlloc;
  166. #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
  167. #define IAlloc_Free(p, a) (p)->Free((p), a)
  168. #ifdef _WIN32
  169. #define CHAR_PATH_SEPARATOR '\\'
  170. #define WCHAR_PATH_SEPARATOR L'\\'
  171. #define STRING_PATH_SEPARATOR "\\"
  172. #define WSTRING_PATH_SEPARATOR L"\\"
  173. #else
  174. #define CHAR_PATH_SEPARATOR '/'
  175. #define WCHAR_PATH_SEPARATOR L'/'
  176. #define STRING_PATH_SEPARATOR "/"
  177. #define WSTRING_PATH_SEPARATOR L"/"
  178. #endif
  179. #endif