13 #define MAX_LINE_WIDTH 128
15 void strlwr (char * str)
17 while (*str) {*str = tolower (*str); str++; }
20 int filelength (int fd)
23 if (fstat (fd, &buf) == -1)
29 unsigned long _beginthread (void (*pfuncStart)(void *), unsigned unStackSize, void* pArgList)
41 void OutputDebugString (const char *str)
43 fprintf(stderr, "OutputDebugString: %s\n", str);
51 int MulDiv(int a, int b, int c)
53 /* slow long long version */
54 __extension__ long long aa = a;
55 __extension__ long long bb = b;
56 __extension__ long long cc = c;
58 __extension__ long long dd = aa * bb;
59 __extension__ long long ee = dd / cc;
87 void vm_free(void* ptr, char *file, int line)
90 fprintf(stderr, "FREE: %s:%d addr = %p\n", file, line, ptr);
93 RAM **mark = &RamTable;
95 while (item != NULL) {
96 if (item->addr == ptr) {
107 mark = &(item->next);
112 fprintf(stderr, "ERROR: vm_free caught invalid free: addr = %p, file = %s/%d\n", ptr, file, line);
118 void *vm_malloc(int size, char *file, int line)
121 fprintf(stderr, "MALLOC: %s:%d %d bytes\n", file, line, size);
123 RAM *next = (RAM *)malloc(sizeof(RAM));
125 next->addr = malloc(size);
130 next->next = RamTable;
139 char *vm_strdup(char const* str, char *file, int line)
142 fprintf(stderr, "STRDUP: %s:%d\n", file, line);
144 RAM *next = (RAM *)malloc(sizeof(RAM));
146 next->addr = strdup(str);
147 next->size = strlen(str)+1;
151 next->next = RamTable;
154 return (char *)next->addr;
165 fprintf(stderr, "\nDumping allocated memory:\n");
169 fprintf(stderr, "%d: file: %s:%d: addr:%p size:%d\n", i, ptr->file, ptr->line, ptr->addr, ptr->size);
175 fprintf(stderr, "\nTotal of %d left-over bytes from %d allocations\n", mem, i);
179 void windebug_memwatch_init()
184 /* error message debugging junk */
185 int Log_debug_output_to_file = 0;
187 void load_filter_info(void)
192 void outwnd_printf(char* id, char* format, ...)
194 char tmp[MAX_LINE_WIDTH*4];
197 va_start (args, format);
198 vsprintf (tmp, format, args);
200 fprintf (stderr, "%s: %s\n", id, tmp);
203 void outwnd_printf2(char* format, ...)
205 char tmp[MAX_LINE_WIDTH*4];
208 va_start (args, format);
209 vsprintf (tmp, format, args);
211 fprintf (stderr, "General: %s", tmp);
219 void Warning( char * filename, int line, char * format, ... )
221 char tmp[MAX_LINE_WIDTH*4];
224 va_start (args, format);
225 vsprintf (tmp, format, args);
227 fprintf (stderr, "Warning: (%s:%d): %s\n", filename, line, tmp);
230 void Error( char * filename, int line, char * format, ... )
232 char tmp[MAX_LINE_WIDTH*4];
235 va_start (args, format);
236 vsprintf (tmp, format, args);
238 fprintf (stderr, "Error: (%s:%d): %s\n", filename, line, tmp);
242 void WinAssert(char * text,char *filename, int line)
244 fprintf (stderr, "Assertion: (%s:%d) %s\n", filename, line, text);