bes  Updated for version 3.20.6
memtrack.h
1 /*
2  * FILENAME: memtrack.h
3  *
4  * MEM.H -- ** Copyright (c) 1990, Cornerstone Systems Group, Inc.
5  * Dr. Dobbs Journal, August 1990, p. 180
6  *
7  * Modified significantly by Mark A. Ohrenschall, mao@ngdc.noaa.gov
8  *
9  * CAVEAT:
10  * No claims are made as to the suitability of the accompanying
11  * source code for any purpose. Although this source code has been
12  * used by the NOAA, no warranty, expressed or implied, is made by
13  * NOAA or the United States Government as to the accuracy and
14  * functioning of this source code, nor shall the fact of distribution
15  * constitute any such endorsement, and no responsibility is assumed
16  * by NOAA in connection therewith. The source code contained
17  * within was developed by an agency of the U.S. Government.
18  * NOAA's National Geophysical Data Center has no objection to the
19  * use of this source code for any purpose since it is not subject to
20  * copyright protection in the U.S. If this source code is incorporated
21  * into other software, a statement identifying this source code may be
22  * required under 17 U.S.C. 403 to appear with any copyright notice.
23  */
24 
25 
26 #ifndef MEMTRACK_H__
27 #define MEMTRACK_H__
28 
29 #ifndef FF_CC
30 #error "Are you including freeform.h? -- a compiler type must be set!"
31 #endif
32 
33 #define MEMTRACK_LOG "memtrack.log"
34 
35 #define MEMTRACK_OFF 0
36 #define MEMTRACK_BASIC 1
37 #define MEMTRACK_TRACE 2
38 #define MEMTRACK_ULTRA 3
39 
41 {
42 #ifndef MEMTRACK_B
43  char *tag;
44  char *routine;
45  char *file;
46  int line;
47 #endif
48 
49  long addr;
50  unsigned long size;
51  char state;
53 
54 typedef struct memtrack_log
55 {
56  FILE *file;
57  long pos;
58  FF_MEM_ENTRY_PTR entry;
60 
61 
62 #define NO_TAG "generic tag"
63 
64 #ifndef ROUTINE_NAME
65 #define ROUTINE_NAME "unfilled () name"
66 #endif
67 
68 #ifdef FIND_UNWRAPPED_MEM
69 #ifndef MEMTRACK
70 #define MEMTRACK MEMTRACK_ULTRA
71 #endif
72 
73 #define calloc I_should_be_memCalloc
74 #define free I_should_be_memFree
75 #define malloc I_should_be_memMalloc
76 #define realloc I_should_be_memRealloc
77 #define strdup I_should_be_memStrdup
78 
79 #if MEMTRACK == MEMTRACK_ULTRA
80 
81 #define strcpy I_should_be_memStrcpy
82 #define strncpy I_should_be_memStrncpy
83 #define strcat I_should_be_memStrcat
84 #define strncat I_should_be_memStrncat
85 #define strcmp I_should_be_memStrcmp
86 #define strncmp I_should_be_memStrncmp
87 #define strchr I_should_be_memStrchr
88 #define strrchr I_should_be_memStrrchr
89 #define strstr I_should_be_memStrstr
90 #define memcpy I_should_be_memMemcpy
91 #define memmove I_should_be_memMemmove
92 #define memset I_should_be_memMemset
93 
94 #endif /* MEMTRACK == MEMTRACK_ULTRA */
95 
96 #endif /* FIND_UNWRAPPED_MEM */
97 
98 #if MEMTRACK >= MEMTRACK_BASIC
99 
100 #ifdef MEMTRACK_B
101 
102 #define memCalloc(NOBJ, SIZE, TAG) MEMCalloc(NOBJ, SIZE)
103 #define memFree(P, TAG) MEMFree(P)
104 #define memMalloc(SIZE, TAG) MEMMalloc(SIZE)
105 #define memRealloc(P, SIZE, TAG) MEMRealloc(P, SIZE)
106 #define memStrdup(STRING, TAG) MEMStrdup(STRING)
107 #define memExit(STATUS, TAG) MEMExit(STATUS)
108 
109 void *MEMCalloc(size_t nobj, size_t size);
110 void MEMFree(void *p);
111 void *MEMMalloc(size_t size);
112 void *MEMRealloc(void *p, size_t size);
113 char *MEMStrdup(const char *string);
114 void MEMExit(int status);
115 
116 #else
117 
118 #define memCalloc(NOBJ, SIZE, TAG) MEMCalloc(NOBJ, SIZE, TAG, ROUTINE_NAME, __FILE__, __LINE__)
119 #define memFree(P, TAG) MEMFree(P, TAG, ROUTINE_NAME, __FILE__, __LINE__)
120 #define memMalloc(SIZE, TAG) MEMMalloc(SIZE, TAG, ROUTINE_NAME, __FILE__, __LINE__)
121 #define memRealloc(P, SIZE, TAG) MEMRealloc(P, SIZE, TAG, ROUTINE_NAME, __FILE__, __LINE__)
122 #define memStrdup(STRING, TAG) MEMStrdup(STRING, TAG, ROUTINE_NAME, __FILE__, __LINE__)
123 #define memExit(STATUS, TAG) MEMExit(STATUS, TAG, ROUTINE_NAME, __FILE__, __LINE__)
124 
125 void *MEMCalloc(size_t nobj, size_t size, char *tag, char *routine_name, char *cfile_name, int line_number);
126 void MEMFree(void *p, char *tag, char *routine_name, char *cfile_name, int line_number);
127 void *MEMMalloc(size_t size, char *tag, char *routine_name, char *cfile_name, int line_number);
128 void *MEMRealloc(void *p, size_t size, char *tag, char *routine_name, char *cfile_name, int line_number);
129 char *MEMStrdup(const char *string, char *tag, char *routine_name, char *cfile_name, int line_number);
130 void MEMExit(int status, char *tag, char *routine_name, char *cfile_name, int line_number);
131 
132 #endif /* (else) MEMTRACK_B */
133 
134 #else /* MEMTRACK >= MEMTRACK_BASIC */
135 
136 #define memCalloc(NOBJ, SIZE, TAG) calloc(NOBJ, SIZE)
137 
138 #ifdef MEMSAFREE
139 #define memFree(P, TAG) {free(P);P = NULL;}
140 #else
141 #define memFree(P, TAG) free(P)
142 #endif /* MEMSAFREE */
143 
144 #define memMalloc(SIZE, TAG) malloc(SIZE)
145 #define memRealloc(P, SIZE, TAG) realloc(P, SIZE)
146 #define memStrdup(STRING, TAG) os_strdup(STRING)
147 #define memExit(STATUS, TAG) exit(STATUS)
148 
149 #endif /* MEMTRACK >= MEMTRACK_BASIC */
150 
151 #if MEMTRACK >= MEMTRACK_TRACE
152 
153 #ifdef MEMTRACK_B
154 #define memTrace(TAG) MEMTrace()
155 void MEMTrace(void);
156 #else
157 #define memTrace(MSG) MEMTrace(MSG, ROUTINE_NAME, __FILE__, __LINE__);
158 void MEMTrace(char *msg, char *routine_name, char *cfile_name, int line_number);
159 #endif /* MEMTRACK_B */
160 
161 #else
162 #define memTrace(MSG) ;
163 #endif /* MEMTRACK >= MEMTRACK_TRACE */
164 
165 #if MEMTRACK == MEMTRACK_ULTRA
166 
167 #define memStrcpy(S, CT, TAG) MEMStrcpy(S, CT, TAG, ROUTINE_NAME, __FILE__, __LINE__)
168 #define memStrncpy(S, CT, N, TAG) MEMStrncpy(S, CT, N, TAG, ROUTINE_NAME, __FILE__, __LINE__)
169 #define memStrcat(S, CT, TAG) MEMStrcat(S, CT, TAG, ROUTINE_NAME, __FILE__, __LINE__)
170 #define memStrncat(S, CT, N, TAG) MEMStrncat(S, CT, N, TAG, ROUTINE_NAME, __FILE__, __LINE__)
171 #define memStrcmp(CS, CT, TAG) MEMStrcmp(CS, CT, TAG, ROUTINE_NAME, __FILE__, __LINE__)
172 #define memStrncmp(CS, CT, N, TAG) MEMStrncmp(CS, CT, N, TAG, ROUTINE_NAME, __FILE__, __LINE__)
173 #define memStrchr(CS, C, TAG) MEMStrchr(CS, C, TAG, ROUTINE_NAME, __FILE__, __LINE__)
174 #define memStrrchr(CS, C, TAG) MEMStrrchr(CS, C, TAG, ROUTINE_NAME, __FILE__, __LINE__)
175 #define memStrstr(CS, CT, TAG) MEMStrstr(CS, CT, TAG, ROUTINE_NAME, __FILE__, __LINE__)
176 #define memMemcpy(S, CT, N, TAG) MEMMemcpy(S, CT, N, TAG, ROUTINE_NAME, __FILE__, __LINE__)
177 #define memMemmove(S, CT, N, TAG) MEMMemmove(S, CT, N, TAG, ROUTINE_NAME, __FILE__, __LINE__)
178 #define memMemset(DEST, C, COUNT, TAG) MEMMemset(DEST, C, COUNT, TAG, ROUTINE_NAME, __FILE__, __LINE__)
179 
180 #ifdef MEMTRACK_B
181 char *MEMStrcpy(char *s, const char *ct);
182 char *MEMStrncpy(char *s, const char *ct, size_t n);
183 char *MEMStrcat(char *s, const char *ct);
184 char *MEMStrncat(char *s, const char *ct, size_t n);
185 int MEMStrcmp(const char *cs, const char *ct);
186 int MEMStrncmp(const char *cs, const char *ct, size_t n);
187 char *MEMStrchr(const char *cs, int c);
188 char *MEMStrrchr(const char *cs, int c);
189 char *MEMStrstr(const char *cs, const char *ct);
190 void *MEMMemset(void *dest, int c, unsigned int count);
191 
192 #if FF_CC == FF_CC_MSVC1 || FF_CC == FF_CC_MSVC4 || FF_CC == FF_CC_MACCW
193 
194 void *MEMMemcpy(void *s, const void *ct, size_t n);
195 void *MEMMemmove(void *s, const void *ct, size_t n);
196 
197 #endif
198 
199 #if FF_CC == FF_CC_UNIX
200 
201 char *MEMMemcpy(char *s, const char *ct, size_t n);
202 char *MEMMemmove(char *s, const char *ct, size_t n);
203 
204 #endif
205 
206 #else
207 char *MEMStrcpy(char *s, const char *ct, char *tag, char *routine_name, char *cfile_name, int line_number);
208 char *MEMStrncpy(char *s, const char *ct, size_t n, char *tag, char *routine_name, char *cfile_name, int line_number);
209 char *MEMStrcat(char *s, const char *ct, char *tag, char *routine_name, char *cfile_name, int line_number);
210 char *MEMStrncat(char *s, const char *ct, size_t n, char *tag, char *routine_name, char *cfile_name, int line_number);
211 int MEMStrcmp(const char *cs, const char *ct, char *tag, char *routine_name, char *cfile_name, int line_number);
212 int MEMStrncmp(const char *cs, const char *ct, size_t n, char *tag, char *routine_name, char *cfile_name, int line_number);
213 char *MEMStrchr(const char *cs, int c, char *tag, char *routine_name, char *cfile_name, int line_number);
214 char *MEMStrrchr(const char *cs, int c, char *tag, char *routine_name, char *cfile_name, int line_number);
215 char *MEMStrstr(const char *cs, const char *ct, char *tag, char *routine_name, char *cfile_name, int line_number);
216 void *MEMMemset(void *dest, int c, unsigned int count, char *tag, char *routine_name, char *cfile_name, int line_number);
217 
218 #if FF_CC == FF_CC_MSVC1 || FF_CC == FF_CC_MSVC4 || FF_CC == FF_CC_MACCW
219 
220 void *MEMMemcpy(void *s, const void *ct, size_t n, char *tag, char *routine_name, char *cfile_name, int line_number);
221 void *MEMMemmove(void *s, const void *ct, size_t n, char *tag, char *routine_name, char *cfile_name, int line_number);
222 
223 #endif
224 
225 #if FF_CC == FF_CC_UNIX
226 
227 char *MEMMemcpy(char *s, const char *ct, size_t n, char *tag, char *routine_name, char *cfile_name, int line_number);
228 char *MEMMemmove(char *s, const char *ct, size_t n, char *tag, char *routine_name, char *cfile_name, int line_number);
229 
230 #endif
231 
232 #endif /* MEMTRACK_B */
233 
234 #else /* MEMTRACK == MEMTRACK_ULTRA */
235 
236 #define memStrcpy(S, CT, TAG) strcpy(S, CT)
237 #define memStrncpy(S, CT, N, TAG) strncpy(S, CT, N)
238 #define memStrcat(S, CT, TAG) strcat(S, CT)
239 #define memStrncat(S, CT, N, TAG) strncat(S, CT, N)
240 #define memStrcmp(CS, CT, TAG) strcmp(CS, CT)
241 #define memStrncmp(CS, CT, N, TAG) strncmp(CS, CT, N)
242 #define memStrchr(CS, C, TAG) strchr(CS, C)
243 #define memStrrchr(CS, C, TAG) strrchr(CS, C)
244 #define memStrstr(CS, CT, TAG) strstr(CS, CT)
245 #define memMemcpy(S, CT, N, TAG) memcpy(S, CT, N)
246 #define memMemmove(S, CT, N, TAG) memmove(S, CT, N)
247 #define memMemset(DEST,C,COUNT,TAG) memset(DEST,C,COUNT)
248 
249 #endif /* (#else) MEMTRACK == MEMTRACK_ULTRA */
250 
251 #endif /* (NOT) MEMTRACK_H__ */
252 
memtrack_entry_struct_t
Definition: memtrack.h:40
memtrack_log
Definition: memtrack.h:54