1/* portab.h -- portability layer 2 3 This file is part of the LZO real-time data compression library. 4 5 Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer 6 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer 7 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer 8 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer 9 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer 10 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer 11 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer 12 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer 13 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer 14 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer 15 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer 16 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer 17 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer 18 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer 19 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer 20 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer 21 All Rights Reserved. 22 23 The LZO library is free software; you can redistribute it and/or 24 modify it under the terms of the GNU General Public License as 25 published by the Free Software Foundation; either version 2 of 26 the License, or (at your option) any later version. 27 28 The LZO library is distributed in the hope that it will be useful, 29 but WITHOUT ANY WARRANTY; without even the implied warranty of 30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 31 GNU General Public License for more details. 32 33 You should have received a copy of the GNU General Public License 34 along with the LZO library; see the file COPYING. 35 If not, write to the Free Software Foundation, Inc., 36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 37 38 Markus F.X.J. Oberhumer 39 <markus@oberhumer.com> 40 http://www.oberhumer.com/opensource/lzo/ 41 */ 42 43 44#include "lzo/lzoconf.h" 45 46#if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200)) 47 /* avoid '-W4' warnings in system header files */ 48# pragma warning(disable: 4201 4214 4514) 49#endif 50#if (LZO_CC_MSC && (_MSC_VER >= 1300)) 51 /* avoid '-Wall' warnings in system header files */ 52# pragma warning(disable: 4163 4255 4820) 53 /* avoid warnings about inlining */ 54# pragma warning(disable: 4710 4711) 55#endif 56#if (LZO_CC_MSC && (_MSC_VER >= 1400)) 57 /* avoid warnings when using "deprecated" POSIX functions */ 58# pragma warning(disable: 4996) 59#endif 60#if (LZO_CC_PELLESC && (__POCC__ >= 290)) 61# pragma warn(disable:2002) 62#endif 63 64 65/************************************************************************* 66// 67**************************************************************************/ 68 69#if defined(__LZO_MMODEL_HUGE) || defined(ACC_WANT_ACCLIB_GETOPT) || !(defined(LZO_LIBC_ISOC90) || defined(LZO_LIBC_ISOC99)) 70 71#include "examples/portab_a.h" 72 73#else 74 75/* INFO: 76 * The "portab_a.h" version above uses the ACC library to add 77 * support for ancient systems (like 16-bit DOS) and to provide 78 * some gimmicks like Windows high-resolution timers. 79 * Still, on any halfway modern machine you can also use the 80 * following pure ANSI-C code instead. 81 */ 82 83#include <stddef.h> 84#include <stdlib.h> 85#include <stdio.h> 86#include <string.h> 87#include <ctype.h> 88#include <time.h> 89#if defined(CLK_TCK) && !defined(CLOCKS_PER_SEC) 90# define CLOCKS_PER_SEC CLK_TCK 91#endif 92 93#if defined(WANT_LZO_MALLOC) 94# define lzo_malloc(a) (malloc(a)) 95# define lzo_free(a) (free(a)) 96#endif 97#if defined(WANT_LZO_FREAD) 98# define lzo_fread(f,b,s) (fread(b,1,s,f)) 99# define lzo_fwrite(f,b,s) (fwrite(b,1,s,f)) 100#endif 101#if defined(WANT_LZO_UCLOCK) 102# define lzo_uclock_handle_t int 103# define lzo_uclock_t double 104# define lzo_uclock_open(a) ((void)(a)) 105# define lzo_uclock_close(a) ((void)(a)) 106# define lzo_uclock_read(a,b) *(b) = (clock() / (double)(CLOCKS_PER_SEC)) 107# define lzo_uclock_get_elapsed(a,b,c) (*(c) - *(b)) 108#endif 109#if defined(WANT_LZO_WILDARGV) 110# define lzo_wildargv(a,b) ((void)0) 111#endif 112 113#endif 114 115 116/************************************************************************* 117// misc 118**************************************************************************/ 119 120/* turn on assertions */ 121#undef NDEBUG 122#include <assert.h> 123 124/* just in case */ 125#undef xmalloc 126#undef xfree 127#undef xread 128#undef xwrite 129#undef xputc 130#undef xgetc 131#undef xread32 132#undef xwrite32 133 134 135#if defined(WANT_XMALLOC) 136static lzo_voidp xmalloc(lzo_uint len) 137{ 138 lzo_voidp p; 139 lzo_uint align = (lzo_uint) sizeof(lzo_align_t); 140 141 p = (lzo_voidp) lzo_malloc(len > 0 ? len : 1); 142 if (p == NULL) 143 { 144 printf("%s: out of memory\n", progname); 145 exit(1); 146 } 147 if (len >= align && __lzo_align_gap(p, align) != 0) 148 { 149 printf("%s: C library problem: malloc() returned misaligned pointer!\n", progname); 150 exit(1); 151 } 152 return p; 153} 154#endif 155 156 157#if defined(WANT_LZO_UCLOCK) 158 159/* High quality benchmarking. 160 * 161 * Flush the CPU cache to get more accurate benchmark values. 162 * This needs custom kernel patches. As a result - in combination with 163 * the perfctr Linux kernel patches - accurate high-quality benchmarking 164 * is possible. 165 * 166 * All other methods (rdtsc, QueryPerformanceCounter, gettimeofday, ...) 167 * are completely unreliable for our purposes, and the only other 168 * option is to boot into a legacy single-task operating system 169 * like plain MSDOS and to directly reprogram the hardware clock. 170 * [The djgpp2 port of the gcc compiler has support functions for this.] 171 * 172 * Also, for embedded systems it's best to benchmark by using a 173 * CPU emulator/simulator software that can exactly count all 174 * virtual clock ticks. 175 */ 176 177#if !defined(lzo_uclock_flush_cpu_cache) 178# define lzo_uclock_flush_cpu_cache(h,flags) ((void)(h)) 179#endif 180 181#endif 182 183 184/* 185vi:ts=4:et 186*/ 187 188