portab.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* portab.h -- portability layer
  2. This file is part of the LZO real-time data compression library.
  3. Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
  4. All Rights Reserved.
  5. The LZO library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. The LZO library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with the LZO library; see the file COPYING.
  15. If not, write to the Free Software Foundation, Inc.,
  16. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. Markus F.X.J. Oberhumer
  18. <markus@oberhumer.com>
  19. http://www.oberhumer.com/opensource/lzo/
  20. */
  21. #include <lzo/lzoconf.h>
  22. #if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200))
  23. /* avoid '-W4' warnings in system header files */
  24. # pragma warning(disable: 4201 4214 4514)
  25. #endif
  26. #if (LZO_CC_MSC && (_MSC_VER >= 1300))
  27. /* avoid '-Wall' warnings in system header files */
  28. # pragma warning(disable: 4163 4255 4820)
  29. /* avoid warnings about inlining */
  30. # pragma warning(disable: 4710 4711)
  31. #endif
  32. /* disable silly warnings about using "deprecated" POSIX functions like "fopen" */
  33. #if (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1100))
  34. # pragma warning(disable: 1786)
  35. #elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1000))
  36. # pragma warning(disable: 1478)
  37. #elif (LZO_CC_MSC && (_MSC_VER >= 1400))
  38. # pragma warning(disable: 4996)
  39. #endif
  40. #if (LZO_CC_PELLESC && (__POCC__ >= 290))
  41. # pragma warn(disable:2002)
  42. #endif
  43. /*************************************************************************
  44. //
  45. **************************************************************************/
  46. #if defined(LZO_WANT_ACCLIB_GETOPT) || !(defined(LZO_LIBC_ISOC90) || defined(LZO_LIBC_ISOC99))
  47. #include "examples/portab_a.h"
  48. #else
  49. /* On any halfway modern machine we can use the following pure ANSI-C code. */
  50. #include <stddef.h>
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <ctype.h>
  55. #include <time.h>
  56. #if defined(CLK_TCK) && !defined(CLOCKS_PER_SEC)
  57. # define CLOCKS_PER_SEC CLK_TCK
  58. #endif
  59. #if defined(WANT_LZO_MALLOC)
  60. # define lzo_malloc(a) (malloc(a))
  61. # define lzo_free(a) (free(a))
  62. #endif
  63. #if defined(WANT_LZO_FREAD)
  64. # define lzo_fread(f,b,s) (fread(b,1,s,f))
  65. # define lzo_fwrite(f,b,s) (fwrite(b,1,s,f))
  66. #endif
  67. #if defined(WANT_LZO_PCLOCK)
  68. # define lzo_pclock_handle_t int
  69. # define lzo_pclock_t double
  70. # define lzo_pclock_open_default(a) ((void)(a))
  71. # define lzo_pclock_close(a) ((void)(a))
  72. # define lzo_pclock_read(a,b) *(b) = (clock() / (double)(CLOCKS_PER_SEC))
  73. # define lzo_pclock_get_elapsed(a,b,c) (*(c) - *(b))
  74. # define lzo_pclock_flush_cpu_cache(a,b) ((void)(a))
  75. #endif
  76. #if defined(WANT_LZO_WILDARGV)
  77. # define lzo_wildargv(a,b) ((void)0)
  78. #endif
  79. #endif
  80. /*************************************************************************
  81. // misc
  82. **************************************************************************/
  83. /* turn on assertions */
  84. #undef NDEBUG
  85. #include <assert.h>
  86. /* just in case */
  87. #undef xmalloc
  88. #undef xfree
  89. #undef xread
  90. #undef xwrite
  91. #undef xputc
  92. #undef xgetc
  93. #undef xread32
  94. #undef xwrite32
  95. #if defined(WANT_XMALLOC)
  96. static lzo_voidp xmalloc(lzo_uint len)
  97. {
  98. lzo_voidp p;
  99. lzo_uint align = (lzo_uint) sizeof(lzo_align_t);
  100. p = (lzo_voidp) lzo_malloc(len > 0 ? len : 1);
  101. if (p == NULL)
  102. {
  103. printf("%s: out of memory\n", progname);
  104. exit(1);
  105. }
  106. if (len >= align && __lzo_align_gap(p, align) != 0)
  107. {
  108. printf("%s: C library problem: malloc() returned misaligned pointer!\n", progname);
  109. exit(1);
  110. }
  111. return p;
  112. }
  113. #endif
  114. /* vim:set ts=4 sw=4 et: */