00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _MLO_UTILS_H_
00029 #define _MLO_UTILS_H_
00030
00031
00032
00033
00034 #include "MloConfig.h"
00035 #include "MloTypes.h"
00036
00037 #if defined(MLO_CONFIG_HAVE_STDLIB_H)
00038 #include <stdlib.h>
00039 #endif
00040
00041 #if defined(MLO_CONFIG_HAVE_STRING_H)
00042 #include <string.h>
00043 #endif
00044
00045 #if defined (MLO_CONFIG_HAVE_LIMITS_H)
00046 #include <limits.h>
00047 #endif
00048
00049 #if defined(DMALLOC)
00050 #include <dmalloc.h>
00051 #endif
00052
00053
00054
00055
00056 #define MLO_ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
00057
00058 #if ! defined (MLO_CONFIG_HAVE_LIMITS_H) && ! defined (CHAR_BIT)
00059 #define CHAR_BIT (8)
00060 #endif
00061 #define MLO_BIT_DEPTH(x) (sizeof (x) * CHAR_BIT)
00062 #define MLO_MAX_VAL_U(x) ((1L << MLO_BIT_DEPTH (x)) - 1)
00063 #define MLO_MAX_VAL_S(x) ((1L << (MLO_BIT_DEPTH (x) - 1)) - 1)
00064 #define MLO_MIN_VAL_S(x) (-1L << (MLO_BIT_DEPTH (x) - 1))
00065
00066 #define MLO_ABS(x) (((x) < 0) ? (-(x)) : (x))
00067 #define MLO_SIGN(x) (((x) < 0) ? -1 : 1)
00068 #define MLO_MAX(x,a) (((x) < (a)) ? (a) : (x))
00069 #define MLO_MIN(x,a) (((a) < (x)) ? (a) : (x))
00070 #define MLO_BOUND(x,a,b) (MLO_MAX (MLO_MIN ((x), (b)), (a)))
00071
00072
00073
00074
00075 #ifdef __cplusplus
00076 extern "C" {
00077 #endif
00078
00079 extern void MLO_BytesFromInt32Be(unsigned char* buffer, unsigned long value);
00080 extern void MLO_BytesFromInt16Be(unsigned char* buffer, unsigned short value);
00081 extern unsigned long MLO_BytesToInt32Be(const unsigned char* buffer);
00082 extern unsigned short MLO_BytesToInt16Be(const unsigned char* buffer);
00083
00084 extern void MLO_BytesFromInt32Le(unsigned char* buffer, unsigned long value);
00085 extern void MLO_BytesFromInt16Le(unsigned char* buffer, unsigned short value);
00086 extern unsigned long MLO_BytesToInt32Le(const unsigned char* buffer);
00087 extern unsigned short MLO_BytesToInt16Le(const unsigned char* buffer);
00088
00089
00090
00091
00092 #if defined(MLO_CONFIG_HAVE_MALLOC)
00093 #define MLO_AllocateMemory malloc
00094 #else
00095 extern void* MLO_AllocateMemory(unsigned int);
00096 #endif
00097
00098 #if defined(MLO_CONFIG_HAVE_CALLOC)
00099 #define MLO_AllocateZeroMemory(x) calloc(1,(x))
00100 #else
00101 extern void* MLO_AllocateZeroMemory(unsigned int);
00102 #endif
00103
00104 #if defined(MLO_CONFIG_HAVE_FREE)
00105 #define MLO_FreeMemory free
00106 #else
00107 extern void MLO_FreeMemory(void* pointer);
00108 #endif
00109
00110 #if defined(MLO_CONFIG_HAVE_MEMCPY)
00111 #define MLO_CopyMemory memcpy
00112 #else
00113 extern void MLO_CopyMemory(void* dest, const void* src, MLO_Size size);
00114 #endif
00115
00116 #if defined(MLO_CONFIG_HAVE_MEMMOVE)
00117 #define MLO_MoveMemory memmove
00118 #else
00119 extern void MLO_MoveMemory(void* dest, const void* src, MLO_Size size);
00120 #endif
00121
00122 #if defined(MLO_CONFIG_HAVE_MEMSET)
00123 #define MLO_SetMemory memset
00124 #else
00125 extern void MLO_SetMemory(void* dest, int c, MLO_Size size);
00126 #endif
00127
00128 #ifdef __cplusplus
00129 }
00130 #endif
00131
00132 #endif