00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __TOOLS_H__
00022 #define __TOOLS_H__
00023
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include "global.h"
00027 #include "htdata.h"
00028
00029 #ifdef HAVE_CONFIG_H
00030 #include "config.h"
00031 #endif
00032
00033 #define MIN(a, b) ((a) < (b) ? (a) : (b))
00034 #define MAX(a, b) ((a) > (b) ? (a) : (b))
00035
00036 #ifdef NO_NATIVE_UNALIGNED_MOVES
00037 #define UNALIGNED_MOVE(a, b) memcpy(&(a), &(b), sizeof(a))
00038 #define UNALIGNED_MOVE_CONST(a, b, type) {assert(sizeof(a)==sizeof(type));type c = b;memcpy(&(a), &c, sizeof(a));}
00039 #else
00040 #define UNALIGNED_MOVE(a, b) (a) = (b)
00041 #define UNALIGNED_MOVE_CONST(a, b, type) (a) = (b)
00042 #endif
00043
00044 dword delinearize(dword d);
00045
00046 int compare_keys_int_delinear(Object *key_a, Object *key_b);
00047 int compare_keys_uint_delinear(Object *key_a, Object *key_b);
00048
00049 int *random_permutation(int max);
00050
00051 double calc_entropy(byte *buf, int size);
00052 int calc_entropy2(byte *buf, int size);
00053
00054 #define OUT_OF_MEMORY_FAIL 0
00055 #define OUT_OF_MEMORY_IGNORE 1
00056 #define OUT_OF_MEMORY_RETRY 2
00057 extern int (*out_of_memory_func)(int size);
00058 int out_of_memory(int size);
00059
00060
00061 void *smalloc(size_t size);
00062 void *smalloc0(size_t size);
00063
00064 #endif