"Fossies" - the Fresh Open Source Software Archive

Member "hashcat-6.2.6/deps/LZMA-SDK/C/7zTypes.h" (2 Sep 2022, 13904 Bytes) of package /linux/privat/hashcat-6.2.6.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. See also the last Fossies "Diffs" side-by-side code changes report for "7zTypes.h": 6.2.1_vs_6.2.2.

    1 /* 7zTypes.h -- Basic types
    2 2021-04-25 : Igor Pavlov : Public domain */
    3 
    4 #ifndef __7Z_TYPES_H
    5 #define __7Z_TYPES_H
    6 
    7 #ifdef _WIN32
    8 /* #include <windows.h> */
    9 #else
   10 #include <errno.h>
   11 #endif
   12 
   13 #include <stddef.h>
   14 
   15 #ifndef EXTERN_C_BEGIN
   16 #ifdef __cplusplus
   17 #define EXTERN_C_BEGIN extern "C" {
   18 #define EXTERN_C_END }
   19 #else
   20 #define EXTERN_C_BEGIN
   21 #define EXTERN_C_END
   22 #endif
   23 #endif
   24 
   25 EXTERN_C_BEGIN
   26 
   27 #define SZ_OK 0
   28 
   29 #define SZ_ERROR_DATA 1
   30 #define SZ_ERROR_MEM 2
   31 #define SZ_ERROR_CRC 3
   32 #define SZ_ERROR_UNSUPPORTED 4
   33 #define SZ_ERROR_PARAM 5
   34 #define SZ_ERROR_INPUT_EOF 6
   35 #define SZ_ERROR_OUTPUT_EOF 7
   36 #define SZ_ERROR_READ 8
   37 #define SZ_ERROR_WRITE 9
   38 #define SZ_ERROR_PROGRESS 10
   39 #define SZ_ERROR_FAIL 11
   40 #define SZ_ERROR_THREAD 12
   41 
   42 #define SZ_ERROR_ARCHIVE 16
   43 #define SZ_ERROR_NO_ARCHIVE 17
   44 
   45 typedef int SRes;
   46 
   47 
   48 #ifdef _MSC_VER
   49   #if _MSC_VER > 1200
   50     #define MY_ALIGN(n) __declspec(align(n))
   51   #else
   52     #define MY_ALIGN(n)
   53   #endif
   54 #else
   55   #define MY_ALIGN(n) __attribute__ ((aligned(n)))
   56 #endif
   57 
   58 
   59 #ifdef _WIN32
   60 
   61 /* typedef DWORD WRes; */
   62 typedef unsigned WRes;
   63 #define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
   64 
   65 #else // _WIN32
   66 
   67 // #define ENV_HAVE_LSTAT
   68 typedef int WRes;
   69 
   70 // (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT
   71 #define MY__FACILITY_ERRNO  0x800
   72 #define MY__FACILITY_WIN32  7
   73 #define MY__FACILITY__WRes  MY__FACILITY_ERRNO
   74 
   75 #define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \
   76           ( (HRESULT)(x) & 0x0000FFFF) \
   77           | (MY__FACILITY__WRes << 16)  \
   78           | (HRESULT)0x80000000 ))
   79 
   80 #define MY_SRes_HRESULT_FROM_WRes(x) \
   81   ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : MY_HRESULT_FROM_errno_CONST_ERROR(x))
   82 
   83 // we call macro HRESULT_FROM_WIN32 for system errors (WRes) that are (errno)
   84 #define HRESULT_FROM_WIN32(x) MY_SRes_HRESULT_FROM_WRes(x)
   85 
   86 /*
   87 #define ERROR_FILE_NOT_FOUND             2L
   88 #define ERROR_ACCESS_DENIED              5L
   89 #define ERROR_NO_MORE_FILES              18L
   90 #define ERROR_LOCK_VIOLATION             33L
   91 #define ERROR_FILE_EXISTS                80L
   92 #define ERROR_DISK_FULL                  112L
   93 #define ERROR_NEGATIVE_SEEK              131L
   94 #define ERROR_ALREADY_EXISTS             183L
   95 #define ERROR_DIRECTORY                  267L
   96 #define ERROR_TOO_MANY_POSTS             298L
   97 
   98 #define ERROR_INVALID_REPARSE_DATA       4392L
   99 #define ERROR_REPARSE_TAG_INVALID        4393L
  100 #define ERROR_REPARSE_TAG_MISMATCH       4394L
  101 */
  102 
  103 // we use errno equivalents for some WIN32 errors:
  104 
  105 #define ERROR_INVALID_FUNCTION      EINVAL
  106 #define ERROR_ALREADY_EXISTS        EEXIST
  107 #define ERROR_FILE_EXISTS           EEXIST
  108 #define ERROR_PATH_NOT_FOUND        ENOENT
  109 #define ERROR_FILE_NOT_FOUND        ENOENT
  110 #define ERROR_DISK_FULL             ENOSPC
  111 // #define ERROR_INVALID_HANDLE        EBADF
  112 
  113 // we use FACILITY_WIN32 for errors that has no errno equivalent
  114 // Too many posts were made to a semaphore.
  115 #define ERROR_TOO_MANY_POSTS        ((HRESULT)0x8007012AL)
  116 #define ERROR_INVALID_REPARSE_DATA  ((HRESULT)0x80071128L)
  117 #define ERROR_REPARSE_TAG_INVALID   ((HRESULT)0x80071129L)
  118 
  119 // if (MY__FACILITY__WRes != FACILITY_WIN32),
  120 // we use FACILITY_WIN32 for COM errors:
  121 #define E_OUTOFMEMORY               ((HRESULT)0x8007000EL)
  122 #define E_INVALIDARG                ((HRESULT)0x80070057L)
  123 #define MY__E_ERROR_NEGATIVE_SEEK   ((HRESULT)0x80070083L)
  124 
  125 /*
  126 // we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:
  127 #define E_OUTOFMEMORY             MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM)
  128 #define E_INVALIDARG              MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
  129 #define MY__E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
  130 */
  131 
  132 // gcc / clang : (sizeof(long) == sizeof(void*)) in 32/64 bits
  133 typedef          long INT_PTR;
  134 typedef unsigned long UINT_PTR;
  135 
  136 #define TEXT(quote) quote
  137 
  138 #define FILE_ATTRIBUTE_READONLY       0x0001
  139 #define FILE_ATTRIBUTE_HIDDEN         0x0002
  140 #define FILE_ATTRIBUTE_SYSTEM         0x0004
  141 #define FILE_ATTRIBUTE_DIRECTORY      0x0010
  142 #define FILE_ATTRIBUTE_ARCHIVE        0x0020
  143 #define FILE_ATTRIBUTE_DEVICE         0x0040
  144 #define FILE_ATTRIBUTE_NORMAL         0x0080
  145 #define FILE_ATTRIBUTE_TEMPORARY      0x0100
  146 #define FILE_ATTRIBUTE_SPARSE_FILE    0x0200
  147 #define FILE_ATTRIBUTE_REPARSE_POINT  0x0400
  148 #define FILE_ATTRIBUTE_COMPRESSED     0x0800
  149 #define FILE_ATTRIBUTE_OFFLINE        0x1000
  150 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x2000
  151 #define FILE_ATTRIBUTE_ENCRYPTED      0x4000
  152 
  153 #define FILE_ATTRIBUTE_UNIX_EXTENSION 0x8000   /* trick for Unix */
  154 
  155 #endif
  156 
  157 
  158 #ifndef RINOK
  159 #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
  160 #endif
  161 
  162 #ifndef RINOK_WRes
  163 #define RINOK_WRes(x) { WRes __result__ = (x); if (__result__ != 0) return __result__; }
  164 #endif
  165 
  166 typedef unsigned char Byte;
  167 typedef short Int16;
  168 typedef unsigned short UInt16;
  169 
  170 #ifdef _LZMA_UINT32_IS_ULONG
  171 typedef long Int32;
  172 typedef unsigned long UInt32;
  173 #else
  174 typedef int Int32;
  175 typedef unsigned int UInt32;
  176 #endif
  177 
  178 
  179 #ifndef _WIN32
  180 
  181 typedef int INT;
  182 typedef Int32 INT32;
  183 typedef unsigned int UINT;
  184 typedef UInt32 UINT32;
  185 typedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit for _WIN32 compatibility
  186 typedef UINT32 ULONG;
  187 
  188 #undef DWORD
  189 typedef UINT32 DWORD;
  190 
  191 #define VOID void
  192 
  193 #define HRESULT LONG
  194 
  195 typedef void *LPVOID;
  196 // typedef void VOID;
  197 // typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
  198 // gcc / clang on Unix  : sizeof(long==sizeof(void*) in 32 or 64 bits)
  199 typedef          long  INT_PTR;
  200 typedef unsigned long  UINT_PTR;
  201 typedef          long  LONG_PTR;
  202 typedef unsigned long  DWORD_PTR;
  203 
  204 typedef size_t SIZE_T;
  205 
  206 #endif //  _WIN32
  207 
  208 
  209 
  210 #ifdef _SZ_NO_INT_64
  211 
  212 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
  213    NOTES: Some code will work incorrectly in that case! */
  214 
  215 typedef long Int64;
  216 typedef unsigned long UInt64;
  217 
  218 #else
  219 
  220 #if defined(_MSC_VER) || defined(__BORLANDC__)
  221 typedef __int64 Int64;
  222 typedef unsigned __int64 UInt64;
  223 #define UINT64_CONST(n) n
  224 #else
  225 typedef long long int Int64;
  226 typedef unsigned long long int UInt64;
  227 #define UINT64_CONST(n) n ## ULL
  228 #endif
  229 
  230 #endif
  231 
  232 #ifdef _LZMA_NO_SYSTEM_SIZE_T
  233 typedef UInt32 SizeT;
  234 #else
  235 typedef size_t SizeT;
  236 #endif
  237 
  238 typedef int BoolInt;
  239 /* typedef BoolInt Bool; */
  240 #define True 1
  241 #define False 0
  242 
  243 
  244 #ifdef _WIN32
  245 #define MY_STD_CALL __stdcall
  246 #else
  247 #define MY_STD_CALL
  248 #endif
  249 
  250 #ifdef _MSC_VER
  251 
  252 #if _MSC_VER >= 1300
  253 #define MY_NO_INLINE __declspec(noinline)
  254 #else
  255 #define MY_NO_INLINE
  256 #endif
  257 
  258 #define MY_FORCE_INLINE __forceinline
  259 
  260 #define MY_CDECL __cdecl
  261 #define MY_FAST_CALL __fastcall
  262 
  263 #else //  _MSC_VER
  264 
  265 #if (defined(__GNUC__) && (__GNUC__ >= 4)) \
  266     || (defined(__clang__) && (__clang_major__ >= 4)) \
  267     || defined(__INTEL_COMPILER) \
  268     || defined(__xlC__)
  269 #define MY_NO_INLINE __attribute__((noinline))
  270 // #define MY_FORCE_INLINE __attribute__((always_inline)) inline
  271 #else
  272 #define MY_NO_INLINE
  273 #endif
  274 
  275 #define MY_FORCE_INLINE
  276 
  277 
  278 #define MY_CDECL
  279 
  280 #if  defined(_M_IX86) \
  281   || defined(__i386__)
  282 // #define MY_FAST_CALL __attribute__((fastcall))
  283 // #define MY_FAST_CALL __attribute__((cdecl))
  284 #define MY_FAST_CALL
  285 #elif defined(MY_CPU_AMD64)
  286 // #define MY_FAST_CALL __attribute__((ms_abi))
  287 #define MY_FAST_CALL
  288 #else
  289 #define MY_FAST_CALL
  290 #endif
  291 
  292 #endif //  _MSC_VER
  293 
  294 
  295 /* The following interfaces use first parameter as pointer to structure */
  296 
  297 typedef struct IByteIn IByteIn;
  298 struct IByteIn
  299 {
  300   Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */
  301 };
  302 #define IByteIn_Read(p) (p)->Read(p)
  303 
  304 
  305 typedef struct IByteOut IByteOut;
  306 struct IByteOut
  307 {
  308   void (*Write)(const IByteOut *p, Byte b);
  309 };
  310 #define IByteOut_Write(p, b) (p)->Write(p, b)
  311 
  312 
  313 typedef struct ISeqInStream ISeqInStream;
  314 struct ISeqInStream
  315 {
  316   SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size);
  317     /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
  318        (output(*size) < input(*size)) is allowed */
  319 };
  320 #define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
  321 
  322 /* it can return SZ_ERROR_INPUT_EOF */
  323 SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size);
  324 SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType);
  325 SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf);
  326 
  327 
  328 typedef struct ISeqOutStream ISeqOutStream;
  329 struct ISeqOutStream
  330 {
  331   size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size);
  332     /* Returns: result - the number of actually written bytes.
  333        (result < size) means error */
  334 };
  335 #define ISeqOutStream_Write(p, buf, size) (p)->Write(p, buf, size)
  336 
  337 typedef enum
  338 {
  339   SZ_SEEK_SET = 0,
  340   SZ_SEEK_CUR = 1,
  341   SZ_SEEK_END = 2
  342 } ESzSeek;
  343 
  344 
  345 typedef struct ISeekInStream ISeekInStream;
  346 struct ISeekInStream
  347 {
  348   SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
  349   SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin);
  350 };
  351 #define ISeekInStream_Read(p, buf, size)   (p)->Read(p, buf, size)
  352 #define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
  353 
  354 
  355 typedef struct ILookInStream ILookInStream;
  356 struct ILookInStream
  357 {
  358   SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size);
  359     /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
  360        (output(*size) > input(*size)) is not allowed
  361        (output(*size) < input(*size)) is allowed */
  362   SRes (*Skip)(const ILookInStream *p, size_t offset);
  363     /* offset must be <= output(*size) of Look */
  364 
  365   SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
  366     /* reads directly (without buffer). It's same as ISeqInStream::Read */
  367   SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin);
  368 };
  369 
  370 #define ILookInStream_Look(p, buf, size)   (p)->Look(p, buf, size)
  371 #define ILookInStream_Skip(p, offset)      (p)->Skip(p, offset)
  372 #define ILookInStream_Read(p, buf, size)   (p)->Read(p, buf, size)
  373 #define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
  374 
  375 
  376 SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size);
  377 SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset);
  378 
  379 /* reads via ILookInStream::Read */
  380 SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType);
  381 SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size);
  382 
  383 
  384 
  385 typedef struct
  386 {
  387   ILookInStream vt;
  388   const ISeekInStream *realStream;
  389  
  390   size_t pos;
  391   size_t size; /* it's data size */
  392   
  393   /* the following variables must be set outside */
  394   Byte *buf;
  395   size_t bufSize;
  396 } CLookToRead2;
  397 
  398 void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
  399 
  400 #define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; }
  401 
  402 
  403 typedef struct
  404 {
  405   ISeqInStream vt;
  406   const ILookInStream *realStream;
  407 } CSecToLook;
  408 
  409 void SecToLook_CreateVTable(CSecToLook *p);
  410 
  411 
  412 
  413 typedef struct
  414 {
  415   ISeqInStream vt;
  416   const ILookInStream *realStream;
  417 } CSecToRead;
  418 
  419 void SecToRead_CreateVTable(CSecToRead *p);
  420 
  421 
  422 typedef struct ICompressProgress ICompressProgress;
  423 
  424 struct ICompressProgress
  425 {
  426   SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize);
  427     /* Returns: result. (result != SZ_OK) means break.
  428        Value (UInt64)(Int64)-1 for size means unknown value. */
  429 };
  430 #define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
  431 
  432 
  433 
  434 typedef struct ISzAlloc ISzAlloc;
  435 typedef const ISzAlloc * ISzAllocPtr;
  436 
  437 struct ISzAlloc
  438 {
  439   void *(*Alloc)(ISzAllocPtr p, size_t size);
  440   void (*Free)(ISzAllocPtr p, void *address); /* address can be 0 */
  441 };
  442 
  443 #define ISzAlloc_Alloc(p, size) (p)->Alloc(p, size)
  444 #define ISzAlloc_Free(p, a) (p)->Free(p, a)
  445 
  446 /* deprecated */
  447 #define IAlloc_Alloc(p, size) ISzAlloc_Alloc(p, size)
  448 #define IAlloc_Free(p, a) ISzAlloc_Free(p, a)
  449 
  450 
  451 
  452 
  453 
  454 #ifndef MY_offsetof
  455   #ifdef offsetof
  456     #define MY_offsetof(type, m) offsetof(type, m)
  457     /*
  458     #define MY_offsetof(type, m) FIELD_OFFSET(type, m)
  459     */
  460   #else
  461     #define MY_offsetof(type, m) ((size_t)&(((type *)0)->m))
  462   #endif
  463 #endif
  464 
  465 
  466 
  467 #ifndef MY_container_of
  468 
  469 /*
  470 #define MY_container_of(ptr, type, m) container_of(ptr, type, m)
  471 #define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
  472 #define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
  473 #define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
  474 */
  475 
  476 /*
  477   GCC shows warning: "perhaps the 'offsetof' macro was used incorrectly"
  478     GCC 3.4.4 : classes with constructor
  479     GCC 4.8.1 : classes with non-public variable members"
  480 */
  481 
  482 #define MY_container_of(ptr, type, m) ((type *)(void *)((char *)(void *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m)))
  483 
  484 #endif
  485 
  486 #define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr))
  487 
  488 /*
  489 #define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
  490 */
  491 #define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
  492 
  493 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
  494 /*
  495 #define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m)
  496 */
  497 
  498 
  499 #define MY_memset_0_ARRAY(a) memset((a), 0, sizeof(a))
  500 
  501 #ifdef _WIN32
  502 
  503 #define CHAR_PATH_SEPARATOR '\\'
  504 #define WCHAR_PATH_SEPARATOR L'\\'
  505 #define STRING_PATH_SEPARATOR "\\"
  506 #define WSTRING_PATH_SEPARATOR L"\\"
  507 
  508 #else
  509 
  510 #define CHAR_PATH_SEPARATOR '/'
  511 #define WCHAR_PATH_SEPARATOR L'/'
  512 #define STRING_PATH_SEPARATOR "/"
  513 #define WSTRING_PATH_SEPARATOR L"/"
  514 
  515 #endif
  516 
  517 EXTERN_C_END
  518 
  519 #endif