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 int filelength (int fd)
29 if (fstat (fd, &buf) == -1)
35 unsigned long _beginthread (void (*pfuncStart)(void *), unsigned unStackSize, void* pArgList)
44 SDL_Delay( long(mili) );
47 void OutputDebugString (const char *str)
49 fprintf(stderr, "OutputDebugString: %s\n", str);
57 void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
62 /* fs2 only uses fname */
64 const char *ls = strrchr(path, '/');
66 ls++; // move past '/'
71 const char *lp = strrchr(path, '.');
73 lp = ls + strlen(ls); // move to the end
77 if (dist > (_MAX_FNAME-1))
80 strncpy(fname, ls, dist);
81 fname[dist] = 0; // add null, just in case
85 int MulDiv(int a, int b, int c)
87 /* slow long long version */
88 __extension__ long long aa = a;
89 __extension__ long long bb = b;
90 __extension__ long long cc = c;
92 __extension__ long long dd = aa * bb;
93 __extension__ long long ee = dd / cc;
118 static RAM *RamTable;
122 void vm_free(void* ptr, char *file, int line)
124 void vm_free(void* ptr)
128 fprintf(stderr, "FREE: %s:%d addr = %p\n", file, line, ptr);
130 RAM *item = RamTable;
131 RAM **mark = &RamTable;
133 while (item != NULL) {
134 if (item->addr == ptr) {
145 mark = &(item->next);
150 fprintf(stderr, "ERROR: vm_free caught invalid free: addr = %p, file = %s/%d\n", ptr, file, line);
157 void *vm_malloc(int size, char *file, int line)
159 void *vm_malloc(int size)
163 fprintf(stderr, "MALLOC: %s:%d %d bytes\n", file, line, size);
165 RAM *next = (RAM *)malloc(sizeof(RAM));
167 next->addr = malloc(size);
172 next->next = RamTable;
182 char *vm_strdup(char const* str, char *file, int line)
184 char *vm_strdup(char const* str)
188 fprintf(stderr, "STRDUP: %s:%d\n", file, line);
190 RAM *next = (RAM *)malloc(sizeof(RAM));
192 next->addr = strdup(str);
193 next->size = strlen(str)+1;
197 next->next = RamTable;
200 return (char *)next->addr;
211 fprintf(stderr, "\nDumping allocated memory:\n");
215 fprintf(stderr, "%d: file: %s:%d: addr:%p size:%d\n", i, ptr->file, ptr->line, ptr->addr, ptr->size);
221 fprintf(stderr, "\nTotal of %d left-over bytes from %d allocations\n", mem, i);
225 void windebug_memwatch_init()
230 /* error message debugging junk */
232 int Log_debug_output_to_file = 0;
234 void load_filter_info(void)
239 void outwnd_printf(char* id, char* format, ...)
241 char tmp[MAX_LINE_WIDTH*4];
244 va_start (args, format);
245 vsprintf (tmp, format, args);
247 fprintf (stderr, "%s: %s\n", id, tmp);
250 void outwnd_printf2(char* format, ...)
252 char tmp[MAX_LINE_WIDTH*4];
255 va_start (args, format);
256 vsprintf (tmp, format, args);
258 fprintf (stderr, "General: %s", tmp);
266 void Warning( char * filename, int line, char * format, ... )
268 char tmp[MAX_LINE_WIDTH*4];
271 va_start (args, format);
272 vsprintf (tmp, format, args);
274 fprintf (stderr, "Warning: (%s:%d): %s\n", filename, line, tmp);
277 void Error( char * filename, int line, char * format, ... )
279 char tmp[MAX_LINE_WIDTH*4];
282 va_start (args, format);
283 vsprintf (tmp, format, args);
285 fprintf (stderr, "Error: (%s:%d): %s\n", filename, line, tmp);
289 void WinAssert(char * text,char *filename, int line)
291 fprintf (stderr, "Assertion: (%s:%d) %s\n", filename, line, text);