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