Blame examples/portab.h

Packit Service 5195f2
/* portab.h -- portability layer
Packit Service 5195f2
Packit Service 5195f2
   This file is part of the LZO real-time data compression library.
Packit Service 5195f2
Packit Service 5195f2
   Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer
Packit Service 5195f2
   All Rights Reserved.
Packit Service 5195f2
Packit Service 5195f2
   The LZO library is free software; you can redistribute it and/or
Packit Service 5195f2
   modify it under the terms of the GNU General Public License as
Packit Service 5195f2
   published by the Free Software Foundation; either version 2 of
Packit Service 5195f2
   the License, or (at your option) any later version.
Packit Service 5195f2
Packit Service 5195f2
   The LZO library is distributed in the hope that it will be useful,
Packit Service 5195f2
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 5195f2
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 5195f2
   GNU General Public License for more details.
Packit Service 5195f2
Packit Service 5195f2
   You should have received a copy of the GNU General Public License
Packit Service 5195f2
   along with the LZO library; see the file COPYING.
Packit Service 5195f2
   If not, write to the Free Software Foundation, Inc.,
Packit Service 5195f2
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit Service 5195f2
Packit Service 5195f2
   Markus F.X.J. Oberhumer
Packit Service 5195f2
   <markus@oberhumer.com>
Packit Service 5195f2
   http://www.oberhumer.com/opensource/lzo/
Packit Service 5195f2
 */
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
#include "lzo/lzoconf.h"
Packit Service 5195f2
Packit Service 5195f2
#if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200))
Packit Service 5195f2
   /* avoid '-W4' warnings in system header files */
Packit Service 5195f2
#  pragma warning(disable: 4201 4214 4514)
Packit Service 5195f2
#endif
Packit Service 5195f2
#if (LZO_CC_MSC && (_MSC_VER >= 1300))
Packit Service 5195f2
   /* avoid '-Wall' warnings in system header files */
Packit Service 5195f2
#  pragma warning(disable: 4163 4255 4820)
Packit Service 5195f2
   /* avoid warnings about inlining */
Packit Service 5195f2
#  pragma warning(disable: 4710 4711)
Packit Service 5195f2
#endif
Packit Service 5195f2
/* disable silly warnings about using "deprecated" POSIX functions like "fopen" */
Packit Service 5195f2
#if (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1100))
Packit Service 5195f2
#  pragma warning(disable: 1786)
Packit Service 5195f2
#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1000))
Packit Service 5195f2
#  pragma warning(disable: 1478)
Packit Service 5195f2
#elif (LZO_CC_MSC && (_MSC_VER >= 1400))
Packit Service 5195f2
#  pragma warning(disable: 4996)
Packit Service 5195f2
#endif
Packit Service 5195f2
#if (LZO_CC_PELLESC && (__POCC__ >= 290))
Packit Service 5195f2
#  pragma warn(disable:2002)
Packit Service 5195f2
#endif
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
/*************************************************************************
Packit Service 5195f2
//
Packit Service 5195f2
**************************************************************************/
Packit Service 5195f2
Packit Service 5195f2
#if defined(LZO_WANT_ACCLIB_GETOPT) || !(defined(LZO_LIBC_ISOC90) || defined(LZO_LIBC_ISOC99))
Packit Service 5195f2
Packit Service 5195f2
#include "examples/portab_a.h"
Packit Service 5195f2
Packit Service 5195f2
#else
Packit Service 5195f2
Packit Service 5195f2
/* On any halfway modern machine we can use the following pure ANSI-C code. */
Packit Service 5195f2
Packit Service 5195f2
#include <stddef.h>
Packit Service 5195f2
#include <stdlib.h>
Packit Service 5195f2
#include <stdio.h>
Packit Service 5195f2
#include <string.h>
Packit Service 5195f2
#include <ctype.h>
Packit Service 5195f2
#include <time.h>
Packit Service 5195f2
#if defined(CLK_TCK) && !defined(CLOCKS_PER_SEC)
Packit Service 5195f2
#  define CLOCKS_PER_SEC CLK_TCK
Packit Service 5195f2
#endif
Packit Service 5195f2
Packit Service 5195f2
#if defined(WANT_LZO_MALLOC)
Packit Service 5195f2
#  define lzo_malloc(a)         (malloc(a))
Packit Service 5195f2
#  define lzo_free(a)           (free(a))
Packit Service 5195f2
#endif
Packit Service 5195f2
#if defined(WANT_LZO_FREAD)
Packit Service 5195f2
#  define lzo_fread(f,b,s)      (fread(b,1,s,f))
Packit Service 5195f2
#  define lzo_fwrite(f,b,s)     (fwrite(b,1,s,f))
Packit Service 5195f2
#endif
Packit Service 5195f2
#if defined(WANT_LZO_PCLOCK)
Packit Service 5195f2
#  define lzo_pclock_handle_t   int
Packit Service 5195f2
#  define lzo_pclock_t          double
Packit Service 5195f2
#  define lzo_pclock_open_default(a) ((void)(a))
Packit Service 5195f2
#  define lzo_pclock_close(a)   ((void)(a))
Packit Service 5195f2
#  define lzo_pclock_read(a,b)  *(b) = (clock() / (double)(CLOCKS_PER_SEC))
Packit Service 5195f2
#  define lzo_pclock_get_elapsed(a,b,c) (*(c) - *(b))
Packit Service 5195f2
#  define lzo_pclock_flush_cpu_cache(a,b)  ((void)(a))
Packit Service 5195f2
#endif
Packit Service 5195f2
#if defined(WANT_LZO_WILDARGV)
Packit Service 5195f2
#  define lzo_wildargv(a,b)     ((void)0)
Packit Service 5195f2
#endif
Packit Service 5195f2
Packit Service 5195f2
#endif
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
/*************************************************************************
Packit Service 5195f2
// misc
Packit Service 5195f2
**************************************************************************/
Packit Service 5195f2
Packit Service 5195f2
/* turn on assertions */
Packit Service 5195f2
#undef NDEBUG
Packit Service 5195f2
#include <assert.h>
Packit Service 5195f2
Packit Service 5195f2
/* just in case */
Packit Service 5195f2
#undef xmalloc
Packit Service 5195f2
#undef xfree
Packit Service 5195f2
#undef xread
Packit Service 5195f2
#undef xwrite
Packit Service 5195f2
#undef xputc
Packit Service 5195f2
#undef xgetc
Packit Service 5195f2
#undef xread32
Packit Service 5195f2
#undef xwrite32
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
#if defined(WANT_XMALLOC)
Packit Service 5195f2
static lzo_voidp xmalloc(lzo_uint len)
Packit Service 5195f2
{
Packit Service 5195f2
    lzo_voidp p;
Packit Service 5195f2
    lzo_uint align = (lzo_uint) sizeof(lzo_align_t);
Packit Service 5195f2
Packit Service 5195f2
    p = (lzo_voidp) lzo_malloc(len > 0 ? len : 1);
Packit Service 5195f2
    if (p == NULL)
Packit Service 5195f2
    {
Packit Service 5195f2
        printf("%s: out of memory\n", progname);
Packit Service 5195f2
        exit(1);
Packit Service 5195f2
    }
Packit Service 5195f2
    if (len >= align && __lzo_align_gap(p, align) != 0)
Packit Service 5195f2
    {
Packit Service 5195f2
        printf("%s: C library problem: malloc() returned misaligned pointer!\n", progname);
Packit Service 5195f2
        exit(1);
Packit Service 5195f2
    }
Packit Service 5195f2
    return p;
Packit Service 5195f2
}
Packit Service 5195f2
#endif
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
/* vim:set ts=4 sw=4 et: */