1 //<MStar Software> 2 //****************************************************************************** 3 // MStar Software 4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved. 5 // All software, firmware and related documentation herein ("MStar Software") are 6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by 7 // law, including, but not limited to, copyright law and international treaties. 8 // Any use, modification, reproduction, retransmission, or republication of all 9 // or part of MStar Software is expressly prohibited, unless prior written 10 // permission has been granted by MStar. 11 // 12 // By accessing, browsing and/or using MStar Software, you acknowledge that you 13 // have read, understood, and agree, to be bound by below terms ("Terms") and to 14 // comply with all applicable laws and regulations: 15 // 16 // 1. MStar shall retain any and all right, ownership and interest to MStar 17 // Software and any modification/derivatives thereof. 18 // No right, ownership, or interest to MStar Software and any 19 // modification/derivatives thereof is transferred to you under Terms. 20 // 21 // 2. You understand that MStar Software might include, incorporate or be 22 // supplied together with third party`s software and the use of MStar 23 // Software may require additional licenses from third parties. 24 // Therefore, you hereby agree it is your sole responsibility to separately 25 // obtain any and all third party right and license necessary for your use of 26 // such third party`s software. 27 // 28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as 29 // MStar`s confidential information and you agree to keep MStar`s 30 // confidential information in strictest confidence and not disclose to any 31 // third party. 32 // 33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any 34 // kind. Any warranties are hereby expressly disclaimed by MStar, including 35 // without limitation, any warranties of merchantability, non-infringement of 36 // intellectual property rights, fitness for a particular purpose, error free 37 // and in conformity with any international standard. You agree to waive any 38 // claim against MStar for any loss, damage, cost or expense that you may 39 // incur related to your use of MStar Software. 40 // In no event shall MStar be liable for any direct, indirect, incidental or 41 // consequential damages, including without limitation, lost of profit or 42 // revenues, lost or damage of data, and unauthorized system use. 43 // You agree that this Section 4 shall still apply without being affected 44 // even if MStar Software has been modified by MStar in accordance with your 45 // request or instruction for your use, except otherwise agreed by both 46 // parties in writing. 47 // 48 // 5. If requested, MStar may from time to time provide technical supports or 49 // services in relation with MStar Software to you for your use of 50 // MStar Software in conjunction with your or your customer`s product 51 // ("Services"). 52 // You understand and agree that, except otherwise agreed by both parties in 53 // writing, Services are provided on an "AS IS" basis and the warranty 54 // disclaimer set forth in Section 4 above shall apply. 55 // 56 // 6. Nothing contained herein shall be construed as by implication, estoppels 57 // or otherwise: 58 // (a) conferring any license or right to use MStar name, trademark, service 59 // mark, symbol or any other identification; 60 // (b) obligating MStar or any of its affiliates to furnish any person, 61 // including without limitation, you and your customers, any assistance 62 // of any kind whatsoever, or any information; or 63 // (c) conferring any license or right under any intellectual property right. 64 // 65 // 7. These terms shall be governed by and construed in accordance with the laws 66 // of Taiwan, R.O.C., excluding its conflict of law rules. 67 // Any and all dispute arising out hereof or related hereto shall be finally 68 // settled by arbitration referred to the Chinese Arbitration Association, 69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration 70 // Rules of the Association by three (3) arbitrators appointed in accordance 71 // with the said Rules. 72 // The place of arbitration shall be in Taipei, Taiwan and the language shall 73 // be English. 74 // The arbitration award shall be final and binding to both parties. 75 // 76 //****************************************************************************** 77 //<MStar Software> 78 /* zutil.h -- internal interface and configuration of the compression library 79 * Copyright (C) 1995-2005 Jean-loup Gailly. 80 * For conditions of distribution and use, see copyright notice in zlib.h 81 */ 82 83 /* WARNING: this file should *not* be used by applications. It is 84 part of the implementation of the compression library and is 85 subject to change. Applications should only use zlib.h. 86 */ 87 88 /* @(#) $Id$ */ 89 90 #ifndef ZUTIL_H 91 #define ZUTIL_H 92 93 #define ZLIB_INTERNAL 94 #include "zlib.h" 95 96 #ifdef STDC 97 # ifndef _WIN32_WCE 98 # include <stddef.h> 99 # endif 100 101 #ifdef MSOS_TYPE_LINUX_KERNEL 102 #include <linux/string.h> 103 #include <linux/time.h> 104 #else 105 #include <string.h> 106 #include <stdlib.h> 107 #endif 108 #endif 109 #ifdef NO_ERRNO_H 110 # ifdef _WIN32_WCE 111 /* The Microsoft C Run-Time Library for Windows CE doesn't have 112 * errno. We define it as a global variable to simplify porting. 113 * Its value is always 0 and should not be used. We rename it to 114 * avoid conflict with other libraries that use the same workaround. 115 */ 116 # define errno z_errno 117 # endif 118 extern MS_U32 errno; 119 #else 120 # ifndef _WIN32_WCE 121 #ifndef MSOS_TYPE_LINUX_KERNEL 122 # include <errno.h> 123 #endif 124 # endif 125 #endif 126 127 #ifndef local 128 # define local static 129 #endif 130 /* compile with -Dlocal if your debugger can't find static symbols */ 131 132 typedef MS_U8 uch; 133 typedef uch FAR uchf; 134 typedef MS_U16 ush; 135 typedef ush FAR ushf; 136 typedef MS_U32 ulg; 137 138 extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 139 /* (size given to avoid silly warnings with Visual C++) */ 140 141 #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 142 143 #define ERR_RETURN(strm,err) \ 144 return (strm->msg = (char*)ERR_MSG(err), (err)) 145 /* To be used only when the state is known to be valid */ 146 147 /* common constants */ 148 149 #ifndef DEF_WBITS 150 # define DEF_WBITS MAX_WBITS 151 #endif 152 /* default windowBits for decompression. MAX_WBITS is for compression only */ 153 154 #if MAX_MEM_LEVEL >= 8 155 # define DEF_MEM_LEVEL 8 156 #else 157 # define DEF_MEM_LEVEL MAX_MEM_LEVEL 158 #endif 159 /* default memLevel */ 160 161 #define STORED_BLOCK 0 162 #define STATIC_TREES 1 163 #define DYN_TREES 2 164 /* The three kinds of block type */ 165 166 #define MIN_MATCH 3 167 #define MAX_MATCH 258 168 /* The minimum and maximum match lengths */ 169 170 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 171 172 /* target dependencies */ 173 174 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 175 # define OS_CODE 0x00 176 # if defined(__TURBOC__) || defined(__BORLANDC__) 177 # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 178 /* Allow compilation with ANSI keywords only enabled */ 179 void _Cdecl farfree( void *block ); 180 void *_Cdecl farmalloc( MS_U32 nbytes ); 181 # else 182 # include <alloc.h> 183 # endif 184 # else /* MSC or DJGPP */ 185 # include <malloc.h> 186 # endif 187 #endif 188 189 #ifdef AMIGA 190 # define OS_CODE 0x01 191 #endif 192 193 #if defined(VAXC) || defined(VMS) 194 # define OS_CODE 0x02 195 # define F_OPEN(name, mode) \ 196 fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 197 #endif 198 199 #if defined(ATARI) || defined(atarist) 200 # define OS_CODE 0x05 201 #endif 202 203 #ifdef OS2 204 # define OS_CODE 0x06 205 # ifdef M_I86 206 #include <malloc.h> 207 # endif 208 #endif 209 210 #if defined(MACOS) || defined(TARGET_OS_MAC) 211 # define OS_CODE 0x07 212 # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 213 # include <unix.h> /* for fdopen */ 214 # else 215 # ifndef fdopen 216 # define fdopen(fd,mode) NULL /* No fdopen() */ 217 # endif 218 # endif 219 #endif 220 221 #ifdef TOPS20 222 # define OS_CODE 0x0a 223 #endif 224 225 #ifdef WIN32 226 # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 227 # define OS_CODE 0x0b 228 # endif 229 #endif 230 231 #ifdef __50SERIES /* Prime/PRIMOS */ 232 # define OS_CODE 0x0f 233 #endif 234 235 #if defined(_BEOS_) || defined(RISCOS) 236 # define fdopen(fd,mode) NULL /* No fdopen() */ 237 #endif 238 239 #if (defined(_MSC_VER) && (_MSC_VER > 600)) 240 # if defined(_WIN32_WCE) 241 # define fdopen(fd,mode) NULL /* No fdopen() */ 242 # ifndef _PTRDIFF_T_DEFINED 243 typedef MS_U32 ptrdiff_t; 244 # define _PTRDIFF_T_DEFINED 245 # endif 246 # else 247 # define fdopen(fd,type) _fdopen(fd,type) 248 # endif 249 #endif 250 251 /* common defaults */ 252 253 #ifndef OS_CODE 254 # define OS_CODE 0x03 /* assume Unix */ 255 #endif 256 257 #ifndef F_OPEN 258 # define F_OPEN(name, mode) fopen((name), (mode)) 259 #endif 260 261 /* functions */ 262 263 #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 264 # ifndef HAVE_VSNPRINTF 265 # define HAVE_VSNPRINTF 266 # endif 267 #endif 268 #if defined(__CYGWIN__) 269 # ifndef HAVE_VSNPRINTF 270 # define HAVE_VSNPRINTF 271 # endif 272 #endif 273 #ifndef HAVE_VSNPRINTF 274 # ifdef MSDOS 275 /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 276 but for now we just assume it doesn't. */ 277 # define NO_vsnprintf 278 # endif 279 # ifdef __TURBOC__ 280 # define NO_vsnprintf 281 # endif 282 # ifdef WIN32 283 /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 284 # if !defined(vsnprintf) && !defined(NO_vsnprintf) 285 # define vsnprintf _vsnprintf 286 # endif 287 # endif 288 # ifdef __SASC 289 # define NO_vsnprintf 290 # endif 291 #endif 292 #ifdef VMS 293 # define NO_vsnprintf 294 #endif 295 296 #if defined(pyr) 297 # define NO_MEMCPY 298 #endif 299 #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 300 /* Use our own functions for small and medium model with MSC <= 5.0. 301 * You may have to use the same strategy for Borland C (untested). 302 * The __SC__ check is for Symantec. 303 */ 304 # define NO_MEMCPY 305 #endif 306 #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 307 # define HAVE_MEMCPY 308 #endif 309 #ifdef HAVE_MEMCPY 310 # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 311 # define zmemcpy _fmemcpy 312 # define zmemcmp _fmemcmp 313 # define zmemzero(dest, len) _fmemset(dest, 0, len) 314 # else 315 # define zmemcpy memcpy 316 # define zmemcmp memcmp 317 # define zmemzero(dest, len) memset(dest, 0, len) 318 # endif 319 #else 320 extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 321 extern MS_U32 zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 322 extern void zmemzero OF((Bytef* dest, uInt len)); 323 #endif 324 325 /* Diagnostic functions */ 326 #ifdef DEBUG 327 # include <stdio.h> 328 extern MS_U32 z_verbose; 329 extern void z_error OF((char *m)); 330 # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 331 # define Trace(x) {if (z_verbose>=0) fprintf x ;} 332 # define Tracev(x) {if (z_verbose>0) fprintf x ;} 333 # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 334 # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 335 # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 336 #else 337 # define Assert(cond,msg) 338 # define Trace(x) 339 # define Tracev(x) 340 # define Tracevv(x) 341 # define Tracec(c,x) 342 # define Tracecv(c,x) 343 #endif 344 345 346 voidpf zcalloc OF((voidpf opaque, MS_U32 items, MS_U32 size)); 347 void zcfree OF((voidpf opaque, voidpf ptr)); 348 349 #define ZALLOC(strm, items, size) \ 350 (*((strm)->zalloc))((strm)->opaque, (items), (size)) 351 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 352 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 353 354 #endif /* ZUTIL_H */ 355