13 // use system versions of this stuff in here rather than the vm_* versions
19 #define MAX_LINE_WIDTH 128
21 void strlwr (char * str)
23 while (*str) {*str = tolower (*str); str++; }
26 void strupr (char * str)
28 while (*str) {*str = toupper (*str); str++; }
31 int filelength (int fd)
34 if (fstat (fd, &buf) == -1)
40 unsigned long _beginthread (void (*pfuncStart)(void *), unsigned unStackSize, void* pArgList)
49 SDL_Delay( long(mili) );
52 void OutputDebugString (const char *str)
54 fprintf(stderr, "OutputDebugString: %s\n", str);
62 void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
67 /* fs2 only uses fname */
69 const char *ls = strrchr(path, '/');
71 ls++; // move past '/'
76 const char *lp = strrchr(path, '.');
78 lp = ls + strlen(ls); // move to the end
82 if (dist > (_MAX_FNAME-1))
85 strncpy(fname, ls, dist);
86 fname[dist] = 0; // add null, just in case
90 int MulDiv(int a, int b, int c)
92 /* slow long long version */
93 __extension__ long long aa = a;
94 __extension__ long long bb = b;
95 __extension__ long long cc = c;
97 __extension__ long long dd = aa * bb;
98 __extension__ long long ee = dd / cc;
123 static RAM *RamTable;
127 void vm_free(void* ptr, char *file, int line)
129 void vm_free(void* ptr)
133 fprintf(stderr, "FREE: %s:%d addr = %p\n", file, line, ptr);
135 RAM *item = RamTable;
136 RAM **mark = &RamTable;
138 while (item != NULL) {
139 if (item->addr == ptr) {
150 mark = &(item->next);
155 fprintf(stderr, "ERROR: vm_free caught invalid free: addr = %p, file = %s/%d\n", ptr, file, line);
162 void *vm_malloc(int size, char *file, int line)
164 void *vm_malloc(int size)
168 fprintf(stderr, "MALLOC: %s:%d %d bytes\n", file, line, size);
170 RAM *next = (RAM *)malloc(sizeof(RAM));
172 next->addr = malloc(size);
177 next->next = RamTable;
187 char *vm_strdup(char const* str, char *file, int line)
189 char *vm_strdup(char const* str)
193 fprintf(stderr, "STRDUP: %s:%d\n", file, line);
195 RAM *next = (RAM *)malloc(sizeof(RAM));
197 next->addr = strdup(str);
198 next->size = strlen(str)+1;
202 next->next = RamTable;
205 return (char *)next->addr;
216 fprintf(stderr, "\nDumping allocated memory:\n");
220 fprintf(stderr, "%d: file: %s:%d: addr:%p size:%d\n", i, ptr->file, ptr->line, ptr->addr, ptr->size);
226 fprintf(stderr, "\nTotal of %d left-over bytes from %d allocations\n", mem, i);
230 void windebug_memwatch_init()
235 /* error message debugging junk */
237 int Log_debug_output_to_file = 0;
239 void load_filter_info(void)
244 void outwnd_printf(char* id, char* format, ...)
246 char tmp[MAX_LINE_WIDTH*4];
249 va_start (args, format);
250 vsprintf (tmp, format, args);
252 fprintf (stderr, "%s: %s\n", id, tmp);
255 void outwnd_printf2(char* format, ...)
257 char tmp[MAX_LINE_WIDTH*4];
260 va_start (args, format);
261 vsprintf (tmp, format, args);
263 fprintf (stderr, "General: %s", tmp);
271 void Warning( char * filename, int line, char * format, ... )
273 char tmp[MAX_LINE_WIDTH*4];
276 va_start (args, format);
277 vsprintf (tmp, format, args);
279 fprintf (stderr, "Warning: (%s:%d): %s\n", filename, line, tmp);
282 void Error( char * filename, int line, char * format, ... )
284 char tmp[MAX_LINE_WIDTH*4];
287 va_start (args, format);
288 vsprintf (tmp, format, args);
290 fprintf (stderr, "Error: (%s:%d): %s\n", filename, line, tmp);
294 void WinAssert(char * text,char *filename, int line)
296 fprintf (stderr, "Assertion: (%s:%d) %s\n", filename, line, text);