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)
50 // ughh, SDL_Delay causes a slowdown on Tiger for some reason and though I hate
51 // doing this, even the few Apple examples I've seen do this over what SDL_Delay does.
52 uint then = SDL_GetTicks() + mili;
54 while ( then > SDL_GetTicks() );
56 SDL_Delay( long(mili) );
60 void OutputDebugString (const char *str)
62 fprintf(stderr, "OutputDebugString: %s\n", str);
70 // make specified directory, recursively
71 // NOTE: since this is for use with CFILE this code assumes that there will be a trailing '/'
72 // or a trailing filename. any directory name not followed by a '/' will be considered a file
73 int _mkdir(const char *path)
75 int status = 1; // if we don't ever call mkdir() to update this then assume we are in error
76 char *c, tmp_path[MAX_PATH];
78 memset(tmp_path, 0, MAX_PATH);
79 strncpy(tmp_path, path, MAX_PATH-1);
89 status = mkdir(tmp_path, 0700);
94 if (status && (m_error != EEXIST) ) {
95 Warning(__FILE__, __LINE__, "Cannot mkdir %s: %s", tmp_path, strerror(m_error));
106 void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
111 /* fs2 only uses fname */
113 const char *ls = strrchr(path, '/');
115 ls++; // move past '/'
120 const char *lp = strrchr(path, '.');
122 lp = ls + strlen(ls); // move to the end
126 if (dist > (_MAX_FNAME-1))
129 strncpy(fname, ls, dist);
130 fname[dist] = 0; // add null, just in case
134 int MulDiv(int a, int b, int c)
136 /* slow long long version */
137 __extension__ long long aa = a;
138 __extension__ long long bb = b;
139 __extension__ long long cc = c;
141 __extension__ long long dd = aa * bb;
142 __extension__ long long ee = dd / cc;
167 static RAM *RamTable;
171 void vm_free(void* ptr, const char *file, int line)
173 void vm_free(void* ptr)
177 fprintf(stderr, "FREE: %s:%d addr = %p\n", file, line, ptr);
179 RAM *item = RamTable;
180 RAM **mark = &RamTable;
182 while (item != NULL) {
183 if (item->addr == ptr) {
194 mark = &(item->next);
199 fprintf(stderr, "ERROR: vm_free caught invalid free: addr = %p, file = %s/%d\n", ptr, file, line);
206 void *vm_malloc(int size, const char *file, int line)
208 void *vm_malloc(int size)
212 fprintf(stderr, "MALLOC: %s:%d %d bytes\n", file, line, size);
214 RAM *next = (RAM *)malloc(sizeof(RAM));
216 next->addr = malloc(size);
221 next->next = RamTable;
231 char *vm_strdup(char const* str, const char *file, int line)
233 char *vm_strdup(char const* str)
237 fprintf(stderr, "STRDUP: %s:%d\n", file, line);
239 RAM *next = (RAM *)malloc(sizeof(RAM));
241 next->addr = strdup(str);
242 next->size = strlen(str)+1;
246 next->next = RamTable;
249 return (char *)next->addr;
260 fprintf(stderr, "\nDumping allocated memory:\n");
264 fprintf(stderr, "%d: file: %s:%d: addr:%p size:%d\n", i, ptr->file, ptr->line, ptr->addr, ptr->size);
270 fprintf(stderr, "\nTotal of %d left-over bytes from %d allocations\n", mem, i);
274 void windebug_memwatch_init()
279 /* error message debugging junk */
281 int Log_debug_output_to_file = 0;
283 void load_filter_info(void)
288 void outwnd_printf(char* id, char* format, ...)
290 char tmp[MAX_LINE_WIDTH*4];
293 va_start (args, format);
294 vsprintf (tmp, format, args);
296 fprintf (stderr, "%s: %s\n", id, tmp);
299 void outwnd_printf2(char* format, ...)
301 char tmp[MAX_LINE_WIDTH*4];
304 va_start (args, format);
305 vsprintf (tmp, format, args);
307 fprintf (stderr, "General: %s", tmp);
315 void Warning( const char * filename, int line, const char * format, ... )
317 char tmp[MAX_LINE_WIDTH*4];
320 va_start (args, format);
321 vsprintf (tmp, format, args);
323 fprintf (stderr, "Warning: (%s:%d): %s\n", filename, line, tmp);
326 void Error( const char * filename, int line, const char * format, ... )
328 char tmp[MAX_LINE_WIDTH*4];
331 va_start (args, format);
332 vsprintf (tmp, format, args);
334 fprintf (stderr, "Error: (%s:%d): %s\n", filename, line, tmp);
338 void WinAssert(const char * text, const char *filename, int line)
340 fprintf (stderr, "Assertion: (%s:%d) %s\n", filename, line, text);