diff options
Diffstat (limited to 'C/Types.h')
-rwxr-xr-x | C/Types.h | 94 |
1 files changed, 86 insertions, 8 deletions
@@ -1,11 +1,15 @@ /* Types.h -- Basic types -2008-08-05 -Igor Pavlov -Public domain */ +2008-11-23 : Igor Pavlov : Public domain */ #ifndef __7Z_TYPES_H #define __7Z_TYPES_H +#include <stddef.h> + +#ifdef _WIN32 +#include <windows.h> +#endif + #define SZ_OK 0 #define SZ_ERROR_DATA 1 @@ -26,6 +30,12 @@ Public domain */ typedef int SRes; +#ifdef _WIN32 +typedef DWORD WRes; +#else +typedef int WRes; +#endif + #ifndef RINOK #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } #endif @@ -42,11 +52,11 @@ typedef int Int32; typedef unsigned int UInt32; #endif -/* #define _SZ_NO_INT_64 */ -/* define it if your compiler doesn't support 64-bit integers */ - #ifdef _SZ_NO_INT_64 +/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. + NOTES: Some code will work incorrectly in that case! */ + typedef long Int64; typedef unsigned long UInt64; @@ -65,7 +75,6 @@ typedef unsigned long long int UInt64; #ifdef _LZMA_NO_SYSTEM_SIZE_T typedef UInt32 SizeT; #else -#include <stddef.h> typedef size_t SizeT; #endif @@ -104,13 +113,82 @@ typedef struct (output(*size) < input(*size)) is allowed */ } ISeqInStream; +/* it can return SZ_ERROR_INPUT_EOF */ +SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); +SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); +SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); + typedef struct { size_t (*Write)(void *p, const void *buf, size_t size); /* Returns: result - the number of actually written bytes. - (result < size) means error */ + (result < size) means error */ } ISeqOutStream; +typedef enum +{ + SZ_SEEK_SET = 0, + SZ_SEEK_CUR = 1, + SZ_SEEK_END = 2 +} ESzSeek; + +typedef struct +{ + SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ + SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); +} ISeekInStream; + +typedef struct +{ + SRes (*Look)(void *p, void **buf, size_t *size); + /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. + (output(*size) > input(*size)) is not allowed + (output(*size) < input(*size)) is allowed */ + SRes (*Skip)(void *p, size_t offset); + /* offset must be <= output(*size) of Look */ + + SRes (*Read)(void *p, void *buf, size_t *size); + /* reads directly (without buffer). It's same as ISeqInStream::Read */ + SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); +} ILookInStream; + +SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); +SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); + +/* reads via ILookInStream::Read */ +SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); +SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); + +#define LookToRead_BUF_SIZE (1 << 14) + +typedef struct +{ + ILookInStream s; + ISeekInStream *realStream; + size_t pos; + size_t size; + Byte buf[LookToRead_BUF_SIZE]; +} CLookToRead; + +void LookToRead_CreateVTable(CLookToRead *p, int lookahead); +void LookToRead_Init(CLookToRead *p); + +typedef struct +{ + ISeqInStream s; + ILookInStream *realStream; +} CSecToLook; + +void SecToLook_CreateVTable(CSecToLook *p); + +typedef struct +{ + ISeqInStream s; + ILookInStream *realStream; +} CSecToRead; + +void SecToRead_CreateVTable(CSecToRead *p); + typedef struct { SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); |