From a470253b0b331bcc5ed0576e7ea3e6c9243558b4 Mon Sep 17 00:00:00 2001 From: olsner Date: Thu, 4 Mar 2004 20:36:31 +0000 Subject: [PATCH] big merge goes linux! ; ) This was SVN commit r171. --- source/lib/detect.cpp | 7 +++--- source/lib/misc.cpp | 42 ++++++++++++++++++++++++++++++++ source/lib/misc.h | 10 +++++++- source/lib/posix.h | 5 +++- source/lib/res/file.cpp | 2 +- source/lib/res/font.cpp | 2 +- source/lib/res/tex.cpp | 2 +- source/lib/res/tex.h | 2 +- source/lib/res/zip.cpp | 4 +-- source/lib/res/zip.h | 2 +- source/lib/sysdep/sysdep.cpp | 3 ++- source/lib/sysdep/win/win.h | 4 ++- source/lib/sysdep/win/wposix.cpp | 6 ++++- source/lib/sysdep/x.cpp | 3 ++- source/lib/timer.cpp | 2 +- 15 files changed, 79 insertions(+), 17 deletions(-) diff --git a/source/lib/detect.cpp b/source/lib/detect.cpp index 24a092ca71..a94264a789 100755 --- a/source/lib/detect.cpp +++ b/source/lib/detect.cpp @@ -26,7 +26,9 @@ #include "lib.h" #include "detect.h" -#include "sysdep/ia32.h" +#ifdef _M_IX86 +# include "sysdep/ia32.h" +#endif #include "timer.h" #include "ogl.h" #include "sdl.h" @@ -79,7 +81,6 @@ void get_mem_status() #endif } - // // graphics card // @@ -90,7 +91,7 @@ char gfx_drv[128] = "unknown"; // attempt to detect graphics card without OpenGL (in case ogl init fails, // or we want more detailed info). gfx_card[] is unchanged on failure. -inline void get_gfx_info() +void get_gfx_info() { #ifdef _WIN32 win_get_gfx_card(); diff --git a/source/lib/misc.cpp b/source/lib/misc.cpp index d9ee3d7c5c..df2ddf8a7d 100755 --- a/source/lib/misc.cpp +++ b/source/lib/misc.cpp @@ -216,7 +216,49 @@ void base32(const int len, const u8* in, u8* out) } } +#ifndef _WIN32 +char *_itoa(int value, char *out, int radix) +{ + return _ltoa(value, out, radix); +} +static const char digits[]="0123456789abcdef"; + +char *_ultoa(unsigned long int value, char *out, int radix) +{ + char buf[21]; + char *p=buf+21; + + while (value) + { + *(--p)=digits[value % radix]; + value /= radix; + } + + memcpy(out, p, (buf+21)-p); + out[(buf+21)-p]=0; + return out; +} +char *_ltoa(long val, char *out, int radix) +{ + char buf[21]; + char *p=buf+21; + bool sign=val < 0; + if (sign) val=-val; + + while (val) + { + *(--p)=digits[val % radix]; + val /= radix; + } + + if (sign) *(--p) = '-'; + + memcpy(out, p, (buf+21)-p); + out[(buf+21)-p]=0; + return out; +} +#endif diff --git a/source/lib/misc.h b/source/lib/misc.h index ad2f204318..5bf70f0524 100755 --- a/source/lib/misc.h +++ b/source/lib/misc.h @@ -20,6 +20,7 @@ #define __MISC_H__ #include "types.h" +#include "config.h" // bswap32 is overloaded! #ifdef __cplusplus @@ -67,7 +68,7 @@ static inline u32 read_le32(const void* p) for(int i = 0; i < 4; i++) { t <<= 8; - t |= *(const u8*)p++; + t |= *((const u8*)p)++; } return t; #else @@ -98,6 +99,13 @@ extern float fminf(float, float); // big endian! extern void base32(const int len, const u8* in, u8* out); +#ifndef _WIN32 + +char *_itoa(int, char *, int radix); +char *_ultoa(unsigned long int, char*, int radix); +char *_ltoa(long, char *, int radix); + +#endif diff --git a/source/lib/posix.h b/source/lib/posix.h index 3746795f19..594bf1d251 100755 --- a/source/lib/posix.h +++ b/source/lib/posix.h @@ -11,14 +11,17 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include +#include #include -#endif // #ifdef _WIN32 else \ No newline at end of file +#endif // #ifdef _WIN32 else diff --git a/source/lib/res/file.cpp b/source/lib/res/file.cpp index c532f2cb2b..10f847eefb 100755 --- a/source/lib/res/file.cpp +++ b/source/lib/res/file.cpp @@ -682,7 +682,7 @@ skip_wait: } // read directly into target buffer else - p = cb->aio_buf; + p = (void *)cb->aio_buf; // cb->aio_buf is volatile, p is not return ret; } diff --git a/source/lib/res/font.cpp b/source/lib/res/font.cpp index 56d91050ee..758bd42693 100755 --- a/source/lib/res/font.cpp +++ b/source/lib/res/font.cpp @@ -209,7 +209,7 @@ static int Font_reload(Font* f, const char* fn) } -inline Handle font_load(const char* fn, int scope) +Handle font_load(const char* fn, int scope) { return h_alloc(H_Font, fn, scope); } diff --git a/source/lib/res/tex.cpp b/source/lib/res/tex.cpp index 580f2428e2..459f79a06e 100755 --- a/source/lib/res/tex.cpp +++ b/source/lib/res/tex.cpp @@ -746,7 +746,7 @@ static int Tex_reload(Tex* t, const char* fn) } -inline Handle tex_load(const char* const fn, int scope) +Handle tex_load(const char* const fn, int scope) { return h_alloc(H_Tex, fn, scope); } diff --git a/source/lib/res/tex.h b/source/lib/res/tex.h index 7f742ce8ab..f955cfb6b2 100755 --- a/source/lib/res/tex.h +++ b/source/lib/res/tex.h @@ -25,7 +25,7 @@ // load and return a handle to the texture given in . // supports RAW, BMP, JP2, PNG, TGA, DDS -extern Handle tex_load(const char* fn, int scope = 0); +extern Handle tex_load(const char* const fn, int scope = 0); extern int tex_bind(Handle ht); diff --git a/source/lib/res/zip.cpp b/source/lib/res/zip.cpp index 92c3e3cd58..2342789b7d 100755 --- a/source/lib/res/zip.cpp +++ b/source/lib/res/zip.cpp @@ -294,13 +294,13 @@ found_ecdr: // open and return a handle to the zip archive indicated by -inline Handle zip_archive_open(const char* const fn) +Handle zip_archive_open(const char* const fn) { return h_alloc(H_ZArchive, fn); } // close the archive and set ha to 0 -inline int zip_archive_close(Handle& ha) +int zip_archive_close(Handle& ha) { return h_free(ha, H_ZArchive); } diff --git a/source/lib/res/zip.h b/source/lib/res/zip.h index 4784b45518..feb0a846ea 100755 --- a/source/lib/res/zip.h +++ b/source/lib/res/zip.h @@ -21,7 +21,7 @@ #include "h_mgr.h" #include "lib.h" -#include "File.h" +#include "file.h" // diff --git a/source/lib/sysdep/sysdep.cpp b/source/lib/sysdep/sysdep.cpp index 5052f6c4f3..dc4eda3a2b 100755 --- a/source/lib/sysdep/sysdep.cpp +++ b/source/lib/sysdep/sysdep.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "sysdep.h" @@ -28,4 +29,4 @@ void check_heap() { } -#endif // #ifndef _WIN32 \ No newline at end of file +#endif // #ifndef _WIN32 diff --git a/source/lib/sysdep/win/win.h b/source/lib/sysdep/win/win.h index f7d7b17a27..daf9502b9a 100755 --- a/source/lib/sysdep/win/win.h +++ b/source/lib/sysdep/win/win.h @@ -1,9 +1,11 @@ #if !defined(__WIN_H__) && defined(_WIN32) #define __WIN_H__ +#include + // C99 #define snprintf _snprintf -#define snwprintf _snwprintf +#define swprintf _snwprintf #define vsnprintf _vsnprintf #include // wchar_t diff --git a/source/lib/sysdep/win/wposix.cpp b/source/lib/sysdep/win/wposix.cpp index 1cab502760..9f4b4e1129 100755 --- a/source/lib/sysdep/win/wposix.cpp +++ b/source/lib/sysdep/win/wposix.cpp @@ -338,7 +338,11 @@ int pthread_mutex_timedlock(pthread_mutex_t* m, const struct timespec* abs_timeo return WaitForSingleObject(*m, ms_timeout) == WAIT_OBJECT_0? 0 : -1; } - +int pthread_mutex_destroy(pthread_mutex_t* m) +{ + CloseHandle(*m); + return 0; +} ////////////////////////////////////////////////////////////////////////////// // diff --git a/source/lib/sysdep/x.cpp b/source/lib/sysdep/x.cpp index 47012a0e11..af264fbac7 100755 --- a/source/lib/sysdep/x.cpp +++ b/source/lib/sysdep/x.cpp @@ -18,6 +18,7 @@ #ifdef HAVE_X #include +#include "detect.h" // useful for choosing a video mode. not called by detect(). // if we fail, don't change the outputs (assumed initialized to defaults) @@ -33,4 +34,4 @@ void get_cur_resolution(int& xres, int& yres) XCloseDisplay(disp); } -#endif // #ifdef HAVE_X \ No newline at end of file +#endif // #ifdef HAVE_X diff --git a/source/lib/timer.cpp b/source/lib/timer.cpp index 710f8b43f8..183db4dd43 100755 --- a/source/lib/timer.cpp +++ b/source/lib/timer.cpp @@ -88,7 +88,7 @@ double timer_res() #elif defined(HAVE_CLOCK_GETTIME) struct timespec res; - clock_getres(CLOCK_REALTIME, res); + clock_getres(CLOCK_REALTIME, &res); return res.tv_nsec * 1e-9; #else