00001 #ifndef _DYLIB_STD_H
00002 #define _DYLIB_STD_H
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
00029
00030 #include <stddef.h>
00031 #include <stdlib.h>
00032
00033 #include "DylpConfig.h"
00034
00035
00036
00037
00038
00039
00040 #ifndef UNUSED
00041 # if defined(_GNU_SOURCE) || defined(__GNUC__)
00042 # define UNUSED __attribute__((unused))
00043 # else
00044 # define UNUSED
00045 # endif
00046 #endif
00047
00048
00049
00050
00051
00052 #include <string.h>
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #ifndef __cplusplus
00064 #define FALSE 0
00065 #define TRUE 1
00066 # ifdef BOOL
00067 typedef BOOL bool ;
00068 # else
00069
00070
00071
00072
00073
00074
00075
00076 # warning The compile-time symbol BOOL is not defined (dylib_std.h)
00077 typedef int bool ;
00078 # endif
00079 #endif
00080
00081 #ifdef __cplusplus
00082 #ifndef FALSE
00083 # define FALSE false
00084 #endif
00085 #ifndef TRUE
00086 # define TRUE true
00087 #endif
00088 #endif
00089
00090
00091
00092
00093
00094
00095 typedef unsigned int flags ;
00096
00097 #define setflg(zz_flgs,zz_flg) ((zz_flgs) |= (zz_flg))
00098 #define clrflg(zz_flgs,zz_flg) ((zz_flgs) &= ~(zz_flg))
00099 #define comflg(zz_flgs,zz_flg) ((zz_flgs) ^= (zz_flg))
00100 #define getflg(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg))
00101 #define flgon(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg)?TRUE:FALSE)
00102 #define flgoff(zz_flgs,zz_flg) ((zz_flgs)&(zz_flg)?FALSE:TRUE)
00103 #define flgall(zz_flgs,zz_flg) ((((zz_flgs)&(zz_flg)) == (zz_flg))?TRUE:FALSE)
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 typedef struct lnk_struct_tag
00116 { struct lnk_struct_tag *llnxt ;
00117 void *llval ; } lnk_struct ;
00118
00119 #define lnk_in(qqlnk,qqval) ((qqlnk)->llval = (void *) (qqval))
00120 #define lnk_out(qqlnk,qqtype) ((qqtype) (qqlnk)->llval)
00121
00122
00123
00124
00125 #define minn(qa,qb) (((qa) > (qb))?(qb):(qa))
00126 #define maxx(qa,qb) (((qa) > (qb))?(qa):(qb))
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 #if (MALLOC_DEBUG == 2)
00146
00147 #include "dylib_io.h"
00148
00149 void *zz_ptr_zz ;
00150 ioid zz_chn_zz ;
00151
00152 #define MALLOC_DBG_INIT(chn) ( zz_chn_zz = chn )
00153
00154 #define MALLOC(zz_sze_zz) \
00155 ( zz_ptr_zz = (void *) malloc(zz_sze_zz), \
00156 dyio_outfmt(zz_chn_zz,FALSE,":malloc: %d bytes at %#08x in %s.\n", \
00157 zz_sze_zz,zz_ptr_zz,rtnnme), \
00158 zz_ptr_zz )
00159
00160 #define CALLOC(zz_cnt_zz,zz_sze_zz) \
00161 ( zz_ptr_zz = (void *) calloc(zz_cnt_zz,zz_sze_zz), \
00162 dyio_outfmt(zz_chn_zz,FALSE,":calloc: %d (%d*%d) bytes at %#08x in %s.\n", \
00163 zz_cnt_zz*zz_sze_zz,zz_cnt_zz,zz_sze_zz,zz_ptr_zz,rtnnme), \
00164 zz_ptr_zz )
00165
00166 #define REALLOC(zz_rptr_zz,zz_sze_zz) \
00167 ( zz_ptr_zz = (void *) realloc(zz_rptr_zz,zz_sze_zz), \
00168 dyio_outfmt(zz_chn_zz,FALSE, \
00169 ":realloc: %#08x changed to %d bytes at %#08x in %s.\n", \
00170 zz_rptr_zz,zz_sze_zz,zz_ptr_zz,rtnnme), \
00171 zz_ptr_zz )
00172
00173 #define FREE(zz_fptr_zz) \
00174 ( dyio_outfmt(zz_chn_zz,FALSE,":free: %#08x in %s.\n",zz_fptr_zz,rtnnme), \
00175 free((void *) zz_fptr_zz) )
00176
00177 #elif (MALLOC_DEBUG == 1)
00178
00179 #include <stdio.h>
00180 void *zz_ptr_zz ;
00181
00182 #define MALLOC(zz_sze_zz) \
00183 ( zz_ptr_zz = (void *) malloc(zz_sze_zz), \
00184 (zz_ptr_zz != 0)?0:\
00185 fprintf(stderr,":malloc: failed to get %d bytes at %s:%d.\n", \
00186 zz_sze_zz,__FILE__,__LINE__), \
00187 zz_ptr_zz )
00188
00189 #define CALLOC(zz_cnt_zz,zz_sze_zz) \
00190 ( zz_ptr_zz = (void *) calloc(zz_cnt_zz,zz_sze_zz), \
00191 (zz_ptr_zz != 0)?0:\
00192 fprintf(stderr,":calloc: failed to get %d bytes at %s:%d.\n", \
00193 zz_sze_zz*zz_cnt_zz,__FILE__,__LINE__), \
00194 zz_ptr_zz )
00195
00196 #define REALLOC(zz_rptr_zz,zz_sze_zz) \
00197 ( zz_ptr_zz = (void *) realloc(zz_rptr_zz,zz_sze_zz), \
00198 (zz_ptr_zz != 0)?0:\
00199 fprintf(stderr,":realloc: failed to get %d bytes at %s:%d.\n", \
00200 zz_sze_zz,__FILE__,__LINE__), \
00201 zz_ptr_zz )
00202
00203 #define FREE(zz_fptr_zz) free((void *) zz_fptr_zz)
00204
00205 #else
00206
00207 #define MALLOC_DBG_INIT(chn)
00208
00209 #define MALLOC(zz_sze_zz) malloc(zz_sze_zz)
00210
00211 #define CALLOC(zz_cnt_zz,zz_sze_zz) calloc(zz_cnt_zz,zz_sze_zz)
00212
00213 #define REALLOC(zz_rptr_zz,zz_sze_zz) realloc(zz_rptr_zz,zz_sze_zz)
00214
00215 #define FREE(zz_fptr_zz) free((void *) zz_fptr_zz)
00216
00217 #endif
00218
00219
00220 #endif