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 // make specified directory, recursively
63 // NOTE: since this is for use with CFILE this code assumes that there will be a trailing '/'
64 // or a trailing filename. any directory name not followed by a '/' will be considered a file
65 int _mkdir(const char *path)
67 int status = 1; // if we don't ever call mkdir() to update this then assume we are in error
68 char *c, tmp_path[MAX_PATH];
70 memset(tmp_path, 0, MAX_PATH);
71 strncpy(tmp_path, path, MAX_PATH-1);
81 status = mkdir(tmp_path, 0700);
86 if (status && (m_error != EEXIST) ) {
87 Warning(__FILE__, __LINE__, "Cannot mkdir %s: %s", tmp_path, strerror(m_error));
98 void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
103 /* fs2 only uses fname */
105 const char *ls = strrchr(path, '/');
107 ls++; // move past '/'
112 const char *lp = strrchr(path, '.');
114 lp = ls + strlen(ls); // move to the end
118 if (dist > (_MAX_FNAME-1))
121 strncpy(fname, ls, dist);
122 fname[dist] = 0; // add null, just in case
126 int MulDiv(int a, int b, int c)
128 /* slow long long version */
129 __extension__ long long aa = a;
130 __extension__ long long bb = b;
131 __extension__ long long cc = c;
133 __extension__ long long dd = aa * bb;
134 __extension__ long long ee = dd / cc;
159 static RAM *RamTable;
163 void vm_free(void* ptr, char *file, int line)
165 void vm_free(void* ptr)
169 fprintf(stderr, "FREE: %s:%d addr = %p\n", file, line, ptr);
171 RAM *item = RamTable;
172 RAM **mark = &RamTable;
174 while (item != NULL) {
175 if (item->addr == ptr) {
186 mark = &(item->next);
191 fprintf(stderr, "ERROR: vm_free caught invalid free: addr = %p, file = %s/%d\n", ptr, file, line);
198 void *vm_malloc(int size, char *file, int line)
200 void *vm_malloc(int size)
204 fprintf(stderr, "MALLOC: %s:%d %d bytes\n", file, line, size);
206 RAM *next = (RAM *)malloc(sizeof(RAM));
208 next->addr = malloc(size);
213 next->next = RamTable;
223 char *vm_strdup(char const* str, char *file, int line)
225 char *vm_strdup(char const* str)
229 fprintf(stderr, "STRDUP: %s:%d\n", file, line);
231 RAM *next = (RAM *)malloc(sizeof(RAM));
233 next->addr = strdup(str);
234 next->size = strlen(str)+1;
238 next->next = RamTable;
241 return (char *)next->addr;
252 fprintf(stderr, "\nDumping allocated memory:\n");
256 fprintf(stderr, "%d: file: %s:%d: addr:%p size:%d\n", i, ptr->file, ptr->line, ptr->addr, ptr->size);
262 fprintf(stderr, "\nTotal of %d left-over bytes from %d allocations\n", mem, i);
266 void windebug_memwatch_init()
271 /* error message debugging junk */
273 int Log_debug_output_to_file = 0;
275 void load_filter_info(void)
280 void outwnd_printf(char* id, char* format, ...)
282 char tmp[MAX_LINE_WIDTH*4];
285 va_start (args, format);
286 vsprintf (tmp, format, args);
288 fprintf (stderr, "%s: %s\n", id, tmp);
291 void outwnd_printf2(char* format, ...)
293 char tmp[MAX_LINE_WIDTH*4];
296 va_start (args, format);
297 vsprintf (tmp, format, args);
299 fprintf (stderr, "General: %s", tmp);
307 void Warning( char * filename, int line, char * format, ... )
309 char tmp[MAX_LINE_WIDTH*4];
312 va_start (args, format);
313 vsprintf (tmp, format, args);
315 fprintf (stderr, "Warning: (%s:%d): %s\n", filename, line, tmp);
318 void Error( char * filename, int line, char * format, ... )
320 char tmp[MAX_LINE_WIDTH*4];
323 va_start (args, format);
324 vsprintf (tmp, format, args);
326 fprintf (stderr, "Error: (%s:%d): %s\n", filename, line, tmp);
330 void WinAssert(char * text,char *filename, int line)
332 fprintf (stderr, "Assertion: (%s:%d) %s\n", filename, line, text);