various platform-specific cleanups

git-svn: trunk@3452
remotes/push_mirror/metadata
Tomasz Kojm 18 years ago
parent 615a77ac58
commit 1266e3e098
  1. 4
      ChangeLog
  2. 61
      libclamav/cltypes.h
  3. 104
      libclamav/others.h
  4. 4
      libclamunrar_iface/unrar_iface.c

@ -1,3 +1,7 @@
Sat Dec 22 00:10:53 CET 2007 (tk)
---------------------------------
* libclamav: various platform-specific cleanups
Fri Dec 21 10:39:22 GMT 2007 (njh)
----------------------------------
* libclamav/vba_extract.c: More tidies

@ -25,42 +25,43 @@
#include "clamav-config.h"
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#elif defined HAVE_SYS_INT_TYPES_H /*solaris*/
#ifdef HAVE_SYS_INT_TYPES_H
/* First to give it higher priority on Solaris */
#include <sys/int_types.h>
#elif defined HAVE_INTTYPES_H /*freebsd*/
#elif defined(HAVE_INTTYPES_H)
/* C99: inttypes.h should include stdint.h; more universal because some
* older platforms don't provide stdint.h
*/
#include <inttypes.h>
#elif defined(HAVE_STDINT_H)
#include <stdint.h>
#else
typedef unsigned char uint8_t; typedef signed char int8_t;
# if SIZEOF_INT == 2
typedef unsigned int uint16_t; typedef signed int int16_t;
# elif SIZEOF_SHORT == 2
typedef unsigned short uint16_t; typedef signed short int16_t;
# else
# error unable to typedef int16_t from either int or short
typedef unsigned short uint16_t; typedef signed short int16_t;
# endif
typedef signed char int8_t;
typedef unsigned char uint8_t;
# if SIZEOF_INT == 4
typedef unsigned int uint32_t; typedef signed int int32_t;
# elif SIZEOF_LONG == 4
typedef unsigned long uint32_t; typedef signed long int32_t;
# else
# error unable to typedef int32_t from either int or long
typedef unsigned long uint32_t; typedef signed long int32_t;
# endif
#if SIZEOF_INT == 2
typedef signed int int16_t;
typedef unsigned int uint16_t;
#elif SIZEOF_SHORT == 2
typedef signed short int16_t;
typedef unsigned short uint16_t;
#endif
# if SIZEOF_LONG == 8
typedef unsigned long uint64_t; typedef signed long int64_t;
# elif SIZEOF_LONG_LONG == 8
typedef unsigned long long uint64_t; typedef signed long long int64_t;
# else
# error unable to typedef int64_t from either long or long long
typedef unsigned long long uint64_t; typedef signed long long int64_t;
# endif
#if SIZEOF_INT == 4
typedef signed int int32_t;
typedef unsigned int uint32_t;
#elif SIZEOF_LONG == 4
typedef signed long int32_t;
typedef unsigned long uint32_t;
#endif
#if SIZEOF_LONG == 8
typedef signed long int64_t;
typedef unsigned long uint64_t;
#elif SIZEOF_LONG_LONG == 8
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
#endif
#endif
#endif

@ -99,35 +99,65 @@ typedef struct {
#define BLOCKMAX (ctx->options & CL_SCAN_BLOCKMAX)
#define DETECT_BROKEN (ctx->options & CL_SCAN_BLOCKBROKEN)
/* based on macros from A. Melnikoff */
#define cbswap16(v) (((v & 0xff) << 8) | (((v) >> 8) & 0xff))
#define cbswap32(v) ((((v) & 0x000000ff) << 24) | (((v) & 0x0000ff00) << 8) | \
(((v) & 0x00ff0000) >> 8) | (((v) & 0xff000000) >> 24))
#define cbswap64(v) ((((x) & 0x00000000000000ff) << 56) | \
(((x) & 0x000000000000ff00) << 40) | \
(((v) & 0x0000000000ff0000) << 24) | \
(((v) & 0x00000000ff000000) << 8) | \
(((v) & 0x000000ff00000000) >> 8) | \
(((v) & 0x0000ff0000000000) >> 24) | \
(((v) & 0x00ff000000000000) >> 40) | \
(((v) & 0xff00000000000000) >> 56))
#if WORDS_BIGENDIAN == 0
/* new macros from A. Melnikoff */
/* Little endian */
#define le16_to_host(v) (v)
#define le32_to_host(v) (v)
#define le64_to_host(v) (v)
#define be16_to_host(v) ((v >> 8) | ((v & 0xFF) << 8))
#define be32_to_host(v) ((v >> 24) | ((v & 0x00FF0000) >> 8) | \
((v & 0x0000FF00) << 8) | (v << 24))
#define be64_to_host(v) ((v >> 56) | ((v & 0x00FF000000000000LL) >> 40) | \
((v & 0x0000FF0000000000LL) >> 24) | \
((v & 0x000000FF00000000LL) >> 8) | \
((v & 0x00000000FF000000LL) << 8) | \
((v & 0x0000000000FF0000LL) << 24) | \
((v & 0x000000000000FF00LL) << 40) | \
(v << 56))
#define be16_to_host(v) cbswap16(v)
#define be32_to_host(v) cbswap32(v)
#define be64_to_host(v) cbswap64(v)
#define cli_readint32(buff) (*(const int32_t *)(buff))
#define cli_readint16(buff) (*(const int16_t *)(buff))
#define cli_writeint32(offset, value) (*(uint32_t *)(offset)=(uint32_t)(value))
#else
#define le16_to_host(v) ((v >> 8) | ((v & 0xFF) << 8))
#define le32_to_host(v) ((v >> 24) | ((v & 0x00FF0000) >> 8) | \
((v & 0x0000FF00) << 8) | (v << 24))
#define le64_to_host(v) ((v >> 56) | ((v & 0x00FF000000000000LL) >> 40) | \
((v & 0x0000FF0000000000LL) >> 24) | \
((v & 0x000000FF00000000LL) >> 8) | \
((v & 0x00000000FF000000LL) << 8) | \
((v & 0x0000000000FF0000LL) << 24) | \
((v & 0x000000000000FF00LL) << 40) | \
(v << 56))
/* Big endian */
#define le16_to_host(v) cbswap16(v)
#define le32_to_host(v) cbswap32(v)
#define le64_to_host(v) cbswap64(v)
#define be16_to_host(v) (v)
#define be32_to_host(v) (v)
#define be64_to_host(v) (v)
static inline int32_t cli_readint32(const char *buff)
{
int32_t ret;
ret = buff[0] & 0xff;
ret |= (buff[1] & 0xff) << 8;
ret |= (buff[2] & 0xff) << 16;
ret |= (buff[3] & 0xff) << 24;
return ret;
}
static inline int16_t cli_readint32(const char *buff)
{
int16_t ret;
ret = buff[0] & 0xff;
ret |= (buff[1] & 0xff) << 8;
return ret;
}
static inline void cli_writeint32(char *offset, uint32_t value)
{
offset[0] = value & 0xff;
offset[1] = (value & 0xff00) >> 8;
offset[2] = (value & 0xff0000) >> 16;
offset[3] = (value & 0xff000000) >> 24;
}
#endif
/* used by: spin, yc (C) aCaB */
@ -201,36 +231,4 @@ void cli_bitset_free(bitset_t *bs);
int cli_bitset_set(bitset_t *bs, unsigned long bit_offset);
int cli_bitset_test(bitset_t *bs, unsigned long bit_offset);
#if WORDS_BIGENDIAN == 0
#define cli_readint32(buff) (*(const int32_t *)(buff))
#define cli_readint16(buff) (*(const int16_t *)(buff))
#define cli_writeint32(offset, value) (*(uint32_t *)(offset)=(uint32_t)(value))
#else
static inline int32_t cli_readint32(const char *buff)
{
int32_t ret;
ret = buff[0] & 0xff;
ret |= (buff[1] & 0xff) << 8;
ret |= (buff[2] & 0xff) << 16;
ret |= (buff[3] & 0xff) << 24;
return ret;
}
static inline int16_t cli_readint32(const char *buff)
{
int16_t ret;
ret = buff[0] & 0xff;
ret |= (buff[1] & 0xff) << 8;
return ret;
}
static inline void cli_writeint32(char *offset, uint32_t value)
{
offset[0] = value & 0xff;
offset[1] = (value & 0xff00) >> 8;
offset[2] = (value & 0xff0000) >> 16;
offset[3] = (value & 0xff000000) >> 24;
}
#endif /* WORDS_BIGENDIAN == 0 */
#endif

@ -399,8 +399,8 @@ int unrar_extract_next_prepare(unrar_state_t *state, const char *dirname)
if(!new_metadata)
return UNRAR_EMEM;
new_metadata->pack_size = state->file_header->high_pack_size * 0x100000000 + state->file_header->pack_size;
new_metadata->unpack_size = state->file_header->high_unpack_size * 0x100000000 + state->file_header->unpack_size;
new_metadata->pack_size = state->file_header->high_pack_size * 0x100000000ULL + state->file_header->pack_size;
new_metadata->unpack_size = state->file_header->high_unpack_size * 0x100000000ULL + state->file_header->unpack_size;
new_metadata->crc = state->file_header->file_crc;
new_metadata->method = state->file_header->method;
new_metadata->filename = strdup(state->file_header->filename);

Loading…
Cancel
Save