"Fossies" - the Fresh Open Source Software Archive

Member "UXP-2019.06.08/other-licenses/7zstub/src/C/7zTypes.h" (8 Jun 2019, 9179 Bytes) of package /linux/www/UXP-2019.06.08.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* 7zTypes.h -- Basic types
    2 2017-07-17 : Igor Pavlov : Public domain */
    3 
    4 #ifndef __7Z_TYPES_H
    5 #define __7Z_TYPES_H
    6 
    7 #ifdef _WIN32
    8 /* #include <windows.h> */
    9 #endif
   10 
   11 #include <stddef.h>
   12 
   13 #ifndef EXTERN_C_BEGIN
   14 #ifdef __cplusplus
   15 #define EXTERN_C_BEGIN extern "C" {
   16 #define EXTERN_C_END }
   17 #else
   18 #define EXTERN_C_BEGIN
   19 #define EXTERN_C_END
   20 #endif
   21 #endif
   22 
   23 EXTERN_C_BEGIN
   24 
   25 #define SZ_OK 0
   26 
   27 #define SZ_ERROR_DATA 1
   28 #define SZ_ERROR_MEM 2
   29 #define SZ_ERROR_CRC 3
   30 #define SZ_ERROR_UNSUPPORTED 4
   31 #define SZ_ERROR_PARAM 5
   32 #define SZ_ERROR_INPUT_EOF 6
   33 #define SZ_ERROR_OUTPUT_EOF 7
   34 #define SZ_ERROR_READ 8
   35 #define SZ_ERROR_WRITE 9
   36 #define SZ_ERROR_PROGRESS 10
   37 #define SZ_ERROR_FAIL 11
   38 #define SZ_ERROR_THREAD 12
   39 
   40 #define SZ_ERROR_ARCHIVE 16
   41 #define SZ_ERROR_NO_ARCHIVE 17
   42 
   43 typedef int SRes;
   44 
   45 
   46 #ifdef _WIN32
   47 
   48 /* typedef DWORD WRes; */
   49 typedef unsigned WRes;
   50 #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
   51 
   52 #else
   53 
   54 typedef int WRes;
   55 #define MY__FACILITY_WIN32 7
   56 #define MY__FACILITY__WRes MY__FACILITY_WIN32
   57 #define MY_SRes_HRESULT_FROM_WRes(x) ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (MY__FACILITY__WRes << 16) | 0x80000000)))
   58 
   59 #endif
   60 
   61 
   62 #ifndef RINOK
   63 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
   64 #endif
   65 
   66 typedef unsigned char Byte;
   67 typedef short Int16;
   68 typedef unsigned short UInt16;
   69 
   70 #ifdef _LZMA_UINT32_IS_ULONG
   71 typedef long Int32;
   72 typedef unsigned long UInt32;
   73 #else
   74 typedef int Int32;
   75 typedef unsigned int UInt32;
   76 #endif
   77 
   78 #ifdef _SZ_NO_INT_64
   79 
   80 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
   81    NOTES: Some code will work incorrectly in that case! */
   82 
   83 typedef long Int64;
   84 typedef unsigned long UInt64;
   85 
   86 #else
   87 
   88 #if defined(_MSC_VER) || defined(__BORLANDC__)
   89 typedef __int64 Int64;
   90 typedef unsigned __int64 UInt64;
   91 #define UINT64_CONST(n) n
   92 #else
   93 typedef long long int Int64;
   94 typedef unsigned long long int UInt64;
   95 #define UINT64_CONST(n) n ## ULL
   96 #endif
   97 
   98 #endif
   99 
  100 #ifdef _LZMA_NO_SYSTEM_SIZE_T
  101 typedef UInt32 SizeT;
  102 #else
  103 typedef size_t SizeT;
  104 #endif
  105 
  106 typedef int Bool;
  107 #define True 1
  108 #define False 0
  109 
  110 
  111 #ifdef _WIN32
  112 #define MY_STD_CALL __stdcall
  113 #else
  114 #define MY_STD_CALL
  115 #endif
  116 
  117 #ifdef _MSC_VER
  118 
  119 #if _MSC_VER >= 1300
  120 #define MY_NO_INLINE __declspec(noinline)
  121 #else
  122 #define MY_NO_INLINE
  123 #endif
  124 
  125 #define MY_FORCE_INLINE __forceinline
  126 
  127 #define MY_CDECL __cdecl
  128 #define MY_FAST_CALL __fastcall
  129 
  130 #else
  131 
  132 #define MY_NO_INLINE
  133 #define MY_FORCE_INLINE
  134 #define MY_CDECL
  135 #define MY_FAST_CALL
  136 
  137 /* inline keyword : for C++ / C99 */
  138 
  139 /* GCC, clang: */
  140 /*
  141 #if defined (__GNUC__) && (__GNUC__ >= 4)
  142 #define MY_FORCE_INLINE __attribute__((always_inline))
  143 #define MY_NO_INLINE __attribute__((noinline))
  144 #endif
  145 */
  146 
  147 #endif
  148 
  149 
  150 /* The following interfaces use first parameter as pointer to structure */
  151 
  152 typedef struct IByteIn IByteIn;
  153 struct IByteIn
  154 {
  155   Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */
  156 };
  157 #define IByteIn_Read(p) (p)->Read(p)
  158 
  159 
  160 typedef struct IByteOut IByteOut;
  161 struct IByteOut
  162 {
  163   void (*Write)(const IByteOut *p, Byte b);
  164 };
  165 #define IByteOut_Write(p, b) (p)->Write(p, b)
  166 
  167 
  168 typedef struct ISeqInStream ISeqInStream;
  169 struct ISeqInStream
  170 {
  171   SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);
  172     /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
  173        (output(*size) < input(*size)) is allowed */
  174 };
  175 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
  176 
  177 /* it can return SZ_ERROR_INPUT_EOF */
  178 SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);
  179 SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);
  180 SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);
  181 
  182 
  183 typedef struct ISeqOutStream ISeqOutStream;
  184 struct ISeqOutStream
  185 {
  186   size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);
  187     /* Returns: result - the number of actually written bytes.
  188        (result < size) means error */
  189 };
  190 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
  191 
  192 typedef enum
  193 {
  194   SZ_SEEK_SET = 0,
  195   SZ_SEEK_CUR = 1,
  196   SZ_SEEK_END = 2
  197 } ESzSeek;
  198 
  199 
  200 typedef struct ISeekInStream ISeekInStream;
  201 struct ISeekInStream
  202 {
  203   SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
  204   SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);
  205 };
  206 #define ISeekInStream_Read(p, buf, size)   (p)->Read(p, buf, size)
  207 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
  208 
  209 
  210 typedef struct ILookInStream ILookInStream;
  211 struct ILookInStream
  212 {
  213   SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);
  214     /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
  215        (output(*size) > input(*size)) is not allowed
  216        (output(*size) < input(*size)) is allowed */
  217   SRes (*Skip)(const ILookInStream *p, size_t offset);
  218     /* offset must be <= output(*size) of Look */
  219 
  220   SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
  221     /* reads directly (without buffer). It's same as ISeqInStream::Read */
  222   SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);
  223 };
  224 
  225 #define ILookInStream_Look(p, buf, size)   (p)->Look(p, buf, size)
  226 #define ILookInStream_Skip(p, offset)      (p)->Skip(p, offset)
  227 #define ILookInStream_Read(p, buf, size)   (p)->Read(p, buf, size)
  228 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
  229 
  230 
  231 SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);
  232 SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);
  233 
  234 /* reads via ILookInStream::Read */
  235 SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);
  236 SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);
  237 
  238 
  239 
  240 typedef struct
  241 {
  242   ILookInStream vt;
  243   const ISeekInStream *realStream;
  244  
  245   size_t pos;
  246   size_t size; /* it's data size */
  247   
  248   /* the following variables must be set outside */
  249   Byte *buf;
  250   size_t bufSize;
  251 } CLookToRead2;
  252 
  253 void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
  254 
  255 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
  256 
  257 
  258 typedef struct
  259 {
  260   ISeqInStream vt;
  261   const ILookInStream *realStream;
  262 } CSecToLook;
  263 
  264 void SecToLook_CreateVTable(CSecToLook *p);
  265 
  266 
  267 
  268 typedef struct
  269 {
  270   ISeqInStream vt;
  271   const ILookInStream *realStream;
  272 } CSecToRead;
  273 
  274 void SecToRead_CreateVTable(CSecToRead *p);
  275 
  276 
  277 typedef struct ICompressProgress ICompressProgress;
  278 
  279 struct ICompressProgress
  280 {
  281   SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);
  282     /* Returns: result. (result != SZ_OK) means break.
  283        Value (UInt64)(Int64)-1 for size means unknown value. */
  284 };
  285 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
  286 
  287 
  288 
  289 typedef struct ISzAlloc ISzAlloc;
  290 typedef const ISzAlloc * ISzAllocPtr;
  291 
  292 struct ISzAlloc
  293 {
  294   void *(*Alloc)(ISzAllocPtr p, size_t size);
  295   void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
  296 };
  297 
  298 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
  299 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
  300 
  301 /* deprecated */
  302 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
  303 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
  304 
  305 
  306 
  307 
  308 
  309 #ifndef MY_offsetof
  310   #ifdef offsetof
  311     #define MY_offsetof(type, m) offsetof(type, m)
  312     /*
  313     #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
  314     */
  315   #else
  316     #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
  317   #endif
  318 #endif
  319 
  320 
  321 
  322 #ifndef MY_container_of
  323 
  324 /*
  325 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
  326 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
  327 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
  328 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
  329 */
  330 
  331 /*
  332   GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
  333     GCC 3.4.4 : classes with constructor
  334     GCC 4.8.1 : classes with non-public variable members"
  335 */
  336 
  337 #define MY_container_of(ptr, type, m) ((type *)((char *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
  338 
  339 
  340 #endif
  341 
  342 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(ptr))
  343 
  344 /*
  345 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
  346 */
  347 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
  348 
  349 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
  350 /*
  351 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
  352 */
  353 
  354 
  355 
  356 #ifdef _WIN32
  357 
  358 #define CHAR_PATH_SEPARATOR '\\'
  359 #define WCHAR_PATH_SEPARATOR L'\\'
  360 #define STRING_PATH_SEPARATOR "\\"
  361 #define WSTRING_PATH_SEPARATOR L"\\"
  362 
  363 #else
  364 
  365 #define CHAR_PATH_SEPARATOR '/'
  366 #define WCHAR_PATH_SEPARATOR L'/'
  367 #define STRING_PATH_SEPARATOR "/"
  368 #define WSTRING_PATH_SEPARATOR L"/"
  369 
  370 #endif
  371 
  372 EXTERN_C_END
  373 
  374 #endif