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 void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
56 /* fs2 only uses fname */
58 const char *ls = strrchr(path, '/');
60 ls++; // move past '/'
65 const char *lp = strrchr(path, '.');
67 lp = ls + strlen(ls); // move to the end
70 strncpy(fname, ls, _MAX_FNAME);
74 int MulDiv(int a, int b, int c)
76 /* slow long long version */
77 __extension__ long long aa = a;
78 __extension__ long long bb = b;
79 __extension__ long long cc = c;
81 __extension__ long long dd = aa * bb;
82 __extension__ long long ee = dd / cc;
107 static RAM *RamTable;
110 void vm_free(void* ptr, char *file, int line)
113 fprintf(stderr, "FREE: %s:%d addr = %p\n", file, line, ptr);
115 RAM *item = RamTable;
116 RAM **mark = &RamTable;
118 while (item != NULL) {
119 if (item->addr == ptr) {
130 mark = &(item->next);
135 fprintf(stderr, "ERROR: vm_free caught invalid free: addr = %p, file = %s/%d\n", ptr, file, line);
141 void *vm_malloc(int size, char *file, int line)
144 fprintf(stderr, "MALLOC: %s:%d %d bytes\n", file, line, size);
146 RAM *next = (RAM *)malloc(sizeof(RAM));
148 next->addr = malloc(size);
153 next->next = RamTable;
162 char *vm_strdup(char const* str, char *file, int line)
165 fprintf(stderr, "STRDUP: %s:%d\n", file, line);
167 RAM *next = (RAM *)malloc(sizeof(RAM));
169 next->addr = strdup(str);
170 next->size = strlen(str)+1;
174 next->next = RamTable;
177 return (char *)next->addr;
188 fprintf(stderr, "\nDumping allocated memory:\n");
192 fprintf(stderr, "%d: file: %s:%d: addr:%p size:%d\n", i, ptr->file, ptr->line, ptr->addr, ptr->size);
198 fprintf(stderr, "\nTotal of %d left-over bytes from %d allocations\n", mem, i);
202 void windebug_memwatch_init()
207 /* error message debugging junk */
208 int Log_debug_output_to_file = 0;
210 void load_filter_info(void)
215 void outwnd_printf(char* id, char* format, ...)
217 char tmp[MAX_LINE_WIDTH*4];
220 va_start (args, format);
221 vsprintf (tmp, format, args);
223 fprintf (stderr, "%s: %s\n", id, tmp);
226 void outwnd_printf2(char* format, ...)
228 char tmp[MAX_LINE_WIDTH*4];
231 va_start (args, format);
232 vsprintf (tmp, format, args);
234 fprintf (stderr, "General: %s", tmp);
242 void Warning( char * filename, int line, char * format, ... )
244 char tmp[MAX_LINE_WIDTH*4];
247 va_start (args, format);
248 vsprintf (tmp, format, args);
250 fprintf (stderr, "Warning: (%s:%d): %s\n", filename, line, tmp);
253 void Error( char * filename, int line, char * format, ... )
255 char tmp[MAX_LINE_WIDTH*4];
258 va_start (args, format);
259 vsprintf (tmp, format, args);
261 fprintf (stderr, "Error: (%s:%d): %s\n", filename, line, tmp);
265 void WinAssert(char * text,char *filename, int line)
267 fprintf (stderr, "Assertion: (%s:%d) %s\n", filename, line, text);