Use SDL_ prefixed versions of C library functions.
authorSam Lantinga <slouken@libsdl.org>
Tue, 07 Feb 2006 06:59:48 +0000
changeset 1336 3692456e7b0f
parent 1335 c39265384763
child 1337 c687f06c7473
Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
include/SDL_config.h
include/SDL_getenv.h
include/SDL_stdlib.h
include/SDL_string.h
src/SDL.c
src/SDL_error.c
src/audio/SDL_audio.c
src/audio/SDL_audiodev.c
src/audio/SDL_audiomem.c
src/audio/SDL_sysaudio.h
src/audio/SDL_wave.c
src/audio/SDL_wave.h
src/audio/alsa/SDL_alsa_audio.c
src/audio/amigaos/SDL_ahiaudio.c
src/audio/arts/SDL_artsaudio.c
src/audio/baudio/SDL_beaudio.cc
src/audio/dart/SDL_dart.c
src/audio/dc/SDL_dcaudio.c
src/audio/disk/SDL_diskaudio.c
src/audio/dma/SDL_dmaaudio.c
src/audio/dmedia/SDL_irixaudio.c
src/audio/dsp/SDL_dspaudio.c
src/audio/esd/SDL_esdaudio.c
src/audio/macosx/SDL_coreaudio.c
src/audio/macrom/SDL_romaudio.c
src/audio/mint/SDL_mintaudio.c
src/audio/mint/SDL_mintaudio_dma8.c
src/audio/mint/SDL_mintaudio_gsxb.c
src/audio/mint/SDL_mintaudio_mcsn.c
src/audio/mint/SDL_mintaudio_stfa.c
src/audio/mint/SDL_mintaudio_xbios.c
src/audio/mme/SDL_mmeaudio.c
src/audio/nas/SDL_nasaudio.c
src/audio/nto/SDL_nto_audio.c
src/audio/openbsd/SDL_openbsdaudio.c
src/audio/paudio/SDL_paudio.c
src/audio/sun/SDL_sunaudio.c
src/audio/ums/SDL_umsaudio.c
src/audio/windib/SDL_dibaudio.c
src/audio/windx5/SDL_dx5audio.c
src/cdrom/SDL_cdrom.c
src/cdrom/SDL_syscdrom.h
src/cdrom/aix/SDL_syscdrom.c
src/cdrom/beos/SDL_syscdrom.cc
src/cdrom/bsdi/SDL_syscdrom.c
src/cdrom/freebsd/SDL_syscdrom.c
src/cdrom/linux/SDL_syscdrom.c
src/cdrom/macos/SDL_syscdrom.c
src/cdrom/macosx/AudioFilePlayer.c
src/cdrom/macosx/AudioFileReaderThread.c
src/cdrom/macosx/SDLOSXCAGuard.c
src/cdrom/openbsd/SDL_syscdrom.c
src/cdrom/os2/SDL_syscdrom.c
src/cdrom/osf/SDL_syscdrom.c
src/cdrom/qnx/SDL_syscdrom.c
src/cdrom/win32/SDL_syscdrom.c
src/events/SDL_active.c
src/events/SDL_events.c
src/events/SDL_keyboard.c
src/events/SDL_mouse.c
src/events/SDL_sysevents.h
src/file/SDL_rwops.c
src/joystick/SDL_joystick.c
src/joystick/SDL_sysjoystick.h
src/joystick/amigaos/SDL_sysjoystick.c
src/joystick/beos/SDL_bejoystick.cc
src/joystick/bsd/SDL_sysjoystick.c
src/joystick/dc/SDL_sysjoystick.c
src/joystick/linux/SDL_sysjoystick.c
src/joystick/macos/SDL_sysjoystick.c
src/joystick/mint/SDL_sysjoystick.c
src/joystick/os2/SDL_sysjoystick.c
src/joystick/riscos/SDL_sysjoystick.c
src/joystick/win32/SDL_mmjoystick.c
src/loadso/macos/SDL_loadso.c
src/loadso/macosx/SDL_loadso.c
src/loadso/windows/SDL_loadso.c
src/main/macos/SDL_main.c
src/main/win32/SDL_win32_main.c
src/stdlib/SDL_getenv.c
src/stdlib/SDL_malloc.c
src/stdlib/SDL_qsort.c
src/stdlib/SDL_string.c
src/thread/SDL_thread.c
src/thread/amigaos/SDL_syssem.c
src/thread/amigaos/SDL_thread.c
src/thread/beos/SDL_syssem.c
src/thread/bsdi/SDL_syssem.c
src/thread/dc/SDL_syscond.c
src/thread/dc/SDL_sysmutex.c
src/thread/generic/SDL_syscond.c
src/thread/generic/SDL_sysmutex.c
src/thread/generic/SDL_syssem.c
src/thread/linux/SDL_syscond.c
src/thread/linux/SDL_sysmutex.c
src/thread/linux/SDL_syssem.c
src/thread/linux/SDL_systhread.c
src/thread/os2/SDL_syscond.c
src/thread/os2/SDL_sysmutex.c
src/thread/os2/SDL_syssem.c
src/thread/os2/SDL_systhread.c
src/thread/pth/SDL_syscond.c
src/thread/pth/SDL_sysmutex.c
src/thread/riscos/SDL_syscond.c
src/thread/riscos/SDL_sysmutex.c
src/thread/riscos/SDL_syssem.c
src/thread/win32/SDL_sysmutex.c
src/thread/win32/SDL_syssem.c
src/thread/win32/SDL_systhread.c
src/timer/SDL_timer.c
src/timer/linux/SDL_systimer.c
src/video/SDL_RLEaccel.c
src/video/SDL_blit_0.c
src/video/SDL_blit_N.c
src/video/SDL_bmp.c
src/video/SDL_cursor.c
src/video/SDL_gamma.c
src/video/SDL_pixels.c
src/video/SDL_surface.c
src/video/SDL_video.c
src/video/SDL_yuv.c
src/video/SDL_yuv_sw.c
src/video/Xext/Xv/Xv.c
src/video/Xext/Xxf86dga/XF86DGA.c
src/video/aalib/SDL_aavideo.c
src/video/ataricommon/SDL_atarievents.c
src/video/ataricommon/SDL_atarigl.c
src/video/ataricommon/SDL_biosevents.c
src/video/ataricommon/SDL_gemdosevents.c
src/video/ataricommon/SDL_ikbdevents.c
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_sysmouse.cc
src/video/bwindow/SDL_sysvideo.cc
src/video/bwindow/SDL_sysyuv.cc
src/video/cybergfx/SDL_amigamouse.c
src/video/cybergfx/SDL_cgxaccel.c
src/video/cybergfx/SDL_cgximage.c
src/video/cybergfx/SDL_cgxmodes.c
src/video/cybergfx/SDL_cgxvideo.c
src/video/cybergfx/SDL_cgxwm.c
src/video/cybergfx/SDL_cgxyuv.c
src/video/dc/SDL_dcevents.c
src/video/dc/SDL_dcvideo.c
src/video/dga/SDL_dgavideo.c
src/video/directfb/SDL_DirectFB_video.c
src/video/dummy/SDL_nullvideo.c
src/video/epoc/SDL_epocvideo.cpp
src/video/fbcon/SDL_fbelo.c
src/video/fbcon/SDL_fbevents.c
src/video/fbcon/SDL_fbvideo.c
src/video/gapi/SDL_gapivideo.c
src/video/gem/SDL_gemevents.c
src/video/gem/SDL_gemmouse.c
src/video/gem/SDL_gemvideo.c
src/video/ggi/SDL_ggivideo.c
src/video/ipod/SDL_ipodvideo.c
src/video/maccommon/SDL_macmouse.c
src/video/maccommon/SDL_macwm.c
src/video/macdsp/SDL_dspvideo.c
src/video/macrom/SDL_romvideo.c
src/video/os2fslib/SDL_os2fslib.c
src/video/photon/SDL_ph_gl.c
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_ph_modes.c
src/video/photon/SDL_ph_mouse.c
src/video/photon/SDL_ph_video.c
src/video/photon/SDL_ph_wm.c
src/video/photon/SDL_phyuv.c
src/video/picogui/SDL_pgevents.c
src/video/picogui/SDL_pgvideo.c
src/video/ps2gs/SDL_gsevents.c
src/video/ps2gs/SDL_gsvideo.c
src/video/ps2gs/SDL_gsyuv.c
src/video/qtopia/SDL_QWin.cc
src/video/qtopia/SDL_sysevents.cc
src/video/qtopia/SDL_sysvideo.cc
src/video/riscos/SDL_riscosFullScreenVideo.c
src/video/riscos/SDL_riscosevents.c
src/video/riscos/SDL_riscosmouse.c
src/video/riscos/SDL_riscossprite.c
src/video/riscos/SDL_riscostask.c
src/video/riscos/SDL_riscosvideo.c
src/video/riscos/SDL_wimppoll.c
src/video/riscos/SDL_wimpvideo.c
src/video/svga/SDL_svgaevents.c
src/video/svga/SDL_svgavideo.c
src/video/vgl/SDL_vglevents.c
src/video/vgl/SDL_vglvideo.c
src/video/wincommon/SDL_lowvideo.h
src/video/wincommon/SDL_sysevents.c
src/video/wincommon/SDL_sysmouse.c
src/video/wincommon/SDL_syswm.c
src/video/wincommon/SDL_wingl.c
src/video/windib/SDL_dibevents.c
src/video/windib/SDL_dibvideo.c
src/video/windx5/SDL_dx5events.c
src/video/windx5/SDL_dx5video.c
src/video/windx5/SDL_dx5yuv.c
src/video/wscons/SDL_wsconsvideo.c
src/video/x11/SDL_x11dga.c
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11gl.c
src/video/x11/SDL_x11image.c
src/video/x11/SDL_x11modes.c
src/video/x11/SDL_x11mouse.c
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11video.h
src/video/x11/SDL_x11wm.c
src/video/x11/SDL_x11yuv.c
src/video/xbios/SDL_xbios.c
src/video/xbios/SDL_xbios_centscreen.c
src/video/xbios/SDL_xbios_sb3.c
--- a/include/SDL_config.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/include/SDL_config.h	Tue Feb 07 06:59:48 2006 +0000
@@ -54,16 +54,16 @@
 #endif /* !_WIN32_WCE */
 
 /* Features provided by SDL_stdlib.h */
-#if !defined(_WIN32) /* Don't use C runtime versions of these on Windows */
-#define HAVE_GETENV
-#define HAVE_PUTENV
-#endif
 #define HAVE_MALLOC
 #define HAVE_REALLOC
 #define HAVE_FREE
 #ifndef HAVE_ALLOCA
 #define HAVE_ALLOCA
 #endif
+#if !defined(_WIN32) /* Don't use C runtime versions of these on Windows */
+#define HAVE_GETENV
+#define HAVE_PUTENV
+#endif
 /*#define HAVE_QSORT*/
 
 /* Features provided by SDL_string.h */
@@ -74,6 +74,8 @@
 #define HAVE_STRLEN
 #define HAVE_STRCPY
 #define HAVE_STRNCPY
+#define HAVE_STRCAT
+#define HAVE_STRNCAT
 /*#define HAVE__STRREV*/
 /*#define HAVE__STRUPR*/
 /*#define HAVE__STRLWR*/
@@ -94,7 +96,7 @@
 /*#define HAVE_STRCASECMP*/
 #define HAVE_SSCANF
 /*#define HAVE_SNPRINTF*/
-#define HAVE_VSNPRINTF
+/*#define HAVE_VSNPRINTF*/
 
 #endif /* HAVE_LIBC */
 
--- a/include/SDL_getenv.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/include/SDL_getenv.h	Tue Feb 07 06:59:48 2006 +0000
@@ -20,39 +20,4 @@
     slouken@libsdl.org
 */
 
-#ifndef _SDL_getenv_h
-#define _SDL_getenv_h
-
-#include "SDL_config.h"
-
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-
-#include "begin_code.h"
-/* Set up for C function definitions, even when using C++ */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef HAVE_GETENV
-#define SDL_getenv	getenv
-#else
-#define getenv		SDL_getenv
-extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
-#endif
-
-#ifdef HAVE_PUTENV
-#define SDL_putenv	putenv
-#else
-#define putenv		SDL_putenv
-extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
-#endif
-
-/* Ends C function definitions when using C++ */
-#ifdef __cplusplus
-}
-#endif
-#include "close_code.h"
-
-#endif /* _SDL_getenv_h */
+#include "SDL_stdlib.h"
--- a/include/SDL_stdlib.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/include/SDL_stdlib.h	Tue Feb 07 06:59:48 2006 +0000
@@ -49,9 +49,6 @@
 #endif
 
 #include "SDL_types.h"
-#include "SDL_stdarg.h"
-#include "SDL_getenv.h"
-
 
 #include "begin_code.h"
 /* Set up for C function definitions, even when using C++ */
@@ -62,21 +59,18 @@
 #ifdef HAVE_MALLOC
 #define SDL_malloc	malloc
 #else
-#define malloc		SDL_malloc
 extern DECLSPEC void * SDLCALL SDL_malloc(size_t size);
 #endif
 
 #ifdef HAVE_REALLOC
 #define SDL_realloc	realloc
 #else
-#define realloc		SDL_realloc
 extern DECLSPEC void * SDLCALL SDL_realloc(void *mem, size_t size);
 #endif
 
 #ifdef HAVE_FREE
 #define SDL_free	free
 #else
-#define free		SDL_free
 extern DECLSPEC void SDLCALL SDL_free(void *mem);
 #endif
 
@@ -84,14 +78,25 @@
 #define SDL_stack_alloc(type, count)    (type*)alloca(sizeof(type)*count)
 #define SDL_stack_free(data)
 #else
-#define SDL_stack_alloc(type, count)    SDL_malloc(sizeof(type)*count)
+#define SDL_stack_alloc(type, count)    (type*)SDL_malloc(sizeof(type)*count)
 #define SDL_stack_free(data)            SDL_free(data)
 #endif
 
+#ifdef HAVE_GETENV
+#define SDL_getenv	getenv
+#else
+extern DECLSPEC char * SDLCALL SDL_getenv(const char *name);
+#endif
+
+#ifdef HAVE_PUTENV
+#define SDL_putenv	putenv
+#else
+extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
+#endif
+
 #ifdef HAVE_QSORT
 #define SDL_qsort	qsort
 #else
-#define qsort		SDL_qsort
 extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size,
            int (*compare)(const void *, const void *));
 #endif
--- a/include/SDL_string.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/include/SDL_string.h	Tue Feb 07 06:59:48 2006 +0000
@@ -44,10 +44,9 @@
 extern "C" {
 #endif
 
-#ifndef HAVE_MEMSET
-#define memset          SDL_memset
-#endif
-#ifndef SDL_memset
+#ifdef HAVE_MEMSET
+#define SDL_memset      memset
+#else
 extern DECLSPEC void * SDLCALL SDL_memset(void *dst, int c, size_t len);
 #endif
 
@@ -98,23 +97,14 @@
 		: "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \
 		: "memory" );						  \
 } while(0)
-#define SDL_memcpy4(dst, src, len)				\
-do {								\
-	int ecx, edi, esi;					\
-	__asm__ __volatile__ (					\
-		"cld\n\t"					\
-		"rep ; movsl"					\
-		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
-		: "0" ((unsigned)(len)), "1" (dst), "2" (src)	\
-		: "memory" );					\
-} while(0)
-#endif
-#ifndef HAVE_MEMCPY
-#define memcpy          SDL_memcpy
 #endif
 #ifndef SDL_memcpy
+#ifdef HAVE_MEMCPY
+#define SDL_memcpy      memcpy
+#else
 extern DECLSPEC void * SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
 #endif
+#endif
 
 #if defined(__GNUC__) && defined(i386)
 #define SDL_memcpy4(dst, src, len)				\
@@ -162,9 +152,9 @@
 extern DECLSPEC void * SDLCALL SDL_revcpy(void *dst, const void *src, size_t len);
 #endif
 
-#ifndef HAVE_MEMMOVE
-#define memmove         SDL_memmove
-#endif
+#ifdef HAVE_MEMMOVE
+#define SDL_memmove     memmove
+#else
 #define SDL_memmove(dst, src, len)			\
 do {							\
 	if ( dst < src ) {				\
@@ -173,109 +163,107 @@
 		SDL_revcpy(dst, src, len);		\
 	}						\
 } while(0)
+#endif
 
-#ifndef HAVE_MEMCMP
-#define memcmp          SDL_memcmp
-#endif
-#ifndef SDL_memcmp
+#ifdef HAVE_MEMCMP
+#define SDL_memcmp      memcmp
+#else
 extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
 #endif
 
 #ifdef HAVE_STRLEN
 #define SDL_strlen      strlen
 #else
-#define strlen          SDL_strlen
 extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
 #endif
 
 #ifdef HAVE_STRCPY
 #define SDL_strcpy     strcpy
 #else
-#define strcpy         SDL_strcpy
 extern DECLSPEC char * SDLCALL SDL_strcpy(char *dst, const char *src);
 #endif
 
 #ifdef HAVE_STRNCPY
 #define SDL_strncpy     strncpy
 #else
-#define strncpy         SDL_strncpy
 extern DECLSPEC char * SDLCALL SDL_strncpy(char *dst, const char *src, size_t maxlen);
 #endif
 
+#ifdef HAVE_STRCAT
+#define SDL_strcat     strcat
+#else
+#define SDL_strcat(dst, src)    (SDL_strcpy(dst+SDL_strlen(dst), src), dst)
+#endif
+
+#ifdef HAVE_STRNCAT
+#define SDL_strncat    strncat
+#else
+#define SDL_strncat(dst, src, n) (SDL_strncpy(dst+SDL_strlen(dst), src, n), dst)
+#endif
+
 #ifdef HAVE__STRREV
 #define SDL_strrev      _strrev
 #else
-#define _strrev	        SDL_strrev
 extern DECLSPEC char * SDLCALL SDL_strrev(char *string);
 #endif
 
 #ifdef HAVE__STRUPR
 #define SDL_strupr      _strupr
 #else
-#define _strupr         SDL_strupr
 extern DECLSPEC char * SDLCALL SDL_strupr(char *string);
 #endif
 
 #ifdef HAVE__STRLWR
 #define SDL_strlwr      _strlwr
 #else
-#define _strlwr         SDL_strlwr
 extern DECLSPEC char * SDLCALL SDL_strlwr(char *string);
 #endif
 
 #ifdef HAVE_STRCHR
 #define SDL_strchr      strchr
 #else
-#define strchr          SDL_strchr
 extern DECLSPEC char * SDLCALL SDL_strchr(const char *string, int c);
 #endif
 
 #ifdef HAVE_STRRCHR
 #define SDL_strrchr     strrchr
 #else
-#define strrchr         SDL_strrchr
 extern DECLSPEC char * SDLCALL SDL_strrchr(const char *string, int c);
 #endif
 
 #ifdef HAVE_STRSTR
 #define SDL_strstr      strstr
 #else
-#define strstr          SDL_strstr
 extern DECLSPEC char * SDLCALL SDL_strstr(const char *haystack, const char *needle);
 #endif
 
 #ifdef HAVE_ITOA
 #define SDL_itoa        itoa
 #else
-#define itoa            SDL_itoa
 #define SDL_itoa(value, string, radix)	SDL_ltoa((long)value, string, radix)
 #endif
 
 #ifdef HAVE__LTOA
 #define SDL_ltoa        _ltoa
 #else
-#define _ltoa        SDL_ltoa
 extern DECLSPEC char * SDLCALL SDL_ltoa(long value, char *string, int radix);
 #endif
 
 #ifdef HAVE__UITOA
 #define SDL_uitoa       _uitoa
 #else
-#define _uitoa          SDL_uitoa
 #define SDL_uitoa(value, string, radix)	SDL_ultoa((long)value, string, radix)
 #endif
 
 #ifdef HAVE__ULTOA
 #define SDL_ultoa       _ultoa
 #else
-#define _ultoa          SDL_ultoa
 extern DECLSPEC char * SDLCALL SDL_ultoa(unsigned long value, char *string, int radix);
 #endif
 
 #ifdef HAVE_STRTOL
 #define SDL_strtol      strtol
 #else
-#define strtol          SDL_strtol
 extern DECLSPEC long SDLCALL SDL_strtol(const char *string, char **endp, int base);
 #endif
 
@@ -284,21 +272,18 @@
 #ifdef HAVE__I64TOA
 #define SDL_lltoa       _i64toa
 #else
-#define _i64toa         SDL_lltoa
 extern DECLSPEC char* SDLCALL SDL_lltoa(Sint64 value, char *string, int radix);
 #endif
 
 #ifdef HAVE__UI64TOA
 #define SDL_ulltoa      _ui64toa
 #else
-#define _ui64toa        SDL_ulltoa
 extern DECLSPEC char* SDLCALL SDL_ulltoa(Uint64 value, char *string, int radix);
 #endif
 
 #ifdef HAVE_STRTOLL
 #define SDL_strtoll     strtoll
 #else
-#define strtoll         SDL_strtoll
 extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *string, char **endp, int base);
 #endif
 
@@ -307,14 +292,12 @@
 #ifdef HAVE_STRCMP
 #define SDL_strcmp      strcmp
 #else
-#define strcmp          SDL_strcmp
 extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
 #endif
 
 #ifdef HAVE_STRNCMP
 #define SDL_strncmp     strncmp
 #else
-#define strncmp         SDL_strncmp
 extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
 #endif
 
@@ -325,28 +308,24 @@
 #ifdef HAVE_STRCASECMP
 #define SDL_strcasecmp  strcasecmp
 #else
-#define strcasecmp      SDL_strcasecmp
 extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
 #endif
 
 #ifdef HAVE_SSCANF
 #define SDL_sscanf      sscanf
 #else
-#define sscanf          SDL_sscanf
 extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
 #endif
 
 #ifdef HAVE_SNPRINTF
 #define SDL_snprintf    snprintf
 #else
-#define snprintf        SDL_snprintf
 extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
 #endif
 
 #ifdef HAVE_VSNPRINTF
 #define SDL_vsnprintf   vsnprintf
 #else
-#define vsnprintf       SDL_vsnprintf
 extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
 #endif
 
--- a/src/SDL.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/SDL.c	Tue Feb 07 06:59:48 2006 +0000
@@ -66,7 +66,7 @@
 #ifndef DISABLE_VIDEO
 	/* Initialize the video/event subsystem */
 	if ( (flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO) ) {
-		if ( SDL_VideoInit(getenv("SDL_VIDEODRIVER"),
+		if ( SDL_VideoInit(SDL_getenv("SDL_VIDEODRIVER"),
 		                   (flags&SDL_INIT_EVENTTHREAD)) < 0 ) {
 			return(-1);
 		}
@@ -82,7 +82,7 @@
 #ifndef DISABLE_AUDIO
 	/* Initialize the audio subsystem */
 	if ( (flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO) ) {
-		if ( SDL_AudioInit(getenv("SDL_AUDIODRIVER")) < 0 ) {
+		if ( SDL_AudioInit(SDL_getenv("SDL_AUDIODRIVER")) < 0 ) {
 			return(-1);
 		}
 		SDL_initialized |= SDL_INIT_AUDIO;
--- a/src/SDL_error.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/SDL_error.c	Tue Feb 07 06:59:48 2006 +0000
@@ -63,7 +63,7 @@
 	/* Copy in the key, mark error as valid */
 	error = SDL_GetErrBuf();
 	error->error = 1;
-	strncpy((char *)error->key, fmt, sizeof(error->key));
+	SDL_strncpy((char *)error->key, fmt, sizeof(error->key));
 	error->key[sizeof(error->key)-1] = '\0';
 
 	va_start(ap, fmt);
@@ -98,7 +98,7 @@
 				  char *str = va_arg(ap, char *);
 				  if (str == NULL)
 				      str = "(null)";
-				  strncpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN);
+				  SDL_strncpy((char *)error->args[index].buf, str, ERR_MAX_STRLEN);
 				  error->args[index].buf[ERR_MAX_STRLEN-1] = 0;
 				  error->argc++;
 				}
@@ -125,9 +125,9 @@
 	char tmp[128];
 	int len, i;
 
-	snprintf(tmp, SDL_arraysize(tmp), "%d", value);
+	SDL_snprintf(tmp, SDL_arraysize(tmp), "%d", value);
 	len = 0;
-	if ( strlen(tmp) < maxlen ) {
+	if ( SDL_strlen(tmp) < maxlen ) {
 		for ( i=0; tmp[i]; ++i ) {
 			*str++ = tmp[i];
 			++len;
@@ -141,9 +141,9 @@
 	char tmp[128];
 	int len, i;
 
-	snprintf(tmp, SDL_arraysize(tmp), "%f", value);
+	SDL_snprintf(tmp, SDL_arraysize(tmp), "%f", value);
 	len = 0;
-	if ( strlen(tmp) < maxlen ) {
+	if ( SDL_strlen(tmp) < maxlen ) {
 		for ( i=0; tmp[i]; ++i ) {
 			*str++ = tmp[i];
 			++len;
@@ -157,9 +157,9 @@
 	char tmp[128];
 	int len, i;
 
-	snprintf(tmp, SDL_arraysize(tmp), "%p", value);
+	SDL_snprintf(tmp, SDL_arraysize(tmp), "%p", value);
 	len = 0;
-	if ( strlen(tmp) < maxlen ) {
+	if ( SDL_strlen(tmp) < maxlen ) {
 		for ( i=0; tmp[i]; ++i ) {
 			*str++ = tmp[i];
 			++len;
@@ -253,9 +253,9 @@
 	unsigned int i;
 
 	/* Allocate the UNICODE buffer */
-	errstr16 = (Uint16 *)malloc(maxlen * (sizeof *errstr16));
+	errstr16 = (Uint16 *)SDL_malloc(maxlen * (sizeof *errstr16));
 	if ( ! errstr16 ) {
-		strncpy((char *)errstr, "Out of memory", maxlen);
+		SDL_strncpy((char *)errstr, "Out of memory", maxlen);
 		errstr[maxlen-1] = '\0';
 		return(errstr);
 	}
@@ -269,7 +269,7 @@
 	}
 
 	/* Free UNICODE buffer (if necessary) */
-	free(errstr16);
+	SDL_free(errstr16);
 
 	return(errstr);
 }
@@ -320,7 +320,7 @@
 	SDL_SetError("Hi there!");
 	printf("Error 1: %s\n", SDL_GetError());
 	SDL_ClearError();
-	memset(buffer, '1', BUFSIZ);
+	SDL_memset(buffer, '1', BUFSIZ);
 	buffer[BUFSIZ] = 0;
 	SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
 	printf("Error 2: %s\n", SDL_GetError());
--- a/src/audio/SDL_audio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/SDL_audio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -220,7 +220,7 @@
 				stream = audio->fake_stream;
 			}
 		}
-		memset(stream, silence, stream_len);
+		SDL_memset(stream, silence, stream_len);
 
 		if ( ! audio->paused ) {
 			SDL_mutexP(audio->mixer_lock);
@@ -235,7 +235,7 @@
 			if ( stream == NULL ) {
 				stream = audio->fake_stream;
 			}
-			memcpy(stream, audio->convert.buf,
+			SDL_memcpy(stream, audio->convert.buf,
 			               audio->convert.len_cvt);
 		}
 
@@ -299,17 +299,17 @@
 	audio = NULL;
 	idx = 0;
 #ifdef unix
-	if ( (driver_name == NULL) && (getenv("ESPEAKER") != NULL) ) {
+	if ( (driver_name == NULL) && (SDL_getenv("ESPEAKER") != NULL) ) {
 		/* Ahem, we know that if ESPEAKER is set, user probably wants
 		   to use ESD, but don't start it if it's not already running.
 		   This probably isn't the place to do this, but... Shh! :)
 		 */
 		for ( i=0; bootstrap[i]; ++i ) {
-			if ( strcmp(bootstrap[i]->name, "esd") == 0 ) {
+			if ( SDL_strcmp(bootstrap[i]->name, "esd") == 0 ) {
 				const char *esd_no_spawn;
 
 				/* Don't start ESD if it's not running */
-				esd_no_spawn = getenv("ESD_NO_SPAWN");
+				esd_no_spawn = SDL_getenv("ESD_NO_SPAWN");
 				if ( esd_no_spawn == NULL ) {
 					putenv("ESD_NO_SPAWN=1");
 				}
@@ -329,13 +329,13 @@
 	if ( audio == NULL ) {
 		if ( driver_name != NULL ) {
 #if 0	/* This will be replaced with a better driver selection API */
-			if ( strrchr(driver_name, ':') != NULL ) {
-				idx = atoi(strrchr(driver_name, ':')+1);
+			if ( SDL_strrchr(driver_name, ':') != NULL ) {
+				idx = atoi(SDL_strrchr(driver_name, ':')+1);
 			}
 #endif
 			for ( i=0; bootstrap[i]; ++i ) {
-				if (strncmp(bootstrap[i]->name, driver_name,
-				            strlen(bootstrap[i]->name)) == 0) {
+				if (SDL_strncmp(bootstrap[i]->name, driver_name,
+				            SDL_strlen(bootstrap[i]->name)) == 0) {
 					if ( bootstrap[i]->available() ) {
 						audio=bootstrap[i]->create(idx);
 						break;
@@ -375,7 +375,7 @@
 char *SDL_AudioDriverName(char *namebuf, int maxlen)
 {
 	if ( current_audio != NULL ) {
-		strncpy(namebuf, current_audio->name, maxlen-1);
+		SDL_strncpy(namebuf, current_audio->name, maxlen-1);
 		namebuf[maxlen-1] = '\0';
 		return(namebuf);
 	}
@@ -436,7 +436,7 @@
 	SDL_CalculateAudioSpec(desired);
 
 	/* Open the audio subsystem */
-	memcpy(&audio->spec, desired, sizeof(audio->spec));
+	SDL_memcpy(&audio->spec, desired, sizeof(audio->spec));
 	audio->convert.needed = 0;
 	audio->enabled = 1;
 	audio->paused  = 1;
@@ -489,7 +489,7 @@
 
 	/* See if we need to do any conversion */
 	if ( obtained != NULL ) {
-		memcpy(obtained, &audio->spec, sizeof(audio->spec));
+		SDL_memcpy(obtained, &audio->spec, sizeof(audio->spec));
 	} else if ( desired->freq != audio->spec.freq ||
                     desired->format != audio->spec.format ||
 	            desired->channels != audio->spec.channels ) {
--- a/src/audio/SDL_audiodev.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/SDL_audiodev.c	Tue Feb 07 06:59:48 2006 +0000
@@ -55,8 +55,8 @@
 	char audiopath[1024];
 
 	/* Figure out what our audio device is */
-	if ( ((audiodev=getenv("SDL_PATH_DSP")) == NULL) &&
-	     ((audiodev=getenv("AUDIODEV")) == NULL) ) {
+	if ( ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) &&
+	     ((audiodev=SDL_getenv("AUDIODEV")) == NULL) ) {
 		if ( classic ) {
 			audiodev = _PATH_DEV_AUDIO;
 		} else {
@@ -74,7 +74,7 @@
 	audio_fd = open(audiodev, flags, 0);
 
 	/* If the first open fails, look for other devices */
-	if ( (audio_fd < 0) && (strlen(audiodev) < (sizeof(audiopath)-3)) ) {
+	if ( (audio_fd < 0) && (SDL_strlen(audiodev) < (sizeof(audiopath)-3)) ) {
 		int exists, instance;
 		struct stat sb;
 
@@ -90,7 +90,7 @@
 		audiodev = audiopath;
 	}
 	if ( path != NULL ) {
-		strncpy(path, audiodev, maxlen);
+		SDL_strncpy(path, audiodev, maxlen);
 		path[maxlen-1] = '\0';
 	}
 	return(audio_fd);
@@ -130,15 +130,15 @@
 	int  audio_fd;
 
 	/* Figure out what our audio device is */
-	if ((audiodev=getenv("SDL_PATH_DSP")) == NULL) {
-	    audiodev=getenv("AUDIODEV");
+	if ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) {
+	    audiodev=SDL_getenv("AUDIODEV");
 	}
 	if ( audiodev == NULL ) {
 	    return -1;
 	}
 	audio_fd = open(audiodev, flags, 0);
 	if ( path != NULL ) {
-		strncpy(path, audiodev, maxlen);
+		SDL_strncpy(path, audiodev, maxlen);
 		path[maxlen-1] = '\0';
 	}
 	return audio_fd;
@@ -168,7 +168,7 @@
 	    audio_fd = open(audiopath, flags, 0);
 	    if ( audio_fd > 0 ) {
 		if ( path != NULL ) {
-		    strncpy( path, audiopath, maxlen );
+		    SDL_strncpy( path, audiopath, maxlen );
 		    path[maxlen-1] = '\0';
 		}
 	        return audio_fd;
--- a/src/audio/SDL_audiomem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/SDL_audiomem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -52,7 +52,7 @@
 	/* Set the segment for deletion when it is detatched */
 	shmctl(semid, IPC_RMID, NULL);	/* Delets semid if shmat() fails */
 #else
-	chunk = malloc(size);
+	chunk = SDL_malloc(size);
 #endif
 	return((void *)chunk);
 }
@@ -62,6 +62,6 @@
 #ifdef FORK_HACK
 	shmdt(chunk);
 #else
-	free(chunk);
+	SDL_free(chunk);
 #endif
 }
--- a/src/audio/SDL_sysaudio.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/SDL_sysaudio.h	Tue Feb 07 06:59:48 2006 +0000
@@ -2,7 +2,7 @@
     SDL - Simple DirectMedia Layer
     Copyright (C) 1997-2006 Sam Lantinga
 
-    This library is free software; you can redistribute it and/or
+    This library is SDL_free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
     version 2.1 of the License, or (at your option) any later version.
--- a/src/audio/SDL_wave.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/SDL_wave.c	Tue Feb 07 06:59:48 2006 +0000
@@ -135,7 +135,7 @@
 	*audio_len = (encoded_len/MS_ADPCM_state.wavefmt.blockalign) * 
 				MS_ADPCM_state.wSamplesPerBlock*
 				MS_ADPCM_state.wavefmt.channels*sizeof(Sint16);
-	*audio_buf = (Uint8 *)malloc(*audio_len);
+	*audio_buf = (Uint8 *)SDL_malloc(*audio_len);
 	if ( *audio_buf == NULL ) {
 		SDL_Error(SDL_ENOMEM);
 		return(-1);
@@ -214,7 +214,7 @@
 		}
 		encoded_len -= MS_ADPCM_state.wavefmt.blockalign;
 	}
-	free(freeable);
+	SDL_free(freeable);
 	return(0);
 }
 
@@ -352,7 +352,7 @@
 	*audio_len = (encoded_len/IMA_ADPCM_state.wavefmt.blockalign) * 
 				IMA_ADPCM_state.wSamplesPerBlock*
 				IMA_ADPCM_state.wavefmt.channels*sizeof(Sint16);
-	*audio_buf = (Uint8 *)malloc(*audio_len);
+	*audio_buf = (Uint8 *)SDL_malloc(*audio_len);
 	if ( *audio_buf == NULL ) {
 		SDL_Error(SDL_ENOMEM);
 		return(-1);
@@ -394,7 +394,7 @@
 		}
 		encoded_len -= IMA_ADPCM_state.wavefmt.blockalign;
 	}
-	free(freeable);
+	SDL_free(freeable);
 	return(0);
 }
 
@@ -444,7 +444,7 @@
 	chunk.data = NULL;
 	do {
 		if ( chunk.data != NULL ) {
-			free(chunk.data);
+			SDL_free(chunk.data);
 		}
 		lenread = ReadChunk(src, &chunk);
 		if ( lenread < 0 ) {
@@ -489,7 +489,7 @@
 			was_error = 1;
 			goto done;
 	}
-	memset(spec, 0, (sizeof *spec));
+	SDL_memset(spec, 0, (sizeof *spec));
 	spec->freq = SDL_SwapLE32(format->frequency);
 	switch (SDL_SwapLE16(format->bitspersample)) {
 		case 4:
@@ -521,7 +521,7 @@
 	*audio_buf = NULL;
 	do {
 		if ( *audio_buf != NULL ) {
-			free(*audio_buf);
+			SDL_free(*audio_buf);
 		}
 		lenread = ReadChunk(src, &chunk);
 		if ( lenread < 0 ) {
@@ -553,7 +553,7 @@
 
 done:
 	if ( format != NULL ) {
-		free(format);
+		SDL_free(format);
 	}
 	if ( freesrc && src ) {
 		SDL_RWclose(src);
@@ -574,7 +574,7 @@
 void SDL_FreeWAV(Uint8 *audio_buf)
 {
 	if ( audio_buf != NULL ) {
-		free(audio_buf);
+		SDL_free(audio_buf);
 	}
 }
 
@@ -582,14 +582,14 @@
 {
 	chunk->magic	= SDL_ReadLE32(src);
 	chunk->length	= SDL_ReadLE32(src);
-	chunk->data = (Uint8 *)malloc(chunk->length);
+	chunk->data = (Uint8 *)SDL_malloc(chunk->length);
 	if ( chunk->data == NULL ) {
 		SDL_Error(SDL_ENOMEM);
 		return(-1);
 	}
 	if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) {
 		SDL_Error(SDL_EFREAD);
-		free(chunk->data);
+		SDL_free(chunk->data);
 		return(-1);
 	}
 	return(chunk->length);
--- a/src/audio/SDL_wave.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/SDL_wave.h	Tue Feb 07 06:59:48 2006 +0000
@@ -2,7 +2,7 @@
     SDL - Simple DirectMedia Layer
     Copyright (C) 1997-2006 Sam Lantinga
 
-    This library is free software; you can redistribute it and/or
+    This library is SDL_free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
     version 2.1 of the License, or (at your option) any later version.
--- a/src/audio/alsa/SDL_alsa_audio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/alsa/SDL_alsa_audio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -170,7 +170,7 @@
 {
 	const char *device;
 	
-	device = getenv("AUDIODEV");	/* Is there a standard variable name? */
+	device = SDL_getenv("AUDIODEV");	/* Is there a standard variable name? */
 	if ( device == NULL ) {
 		if (channels == 6) device = "surround51";
 		else if (channels == 4) device = "surround40";
@@ -202,8 +202,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 	UnloadALSALibrary();
 }
 
@@ -213,20 +213,20 @@
 
 	/* Initialize all variables that we clean on shutdown */
 	LoadALSALibrary();
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
 	/* Set the function pointers */
 	this->OpenAudio = ALSA_OpenAudio;
@@ -435,7 +435,7 @@
 		ALSA_CloseAudio(this);
 		return(-1);
 	}
-	memset(mixbuf, spec->silence, spec->size);
+	SDL_memset(mixbuf, spec->silence, spec->size);
 
 	/* Get the parent process id (we're the parent of the audio thread) */
 	parent = getpid();
--- a/src/audio/amigaos/SDL_ahiaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/amigaos/SDL_ahiaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -74,8 +74,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -87,20 +87,20 @@
 #endif
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
 	/* Set the function pointers */
 	this->OpenAudio = AHI_OpenAudio;
@@ -316,7 +316,7 @@
 	
 	D(bug("Before audio_req memcpy\n"));
 
-	memcpy(audio_req[1],audio_req[0],sizeof(struct AHIRequest));
+	SDL_memcpy(audio_req[1],audio_req[0],sizeof(struct AHIRequest));
 
 	if ( mixbuf[0] == NULL || mixbuf[1] == NULL ) {
 		SDL_OutOfMemory();
@@ -325,8 +325,8 @@
 
 	D(bug("Before mixbuf memset\n"));
 
-	memset(mixbuf[0], spec->silence, spec->size);
-	memset(mixbuf[1], spec->silence, spec->size);
+	SDL_memset(mixbuf[0], spec->silence, spec->size);
+	SDL_memset(mixbuf[1], spec->silence, spec->size);
 
 	current_buffer=0;
 	playing=0;
--- a/src/audio/arts/SDL_artsaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/arts/SDL_artsaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -152,8 +152,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 	UnloadARTSLibrary();
 }
 
@@ -163,20 +163,20 @@
 
 	/* Initialize all variables that we clean on shutdown */
 	LoadARTSLibrary();
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 	stream = 0;
 
 	/* Set the function pointers */
@@ -331,7 +331,7 @@
 	if ( mixbuf == NULL ) {
 		return(-1);
 	}
-	memset(mixbuf, spec->silence, spec->size);
+	SDL_memset(mixbuf, spec->silence, spec->size);
 
 	/* Get the parent process id (we're the parent of the audio thread) */
 	parent = getpid();
--- a/src/audio/baudio/SDL_beaudio.cc	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/baudio/SDL_beaudio.cc	Tue Feb 07 06:59:48 2006 +0000
@@ -54,8 +54,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -63,20 +63,20 @@
 	SDL_AudioDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	device = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	device->OpenAudio = BE_OpenAudio;
@@ -102,7 +102,7 @@
 	SDL_AudioDevice *audio = (SDL_AudioDevice *)device;
 
 	/* Silence the buffer, since it's ours */
-	memset(stream, audio->spec.silence, len);
+	SDL_memset(stream, audio->spec.silence, len);
 
 	/* Only do soemthing if audio is enabled */
 	if ( ! audio->enabled )
@@ -115,7 +115,7 @@
 				(Uint8 *)audio->convert.buf,audio->convert.len);
 			SDL_mutexV(audio->mixer_lock);
 			SDL_ConvertAudio(&audio->convert);
-			memcpy(stream,audio->convert.buf,audio->convert.len_cvt);
+			SDL_memcpy(stream,audio->convert.buf,audio->convert.len_cvt);
 		} else {
 			SDL_mutexP(audio->mixer_lock);
 			(*audio->spec.callback)(audio->spec.userdata,
--- a/src/audio/dart/SDL_dart.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/dart/SDL_dart.c	Tue Feb 07 06:59:48 2006 +0000
@@ -94,7 +94,7 @@
   int rc;
 
   // First thing is to try to open a given DART device!
-  memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
+  SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
   // pszDeviceType should contain the device type in low word, and device ordinal in high word!
   AmpOpenParms.pszDeviceType = (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
 
@@ -138,7 +138,7 @@
   iBufSize = spec->size;
 
   // Now query this device if it supports the given freq/bits/channels!
-  memset(&(_this->hidden->MixSetupParms), 0, sizeof(MCI_MIXSETUP_PARMS));
+  SDL_memset(&(_this->hidden->MixSetupParms), 0, sizeof(MCI_MIXSETUP_PARMS));
   _this->hidden->MixSetupParms.ulBitsPerSample = iBits;
   _this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM;
   _this->hidden->MixSetupParms.ulSamplesPerSec = iFreq;
@@ -170,7 +170,7 @@
   // Ok, the device is initialized.
   // Now we should allocate buffers. For this, we need a place where
   // the buffer descriptors will be:
-  _this->hidden->pMixBuffers = (MCI_MIX_BUFFER *) malloc(sizeof(MCI_MIX_BUFFER)*iNumBufs);
+  _this->hidden->pMixBuffers = (MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER)*iNumBufs);
   if (!(_this->hidden->pMixBuffers))
   { // Not enough memory!
     // Close DART, and exit with error code!
@@ -190,7 +190,7 @@
   if ((rc!=MCIERR_SUCCESS) || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers) || (_this->hidden->BufferParms.ulBufferSize==0))
   { // Could not allocate memory!
     // Close DART, and exit with error code!
-    free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
+    SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
     mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
     SDL_SetError("DART could not allocate buffers");
     return(-1);
@@ -200,18 +200,18 @@
     int i;
     for (i=0; i<iNumBufs; i++)
     {
-      pMixBufferDesc pBufferDesc = (pMixBufferDesc) malloc(sizeof(tMixBufferDesc));;
+      pMixBufferDesc pBufferDesc = (pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
       // Check if this buffer was really allocated by DART
       if ((!(_this->hidden->pMixBuffers[i].pBuffer)) || (!pBufferDesc))
       { // Wrong buffer!
         // Close DART, and exit with error code!
         // Free buffer descriptions
         { int j;
-          for (j=0; j<i; j++) free((void *)(_this->hidden->pMixBuffers[j].ulUserParm));
+          for (j=0; j<i; j++) SDL_free((void *)(_this->hidden->pMixBuffers[j].ulUserParm));
         }
         // and cleanup
         mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
-        free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
+        SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
         mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
         SDL_SetError("Error at internal buffer check");
         return(-1);
@@ -224,7 +224,7 @@
       _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
                                             // audio data, but as we will continously send
                                             // audio data, there will be no end.:)
-      memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence, iBufSize);
+      SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence, iBufSize);
     }
   }
   _this->hidden->iNextFreeBuffer = 0;
@@ -235,10 +235,10 @@
     // Could not create event semaphore!
     {
       int i;
-      for (i=0; i<iNumBufs; i++) free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
+      for (i=0; i<iNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
     }
     mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
-    free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
+    SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
     mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
     SDL_SetError("Could not create event semaphore");
     return(-1);
@@ -363,14 +363,14 @@
   // Free memory of buffer descriptions
   {
     int i;
-    for (i=0; i<_this->hidden->iCurrNumBufs; i++) free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
+    for (i=0; i<_this->hidden->iCurrNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
   }
 
   // Deallocate buffers
   rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
 
   // Free bufferlist
-  free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
+  SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
 
   // Close dart
   rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT, &(GenericParms), 0);
@@ -385,8 +385,8 @@
 
 void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-  free(device->hidden);
-  free(device);
+  SDL_free(device->hidden);
+  SDL_free(device);
 }
 
 SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -394,21 +394,21 @@
   SDL_AudioDevice *this;
 
   /* Initialize all variables that we clean on shutdown */
-  this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+  this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
   if ( this )
   {
-    memset(this, 0, (sizeof *this));
+    SDL_memset(this, 0, (sizeof *this));
     this->hidden = (struct SDL_PrivateAudioData *)
-      malloc((sizeof *this->hidden));
+      SDL_malloc((sizeof *this->hidden));
   }
   if ( (this == NULL) || (this->hidden == NULL) )
   {
     SDL_OutOfMemory();
     if ( this )
-      free(this);
+      SDL_free(this);
     return(0);
   }
-  memset(this->hidden, 0, (sizeof *this->hidden));
+  SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
   /* Set the function pointers */
   this->OpenAudio = DART_OpenAudio;
--- a/src/audio/dc/SDL_dcaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/dc/SDL_dcaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -60,8 +60,8 @@
 
 static void DCAUD_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *DCAUD_CreateDevice(int devindex)
@@ -69,20 +69,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
 	/* Set the function pointers */
 	this->OpenAudio = DCAUD_OpenAudio;
@@ -229,7 +229,7 @@
 	if ( this->hidden->mixbuf == NULL ) {
 		return(-1);
 	}
-	memset(this->hidden->mixbuf, spec->silence, spec->size);
+	SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
 	this->hidden->leftpos = 0x11000;
 	this->hidden->rightpos = 0x11000+spec->size;
 	this->hidden->playing = 0;
--- a/src/audio/disk/SDL_diskaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/disk/SDL_diskaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -62,7 +62,7 @@
 
 static const char *DISKAUD_GetOutputFilename(void)
 {
-    const char *envr = getenv(DISKENVR_OUTFILE);
+    const char *envr = SDL_getenv(DISKENVR_OUTFILE);
     return((envr != NULL) ? envr : DISKDEFAULT_OUTFILE);
 }
 
@@ -75,10 +75,10 @@
     int exists = 0;
     struct stat statbuf;
     const char *fname = DISKAUD_GetOutputFilename();
-	const char *envr = getenv("SDL_AUDIODRIVER");
+	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
 	available = 0;
 
-	if ((envr) && (strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
+	if ((envr) && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
 		if (stat(fname, &statbuf) == 0)
 			exists = 1;
 
@@ -93,8 +93,8 @@
 	}
 	return(available);
 #else
-	const char *envr = getenv("SDL_AUDIODRIVER");
-	if ((envr) && (strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
+	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
+	if ((envr) && (SDL_strcmp(envr, DISKAUD_DRIVER_NAME) == 0)) {
 		return(1);
 	}
 
@@ -104,8 +104,8 @@
 
 static void DISKAUD_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *DISKAUD_CreateDevice(int devindex)
@@ -114,22 +114,22 @@
     const char *envr;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
-    envr = getenv(DISKENVR_WRITEDELAY);
+    envr = SDL_getenv(DISKENVR_WRITEDELAY);
     this->hidden->write_delay = (envr) ? atoi(envr) : DISKDEFAULT_WRITEDELAY;
 
 	/* Set the function pointers */
@@ -216,7 +216,7 @@
 	if ( this->hidden->mixbuf == NULL ) {
 		return(-1);
 	}
-	memset(this->hidden->mixbuf, spec->silence, spec->size);
+	SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
 
 	/* We're ready to rock and roll. :-) */
 	return(0);
--- a/src/audio/dma/SDL_dmaaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/dma/SDL_dmaaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -93,8 +93,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -102,20 +102,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 	audio_fd = -1;
 
 	/* Set the function pointers */
@@ -428,11 +428,11 @@
 		dma_buf = NULL;
 		return(-1);
 	}
-	memset(dma_buf, spec->silence, dma_len);
+	SDL_memset(dma_buf, spec->silence, dma_len);
 
 	/* Check to see if we need to use select() workaround */
 	{ char *workaround;
-		workaround = getenv("SDL_DSP_NOSELECT");
+		workaround = SDL_getenv("SDL_DSP_NOSELECT");
 		if ( workaround ) {
 			frame_ticks = (float)(spec->samples*1000)/spec->freq;
 			next_frame = SDL_GetTicks()+frame_ticks;
--- a/src/audio/dmedia/SDL_irixaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/dmedia/SDL_irixaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -62,8 +62,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -71,20 +71,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
 	/* Set the function pointers */
 	this->OpenAudio = AL_OpenAudio;
@@ -211,7 +211,7 @@
 		SDL_OutOfMemory();
 		return(-1);
 	}
-	memset(mixbuf, spec->silence, spec->size);
+	SDL_memset(mixbuf, spec->silence, spec->size);
 
 	/* We're ready to rock and roll. :-) */
 	return(0);
--- a/src/audio/dsp/SDL_dspaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/dsp/SDL_dspaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -82,8 +82,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -91,20 +91,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 	audio_fd = -1;
 
 	/* Set the function pointers */
@@ -322,7 +322,7 @@
 		DSP_CloseAudio(this);
 		return(-1);
 	}
-	memset(mixbuf, spec->silence, spec->size);
+	SDL_memset(mixbuf, spec->silence, spec->size);
 
 	/* Get the parent process id (we're the parent of the audio thread) */
 	parent = getpid();
--- a/src/audio/esd/SDL_esdaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/esd/SDL_esdaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -142,8 +142,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 	UnloadESDLibrary();
 }
 
@@ -153,20 +153,20 @@
 
 	/* Initialize all variables that we clean on shutdown */
 	LoadESDLibrary();
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 	audio_fd = -1;
 
 	/* Set the function pointers */
@@ -261,7 +261,7 @@
 	fp = fopen(temp, "r");
 	if ( fp != NULL ) {
 		if ( fgets(temp, sizeof(temp)-1, fp) ) {
-			progname = strrchr(temp, '/');
+			progname = SDL_strrchr(temp, '/');
 			if ( progname == NULL ) {
 				progname = temp;
 			} else {
@@ -318,7 +318,7 @@
 	if ( mixbuf == NULL ) {
 		return(-1);
 	}
-	memset(mixbuf, spec->silence, spec->size);
+	SDL_memset(mixbuf, spec->silence, spec->size);
 
 	/* Get the parent process id (we're the parent of the audio thread) */
 	parent = getpid();
--- a/src/audio/macosx/SDL_coreaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/macosx/SDL_coreaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -52,8 +52,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -61,20 +61,20 @@
     SDL_AudioDevice *this;
 
     /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+    this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-        memset(this, 0, (sizeof *this));
+        SDL_memset(this, 0, (sizeof *this));
         this->hidden = (struct SDL_PrivateAudioData *)
-                malloc((sizeof *this->hidden));
+                SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
         SDL_OutOfMemory();
         if ( this ) {
-            free(this);
+            SDL_free(this);
         }
         return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
     /* Set the function pointers */
     this->OpenAudio = Core_OpenAudio;
@@ -106,7 +106,7 @@
 
     /* Only do anything if audio is enabled and not paused */
     if ( ! this->enabled || this->paused ) {
-        memset(ioData->mData, this->spec.silence, ioData->mDataByteSize);
+        SDL_memset(ioData->mData, this->spec.silence, ioData->mDataByteSize);
         return 0;
     }
     
@@ -121,7 +121,7 @@
     while (remaining > 0) {
         if (bufferOffset >= bufferSize) {
             /* Generate the data */
-            memset(buffer, this->spec.silence, bufferSize);
+            SDL_memset(buffer, this->spec.silence, bufferSize);
             SDL_mutexP(this->mixer_lock);
             (*this->spec.callback)(this->spec.userdata,
                         buffer, bufferSize);
@@ -132,7 +132,7 @@
         len = bufferSize - bufferOffset;
         if (len > remaining)
             len = remaining;
-        memcpy(ptr, buffer + bufferOffset, len);
+        SDL_memcpy(ptr, buffer + bufferOffset, len);
         ptr += len;
         remaining -= len;
         bufferOffset += len;
@@ -189,7 +189,7 @@
         return;
     }
     
-    free(buffer);
+    SDL_free(buffer);
 }
 
 #define CHECK_RESULT(msg) \
@@ -269,7 +269,7 @@
     
     /* Allocate a sample buffer */
     bufferOffset = bufferSize = this->spec.size;
-    buffer = malloc(bufferSize);
+    buffer = SDL_malloc(bufferSize);
     assert(buffer);
     
     /* Finally, start processing of the audio unit */
--- a/src/audio/macrom/SDL_romaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/macrom/SDL_romaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -66,8 +66,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -75,20 +75,20 @@
     SDL_AudioDevice *this;
 
     /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+    this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-        memset(this, 0, (sizeof *this));
+        SDL_memset(this, 0, (sizeof *this));
         this->hidden = (struct SDL_PrivateAudioData *)
-                malloc((sizeof *this->hidden));
+                SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
         SDL_OutOfMemory();
         if ( this ) {
-            free(this);
+            SDL_free(this);
         }
         return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
     /* Set the function pointers */
     this->OpenAudio   = Mac_OpenAudio;
@@ -135,7 +135,7 @@
             if ( audio->convert.len_cvt != audio->spec.size ) {
                 /* Uh oh... probably crashes here */;
             }
-            memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
+            SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
         } else {
             audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size);
         }
@@ -267,7 +267,7 @@
    }
    
    /* Create the sound manager channel */
-    channel = (SndChannelPtr)malloc(sizeof(*channel));
+    channel = (SndChannelPtr)SDL_malloc(sizeof(*channel));
     if ( channel == NULL ) {
         SDL_OutOfMemory();
         return(-1);
@@ -281,7 +281,7 @@
     channel->qLength = 128;
     if ( SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr ) {
         SDL_SetError("Unable to create audio channel");
-        free(channel);
+        SDL_free(channel);
         channel = NULL;
         return(-1);
     }
@@ -311,7 +311,7 @@
    
     for ( i=0; i<2; ++i ) {
         if ( buffer[i] ) {
-            free(buffer[i]);
+            SDL_free(buffer[i]);
             buffer[i] = NULL;
         }
     }
@@ -355,7 +355,7 @@
                 /* Uh oh... probably crashes here */;
             }
 #endif
-            memcpy(newbuf->dbSoundData, audio->convert.buf,
+            SDL_memcpy(newbuf->dbSoundData, audio->convert.buf,
                             audio->convert.len_cvt);
         } else {
             audio->spec.callback(audio->spec.userdata,
@@ -400,7 +400,7 @@
     }
     for ( i=0; i<2; ++i ) {
         if ( audio_buf[i] ) {
-            free(audio_buf[i]);
+            SDL_free(audio_buf[i]);
             audio_buf[i] = NULL;
         }
     }
@@ -435,7 +435,7 @@
     SDL_CalculateAudioSpec(spec);
 
     /* initialize the double-back header */
-    memset(&audio_dbh, 0, sizeof(audio_dbh));
+    SDL_memset(&audio_dbh, 0, sizeof(audio_dbh));
     doubleBackProc = NewSndDoubleBackProc (sndDoubleBackProc);
     sample_bits = spec->size / spec->samples / spec->channels * 8;
     
@@ -467,7 +467,7 @@
     }
 
     /* Create the sound manager channel */
-    channel = (SndChannelPtr)malloc(sizeof(*channel));
+    channel = (SndChannelPtr)SDL_malloc(sizeof(*channel));
     if ( channel == NULL ) {
         SDL_OutOfMemory();
         return(-1);
@@ -481,7 +481,7 @@
     channel->qLength = 128;
     if ( SndNewChannel(&channel, sampledSynth, initOptions, 0L) != noErr ) {
         SDL_SetError("Unable to create audio channel");
-        free(channel);
+        SDL_free(channel);
         channel = NULL;
         return(-1);
     }
--- a/src/audio/mint/SDL_mintaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -63,7 +63,7 @@
 	SDL_AudioDevice *audio = SDL_MintAudio_device;
 
  	buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
-	memset(buffer, audio->spec.silence, audio->spec.size);
+	SDL_memset(buffer, audio->spec.silence, audio->spec.size);
 
 	if (audio->paused)
 		return;
@@ -76,11 +76,11 @@
 		} else {
 			silence = 0;
 		}
-		memset(audio->convert.buf, silence, audio->convert.len);
+		SDL_memset(audio->convert.buf, silence, audio->convert.len);
 		audio->spec.callback(audio->spec.userdata,
 			(Uint8 *)audio->convert.buf,audio->convert.len);
 		SDL_ConvertAudio(&audio->convert);
-		memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
+		SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
 	} else {
 		audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size);
 	}
@@ -106,7 +106,7 @@
 	/* Put all following ones farer */
 	if (MINTAUDIO_freqcount>0) {
 		for (i=MINTAUDIO_freqcount; i>p; i--) {
-			memcpy(&MINTAUDIO_frequencies[i], &MINTAUDIO_frequencies[i-1], sizeof(mint_frequency_t));
+			SDL_memcpy(&MINTAUDIO_frequencies[i], &MINTAUDIO_frequencies[i-1], sizeof(mint_frequency_t));
 		}
 	}
 
--- a/src/audio/mint/SDL_mintaudio_dma8.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_dma8.c	Tue Feb 07 06:59:48 2006 +0000
@@ -81,10 +81,10 @@
 
 static int Audio_Available(void)
 {
-	const char *envr = getenv("SDL_AUDIODRIVER");
+	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
 
 	/* Check if user asked a different audio driver */
-	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
+	if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
 		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
 		return 0;
 	}
@@ -121,8 +121,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -130,20 +130,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-        memset(this, 0, (sizeof *this));
+        SDL_memset(this, 0, (sizeof *this));
         this->hidden = (struct SDL_PrivateAudioData *)
-                malloc((sizeof *this->hidden));
+                SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
         SDL_OutOfMemory();
         if ( this ) {
-            free(this);
+            SDL_free(this);
         }
         return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
     /* Set the function pointers */
     this->OpenAudio   = Mint_OpenAudio;
@@ -347,7 +347,7 @@
 	}
 	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
 	SDL_MintAudio_numbuf=0;
-	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
+	SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
 	SDL_MintAudio_audiosize = spec->size;
 	SDL_MintAudio_mutex = 0;
 
--- a/src/audio/mint/SDL_mintaudio_gsxb.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Tue Feb 07 06:59:48 2006 +0000
@@ -85,10 +85,10 @@
 
 static int Audio_Available(void)
 {
-	const char *envr = getenv("SDL_AUDIODRIVER");
+	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
 
 	/* Check if user asked a different audio driver */
-	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
+	if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
 		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
 		return(0);
 	}
@@ -127,8 +127,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -136,20 +136,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-        memset(this, 0, (sizeof *this));
+        SDL_memset(this, 0, (sizeof *this));
         this->hidden = (struct SDL_PrivateAudioData *)
-                malloc((sizeof *this->hidden));
+                SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
         SDL_OutOfMemory();
         if ( this ) {
-            free(this);
+            SDL_free(this);
         }
         return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
     /* Set the function pointers */
     this->OpenAudio   = Mint_OpenAudio;
@@ -384,7 +384,7 @@
 	}
 	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
 	SDL_MintAudio_numbuf=0;
-	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
+	SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
 	SDL_MintAudio_audiosize = spec->size;
 	SDL_MintAudio_mutex = 0;
 
--- a/src/audio/mint/SDL_mintaudio_mcsn.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Tue Feb 07 06:59:48 2006 +0000
@@ -84,7 +84,7 @@
 static int Audio_Available(void)
 {
 	unsigned long dummy;
-	const char *envr = getenv("SDL_AUDIODRIVER");
+	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
 
 	SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND);
 
@@ -94,7 +94,7 @@
 	}
 
 	/* Check if user asked a different audio driver */
-	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
+	if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
 		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
 		return(0);
 	}
@@ -141,8 +141,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -150,20 +150,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-        memset(this, 0, (sizeof *this));
+        SDL_memset(this, 0, (sizeof *this));
         this->hidden = (struct SDL_PrivateAudioData *)
-                malloc((sizeof *this->hidden));
+                SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
         SDL_OutOfMemory();
         if ( this ) {
-            free(this);
+            SDL_free(this);
         }
         return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
     /* Set the function pointers */
     this->OpenAudio   = Mint_OpenAudio;
@@ -388,7 +388,7 @@
 	}
 	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
 	SDL_MintAudio_numbuf=0;
-	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
+	SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
 	SDL_MintAudio_audiosize = spec->size;
 	SDL_MintAudio_mutex = 0;
 
--- a/src/audio/mint/SDL_mintaudio_stfa.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_stfa.c	Tue Feb 07 06:59:48 2006 +0000
@@ -89,10 +89,10 @@
 
 static int Audio_Available(void)
 {
-	const char *envr = getenv("SDL_AUDIODRIVER");
+	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
 
 	/* Check if user asked a different audio driver */
-	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
+	if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
 		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
 		return(0);
 	}
@@ -121,8 +121,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -130,20 +130,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-        memset(this, 0, (sizeof *this));
+        SDL_memset(this, 0, (sizeof *this));
         this->hidden = (struct SDL_PrivateAudioData *)
-                malloc((sizeof *this->hidden));
+                SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
         SDL_OutOfMemory();
         if ( this ) {
-            free(this);
+            SDL_free(this);
         }
         return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
     /* Set the function pointers */
     this->OpenAudio   = Mint_OpenAudio;
@@ -308,7 +308,7 @@
 	}
 	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
 	SDL_MintAudio_numbuf=0;
-	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
+	SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
 	SDL_MintAudio_audiosize = spec->size;
 	SDL_MintAudio_mutex = 0;
 
--- a/src/audio/mint/SDL_mintaudio_xbios.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_xbios.c	Tue Feb 07 06:59:48 2006 +0000
@@ -84,7 +84,7 @@
 static int Audio_Available(void)
 {
 	unsigned long dummy;
-	const char *envr = getenv("SDL_AUDIODRIVER");
+	const char *envr = SDL_getenv("SDL_AUDIODRIVER");
 
 	SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND);
 
@@ -94,7 +94,7 @@
 	}
 
 	/* Check if user asked a different audio driver */
-	if ((envr) && (strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
+	if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME)!=0)) {
 		DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
 		return(0);
 	}
@@ -124,8 +124,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -133,20 +133,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-        memset(this, 0, (sizeof *this));
+        SDL_memset(this, 0, (sizeof *this));
         this->hidden = (struct SDL_PrivateAudioData *)
-                malloc((sizeof *this->hidden));
+                SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
         SDL_OutOfMemory();
         if ( this ) {
-            free(this);
+            SDL_free(this);
         }
         return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
     /* Set the function pointers */
     this->OpenAudio   = Mint_OpenAudio;
@@ -285,7 +285,7 @@
 		DEBUG_PRINT((DEBUG_NAME "Not enough memory for the measure\n"));
 		return;
 	}
-	memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE);
+	SDL_memset(buffer, 0, SIZE_BUF_CLOCK_MEASURE);
 
 	Buffoper(0);
 	Settracks(0,0);
@@ -477,7 +477,7 @@
 	}
 	SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size ;
 	SDL_MintAudio_numbuf=0;
-	memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
+	SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size *2);
 	SDL_MintAudio_audiosize = spec->size;
 	SDL_MintAudio_mutex = 0;
 
--- a/src/audio/mme/SDL_mmeaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/mme/SDL_mmeaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -43,10 +43,10 @@
 {
     if ( device ) {
 	if ( device->hidden ) {
-	    free(device->hidden);
+	    SDL_free(device->hidden);
 	    device->hidden = NULL;
 	}
-	free(device);
+	SDL_free(device);
 	device = NULL;
     }
 }
@@ -56,19 +56,19 @@
     SDL_AudioDevice *this;
 
 /* Initialize all variables that we clean on shutdown */
-    this = malloc(sizeof(SDL_AudioDevice));
+    this = SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-	memset(this, 0, (sizeof *this));
-	this->hidden = malloc((sizeof *this->hidden));
+	SDL_memset(this, 0, (sizeof *this));
+	this->hidden = SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
 	SDL_OutOfMemory();
 	if ( this ) {
-	    free(this);
+	    SDL_free(this);
 	}
 	return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
     /* Set the function pointers */
     this->OpenAudio       =       MME_OpenAudio;
     this->WaitAudio       =       MME_WaitAudio;
@@ -92,7 +92,7 @@
     char errbuf[MAXERRORLENGTH];
 
     sprintf(errbuf, "%s: ", function);
-    len = strlen(errbuf);
+    len = SDL_strlen(errbuf);
     waveOutGetErrorText(code, errbuf+len, MAXERRORLENGTH-len);
     SDL_SetError("%s",errbuf);
 }
--- a/src/audio/nas/SDL_nasaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/nas/SDL_nasaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -66,8 +66,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -75,20 +75,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
 	/* Set the function pointers */
 	this->OpenAudio = NAS_OpenAudio;
@@ -293,7 +293,7 @@
 	if ( this->hidden->mixbuf == NULL ) {
 		return(-1);
 	}
-	memset(this->hidden->mixbuf, spec->silence, spec->size);
+	SDL_memset(this->hidden->mixbuf, spec->silence, spec->size);
 
 	/* Get the parent process id (we're the parent of the audio thread) */
 	this->hidden->parent = getpid();
--- a/src/audio/nto/SDL_nto_audio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/nto/SDL_nto_audio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -94,7 +94,7 @@
 
     for (it=0; it<QSA_WA_CARDS; it++)
     {
-       if (strcmp(buggycards[it].cardname, scardname)==0)
+       if (SDL_strcmp(buggycards[it].cardname, scardname)==0)
        {
           if (buggycards[it].bugtype==checkfor)
           {
@@ -120,7 +120,7 @@
 /* PCM transfer channel parameters initialize function */
 static void NTO_InitAudioParams(snd_pcm_channel_params_t* cpars)
 {
-    memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
+    SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
 
     cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
     cpars->mode = SND_PCM_MODE_BLOCK;
@@ -172,11 +172,11 @@
 {
     if ((device)&&(device->hidden))
     {
-        free(device->hidden);
+        SDL_free(device->hidden);
     }
     if (device)
     {
-        free(device);
+        SDL_free(device);
     }
 }
 
@@ -185,22 +185,22 @@
     SDL_AudioDevice *this;
 
     /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+    this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if (this)
     {
-        memset(this, 0, sizeof(SDL_AudioDevice));
-        this->hidden = (struct SDL_PrivateAudioData *)malloc(sizeof(struct SDL_PrivateAudioData));
+        SDL_memset(this, 0, sizeof(SDL_AudioDevice));
+        this->hidden = (struct SDL_PrivateAudioData *)SDL_malloc(sizeof(struct SDL_PrivateAudioData));
     }
     if ((this == NULL) || (this->hidden == NULL))
     {
         SDL_OutOfMemory();
         if (this)
         {
-            free(this);
+            SDL_free(this);
 	}
         return (0);
     }
-    memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
+    SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
     audio_handle = NULL;
 
     /* Set the function pointers */
@@ -280,7 +280,7 @@
             {
                 if ((errno == EINVAL) || (errno == EIO))
                 {
-                    memset(&cstatus, 0, sizeof(cstatus));
+                    SDL_memset(&cstatus, 0, sizeof(cstatus));
                     cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
                     if ((rval = snd_pcm_plugin_status(audio_handle, &cstatus)) < 0)
                     {
@@ -455,7 +455,7 @@
     }
 
     /* Make sure channel is setup right one last time */
-    memset(&csetup, 0x00, sizeof(csetup));
+    SDL_memset(&csetup, 0x00, sizeof(csetup));
     csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
     if (snd_pcm_plugin_setup(audio_handle, &csetup) < 0)
     {
@@ -483,7 +483,7 @@
         SDL_SetError("NTO_OpenAudio(): pcm buffer allocation failed\n");
         return (-1);
     }
-    memset(pcm_buf, spec->silence, pcm_len);
+    SDL_memset(pcm_buf, spec->silence, pcm_len);
 
     /* get the file descriptor */
     if ((audio_fd = snd_pcm_file_descriptor(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0)
--- a/src/audio/openbsd/SDL_openbsdaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/openbsd/SDL_openbsdaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -95,8 +95,8 @@
 static void
 Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
 }
 
 static SDL_AudioDevice
@@ -105,18 +105,18 @@
     SDL_AudioDevice *this;
 
     /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice*)malloc(sizeof(SDL_AudioDevice));
+    this = (SDL_AudioDevice*)SDL_malloc(sizeof(SDL_AudioDevice));
     if(this) {
-	memset(this, 0, (sizeof *this));
+	SDL_memset(this, 0, (sizeof *this));
 	this->hidden =
-	    (struct SDL_PrivateAudioData*)malloc((sizeof *this->hidden));
+	    (struct SDL_PrivateAudioData*)SDL_malloc((sizeof *this->hidden));
     }
     if((this == NULL) || (this->hidden == NULL)) {
 	SDL_OutOfMemory();
-	if(this) free(this);
+	if(this) SDL_free(this);
 	return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
     audio_fd = -1;
 
     /* Set the function pointers */
@@ -397,7 +397,7 @@
     if(mixbuf == NULL) {
 	return(-1);
     }
-    memset(mixbuf, spec->silence, spec->size);
+    SDL_memset(mixbuf, spec->silence, spec->size);
     
     /* Get the parent process id (we're the parent of the audio thread) */
     parent = getpid();
--- a/src/audio/paudio/SDL_paudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/paudio/SDL_paudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -82,8 +82,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -91,20 +91,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 	audio_fd = -1;
 
 	/* Set the function pointers */
@@ -457,7 +457,7 @@
 	if ( mixbuf == NULL ) {
 		return -1;
 	}
-	memset(mixbuf, spec->silence, spec->size);
+	SDL_memset(mixbuf, spec->silence, spec->size);
 
 	/*
 	 * Set some paramters: full volume, first speaker that we can find.
@@ -498,7 +498,7 @@
 
         /* Check to see if we need to use select() workaround */
         { char *workaround;
-                workaround = getenv("SDL_DSP_NOSELECT");
+                workaround = SDL_getenv("SDL_DSP_NOSELECT");
                 if ( workaround ) {
                         frame_ticks = (float)(spec->samples*1000)/spec->freq;
                         next_frame = SDL_GetTicks()+frame_ticks;
--- a/src/audio/sun/SDL_sunaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/sun/SDL_sunaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -75,8 +75,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -84,20 +84,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 	audio_fd = -1;
 
 	/* Set the function pointers */
@@ -236,7 +236,7 @@
 		mixbuf = NULL;
 	}
 	if ( ulaw_buf != NULL ) {
-		free(ulaw_buf);
+		SDL_free(ulaw_buf);
 		ulaw_buf = NULL;
 	}
 	close(audio_fd);
@@ -349,7 +349,7 @@
 	        spec->freq = desired_freq;
 		fragsize = (spec->samples*1000)/(spec->freq/8);
 		frequency = 8;
-		ulaw_buf = (Uint8 *)malloc(fragsize);
+		ulaw_buf = (Uint8 *)SDL_malloc(fragsize);
 		if ( ulaw_buf == NULL ) {
 			SDL_OutOfMemory();
 			return(-1);
@@ -375,7 +375,7 @@
 		SDL_OutOfMemory();
 		return(-1);
 	}
-	memset(mixbuf, spec->silence, spec->size);
+	SDL_memset(mixbuf, spec->silence, spec->size);
 
 	/* We're ready to rock and roll. :-) */
 	return(0);
--- a/src/audio/ums/SDL_umsaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/ums/SDL_umsaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -84,11 +84,11 @@
 
 static void Audio_DeleteDevice(_THIS)
 {
-    if(this->hidden->playbuf._buffer) free(this->hidden->playbuf._buffer);
-    if(this->hidden->fillbuf._buffer) free(this->hidden->fillbuf._buffer);
+    if(this->hidden->playbuf._buffer) SDL_free(this->hidden->playbuf._buffer);
+    if(this->hidden->fillbuf._buffer) SDL_free(this->hidden->fillbuf._buffer);
     _somFree( this->hidden->umsdev );
-    free(this->hidden);
-    free(this);
+    SDL_free(this->hidden);
+    SDL_free(this);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -99,19 +99,19 @@
      * Allocate and initialize management storage and private management
      * storage for this SDL-using library.
      */
-    this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+    this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
     if ( this ) {
-        memset(this, 0, (sizeof *this));
-        this->hidden = (struct SDL_PrivateAudioData *)malloc((sizeof *this->hidden));
+        SDL_memset(this, 0, (sizeof *this));
+        this->hidden = (struct SDL_PrivateAudioData *)SDL_malloc((sizeof *this->hidden));
     }
     if ( (this == NULL) || (this->hidden == NULL) ) {
         SDL_OutOfMemory();
         if ( this ) {
-            free(this);
+            SDL_free(this);
         }
         return(0);
     }
-    memset(this->hidden, 0, (sizeof *this->hidden));
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 #ifdef DEBUG_AUDIO
     fprintf(stderr, "Creating UMS Audio device\n");
 #endif
@@ -204,9 +204,9 @@
     while(samplesToWrite>0);
 
     SDL_LockAudio();
-    memcpy( &swpbuf,                &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer) );
-    memcpy( &this->hidden->playbuf, &this->hidden->fillbuf, sizeof(UMSAudioTypes_Buffer) );
-    memcpy( &this->hidden->fillbuf, &swpbuf,                sizeof(UMSAudioTypes_Buffer) );
+    SDL_memcpy( &swpbuf,                &this->hidden->playbuf, sizeof(UMSAudioTypes_Buffer) );
+    SDL_memcpy( &this->hidden->playbuf, &this->hidden->fillbuf, sizeof(UMSAudioTypes_Buffer) );
+    SDL_memcpy( &this->hidden->fillbuf, &swpbuf,                sizeof(UMSAudioTypes_Buffer) );
     SDL_UnlockAudio();
 
 #ifdef DEBUG_AUDIO
@@ -330,10 +330,10 @@
 
     this->hidden->playbuf._length  = 0;
     this->hidden->playbuf._maximum = spec->size;
-    this->hidden->playbuf._buffer  = (unsigned char*)malloc(spec->size);
+    this->hidden->playbuf._buffer  = (unsigned char*)SDL_malloc(spec->size);
     this->hidden->fillbuf._length  = 0;
     this->hidden->fillbuf._maximum = spec->size;
-    this->hidden->fillbuf._buffer  = (unsigned char*)malloc(spec->size);
+    this->hidden->fillbuf._buffer  = (unsigned char*)SDL_malloc(spec->size);
 
     rc = UADSetBitsPerSample(this,  bitsPerSample );
     rc = UADSetDMABufferSize(this,  frag_spec, &outBufSize );
--- a/src/audio/windib/SDL_dibaudio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/windib/SDL_dibaudio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -55,8 +55,8 @@
 
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -64,20 +64,20 @@
 	SDL_AudioDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
 	/* Set the function pointers */
 	this->OpenAudio = DIB_OpenAudio;
@@ -125,8 +125,8 @@
 	wchar_t werrbuf[MAXERRORLENGTH];
 #endif
 
-	snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
-	len = strlen(errbuf);
+	SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
+	len = SDL_strlen(errbuf);
 
 #ifdef _WIN32_WCE
 	/* UNICODE version */
@@ -213,7 +213,7 @@
 	}
 	/* Free raw mixing buffer */
 	if ( mixbuf != NULL ) {
-		free(mixbuf);
+		SDL_free(mixbuf);
 		mixbuf = NULL;
 	}
 }
@@ -232,7 +232,7 @@
 	mixbuf = NULL;
 
 	/* Set basic WAVE format parameters */
-	memset(&waveformat, 0, sizeof(waveformat));
+	SDL_memset(&waveformat, 0, sizeof(waveformat));
 	waveformat.wFormatTag = WAVE_FORMAT_PCM;
 
 	/* Determine the audio parameters from the AudioSpec */
@@ -299,13 +299,13 @@
 	}
 
 	/* Create the sound buffers */
-	mixbuf = (Uint8 *)malloc(NUM_BUFFERS*spec->size);
+	mixbuf = (Uint8 *)SDL_malloc(NUM_BUFFERS*spec->size);
 	if ( mixbuf == NULL ) {
 		SDL_SetError("Out of memory");
 		return(-1);
 	}
 	for ( i = 0; i < NUM_BUFFERS; ++i ) {
-		memset(&wavebuf[i], 0, sizeof(wavebuf[i]));
+		SDL_memset(&wavebuf[i], 0, sizeof(wavebuf[i]));
 		wavebuf[i].lpData = (LPSTR) &mixbuf[i*spec->size];
 		wavebuf[i].dwBufferLength = spec->size;
 		wavebuf[i].dwFlags = WHDR_DONE;
--- a/src/audio/windx5/SDL_dx5audio.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/audio/windx5/SDL_dx5audio.c	Tue Feb 07 06:59:48 2006 +0000
@@ -133,8 +133,8 @@
 static void Audio_DeleteDevice(SDL_AudioDevice *device)
 {
 	DX5_Unload();
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
@@ -147,20 +147,20 @@
 	}
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+	this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateAudioData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 
 	/* Set the function pointers */
 	this->OpenAudio = DX5_OpenAudio;
@@ -223,13 +223,13 @@
 			error = "Function not supported";
 			break;
 		default:
-			snprintf(errbuf, SDL_arraysize(errbuf),
+			SDL_snprintf(errbuf, SDL_arraysize(errbuf),
 			         "%s: Unknown DirectSound error: 0x%x",
 								function, code);
 			break;
 	}
 	if ( ! errbuf[0] ) {
-		snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
+		SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
 	}
 	SDL_SetError("%s", errbuf);
 	return;
@@ -386,7 +386,7 @@
 	/* Wait for the playing chunk to finish */
 	stream = this->GetAudioBuf(this);
 	if ( stream != NULL ) {
-		memset(stream, silence, mixlen);
+		SDL_memset(stream, silence, mixlen);
 		this->PlayAudio(this);
 	}
 	this->WaitAudio(this);
@@ -435,7 +435,7 @@
 	}
 
 	/* Try to create the primary buffer */
-	memset(&format, 0, sizeof(format));
+	SDL_memset(&format, 0, sizeof(format));
 	format.dwSize = sizeof(format);
 	format.dwFlags=(DSBCAPS_PRIMARYBUFFER|DSBCAPS_GETCURRENTPOSITION2);
 	format.dwFlags |= DSBCAPS_STICKYFOCUS;
@@ -451,7 +451,7 @@
 	}
 
 	/* Check the size of the fragment buffer */
-	memset(&caps, 0, sizeof(caps));
+	SDL_memset(&caps, 0, sizeof(caps));
 	caps.dwSize = sizeof(caps);
 	result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps);
 	if ( result != DS_OK ) {
@@ -516,7 +516,7 @@
 	}
 
 	/* Try to create the secondary buffer */
-	memset(&format, 0, sizeof(format));
+	SDL_memset(&format, 0, sizeof(format));
 	format.dwSize = sizeof(format);
 	format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
 #ifdef USE_POSITION_NOTIFY
@@ -550,9 +550,9 @@
 	                                 DSBLOCK_ENTIREBUFFER);
 	if ( result == DS_OK ) {
 		if ( wavefmt->wBitsPerSample == 8 ) {
-			memset(pvAudioPtr1, 0x80, dwAudioBytes1);
+			SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1);
 		} else {
-			memset(pvAudioPtr1, 0x00, dwAudioBytes1);
+			SDL_memset(pvAudioPtr1, 0x00, dwAudioBytes1);
 		}
 		IDirectSoundBuffer_Unlock(*sndbuf,
 		                          (LPVOID)pvAudioPtr1, dwAudioBytes1,
@@ -584,7 +584,7 @@
 	}
 
 	/* Allocate the notify structures */
-	notify_positions = (DSBPOSITIONNOTIFY *)malloc(NUM_BUFFERS*
+	notify_positions = (DSBPOSITIONNOTIFY *)SDL_malloc(NUM_BUFFERS*
 					sizeof(*notify_positions));
 	if ( notify_positions == NULL ) {
 		goto done;
@@ -620,7 +620,7 @@
 	WAVEFORMATEX waveformat;
 
 	/* Set basic WAVE format parameters */
-	memset(&waveformat, 0, sizeof(waveformat));
+	SDL_memset(&waveformat, 0, sizeof(waveformat));
 	waveformat.wFormatTag = WAVE_FORMAT_PCM;
 
 	/* Determine the audio parameters from the AudioSpec */
--- a/src/cdrom/SDL_cdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/SDL_cdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -117,15 +117,15 @@
 		SDL_SetError("Invalid CD-ROM drive index");
 		return(NULL);
 	}
-	cdrom = (SDL_CD *)malloc(sizeof(*cdrom));
+	cdrom = (SDL_CD *)SDL_malloc(sizeof(*cdrom));
 	if ( cdrom == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(cdrom, 0, sizeof(*cdrom));
+	SDL_memset(cdrom, 0, sizeof(*cdrom));
 	cdrom->id = SDL_CDcaps.Open(drive);
 	if ( cdrom->id < 0 ) {
-		free(cdrom);
+		SDL_free(cdrom);
 		return(NULL);
 	}
 	default_cdrom = cdrom;
@@ -332,7 +332,7 @@
 		return;
 	}
 	SDL_CDcaps.Close(cdrom);
-	free(cdrom);
+	SDL_free(cdrom);
 	default_cdrom = NULL;
 }
 
--- a/src/cdrom/SDL_syscdrom.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/SDL_syscdrom.h	Tue Feb 07 06:59:48 2006 +0000
@@ -2,7 +2,7 @@
     SDL - Simple DirectMedia Layer
     Copyright (C) 1997-2006 Sam Lantinga
 
-    This library is free software; you can redistribute it and/or
+    This library is SDL_free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
     version 2.1 of the License, or (at your option) any later version.
--- a/src/cdrom/aix/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/aix/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -128,12 +128,12 @@
 
 		/* Add this drive to our list */
 		i = SDL_numcds;
-		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+		SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
 		if ( SDL_cdlist[i] == NULL ) {
 			SDL_OutOfMemory();
 			return;
 		}
-		strcpy(SDL_cdlist[i], drive);
+		SDL_strcpy(SDL_cdlist[i], drive);
 		SDL_cdmode[i] = stbuf->st_rdev;
 		++SDL_numcds;
 #ifdef DEBUG_CDROM
@@ -149,7 +149,7 @@
     struct vmount* ptr;
     int            ret;
 
-    buffer = (char*)malloc(10);
+    buffer = (char*)SDL_malloc(10);
     bufsz  = 10;
     if ( buffer==NULL )
     {
@@ -167,8 +167,8 @@
             bufsz = *(int*)buffer; /* Required size is in first word.   */
 				   /* (whatever a word is in AIX 4.3.3) */
 				   /* int seems to be OK in 32bit mode. */
-            free(buffer);
-            buffer = (char*)malloc(bufsz);
+            SDL_free(buffer);
+            buffer = (char*)SDL_malloc(bufsz);
             if ( buffer==NULL )
             {
                 fprintf(stderr,
@@ -237,9 +237,9 @@
     {
         ret = getfsent_r ( &entry, &fsFile, &passNo );
         if ( ret == 0 ) {
-            char* l = strrchr(entry.fs_spec,'/');
+            char* l = SDL_strrchr(entry.fs_spec,'/');
             if ( l != NULL ) {
-                if ( !strncmp("cd",++l,2) ) {
+                if ( !SDL_strncmp("cd",++l,2) ) {
 #ifdef DEBUG_CDROM
                     fprintf(stderr,
 			    "Found unmounted CD ROM drive with device name %s\n",
@@ -266,9 +266,9 @@
     {
         entry = getfsent();
         if ( entry != NULL ) {
-            char* l = strrchr(entry->fs_spec,'/');
+            char* l = SDL_strrchr(entry->fs_spec,'/');
             if ( l != NULL ) {
-                if ( !strncmp("cd",++l,2) ) {
+                if ( !SDL_strncmp("cd",++l,2) ) {
 #ifdef DEBUG_CDROM
                     fprintf(stderr,"Found unmounted CD ROM drive with device name %s", entry->fs_spec);
 #endif
@@ -303,15 +303,15 @@
 	SDL_CDcaps.Close = SDL_SYS_CDClose;
 
 	/* Look in the environment for our CD-ROM drive list */
-	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
+	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
 	if ( SDLcdrom != NULL ) {
 		char *cdpath, *delim;
-		cdpath = malloc(strlen(SDLcdrom)+1);
+		cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
 		if ( cdpath != NULL ) {
-			strcpy(cdpath, SDLcdrom);
+			SDL_strcpy(cdpath, SDLcdrom);
 			SDLcdrom = cdpath;
 			do {
-				delim = strchr(SDLcdrom, ':');
+				delim = SDL_strchr(SDLcdrom, ':');
 				if ( delim ) {
 					*delim++ = '\0';
 				}
@@ -327,7 +327,7 @@
 					SDLcdrom = NULL;
 				}
 			} while ( SDLcdrom );
-			free(cdpath);
+			SDL_free(cdpath);
 		}
 
 		/* If we found our drives, there's nothing left to do */
@@ -369,13 +369,13 @@
      * We found /dev/cd? drives and that is in our list. But we can
      * open only the /dev/rcd? versions of those devices for Audio CD.
      */
-    cdromname = (char*)malloc( strlen(SDL_cdlist[drive]+2) );
-    strcpy(cdromname,SDL_cdlist[drive]);
-    lastsl = strrchr(cdromname,'/');
+    cdromname = (char*)SDL_malloc( SDL_strlen(SDL_cdlist[drive]+2) );
+    SDL_strcpy(cdromname,SDL_cdlist[drive]);
+    lastsl = SDL_strrchr(cdromname,'/');
     if (lastsl) {
 	*lastsl = 0;
 	strcat(cdromname,"/r");
-	lastsl = strrchr(SDL_cdlist[drive],'/');
+	lastsl = SDL_strrchr(SDL_cdlist[drive],'/');
 	if (lastsl) {
 	    lastsl++;
 	    strcat(cdromname,lastsl);
@@ -459,7 +459,7 @@
 #endif
 	}
     }
-    free(cdromname);
+    SDL_free(cdromname);
     return fd;
 }
 
@@ -650,7 +650,7 @@
 
 	if ( SDL_numcds > 0 ) {
 		for ( i=0; i<SDL_numcds; ++i ) {
-			free(SDL_cdlist[i]);
+			SDL_free(SDL_cdlist[i]);
 		}
 		SDL_numcds = 0;
 	}
--- a/src/cdrom/beos/SDL_syscdrom.cc	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/beos/SDL_syscdrom.cc	Tue Feb 07 06:59:48 2006 +0000
@@ -116,12 +116,12 @@
 	if ( SDL_numcds < MAX_DRIVES ) {
 		/* Add this drive to our list */
 		i = SDL_numcds;
-		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+		SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
 		if ( SDL_cdlist[i] == NULL ) {
 			SDL_OutOfMemory();
 			return;
 		}
-		strcpy(SDL_cdlist[i], drive);
+		SDL_strcpy(SDL_cdlist[i], drive);
 		++SDL_numcds;
 #ifdef CDROM_DEBUG
   fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
@@ -165,15 +165,15 @@
 	SDL_CDcaps.Close = SDL_SYS_CDClose;
 
 	/* Look in the environment for our CD-ROM drive list */
-	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
+	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
 	if ( SDLcdrom != NULL ) {
 		char *cdpath, *delim;
-		cdpath = (char *)malloc(strlen(SDLcdrom)+1);
+		cdpath = (char *)SDL_malloc(SDL_strlen(SDLcdrom)+1);
 		if ( cdpath != NULL ) {
-			strcpy(cdpath, SDLcdrom);
+			SDL_strcpy(cdpath, SDLcdrom);
 			SDLcdrom = cdpath;
 			do {
-				delim = strchr(SDLcdrom, ':');
+				delim = SDL_strchr(SDLcdrom, ':');
 				if ( delim ) {
 					*delim++ = '\0';
 				}
@@ -186,7 +186,7 @@
 					SDLcdrom = NULL;
 				}
 			} while ( SDLcdrom );
-			free(cdpath);
+			SDL_free(cdpath);
 		}
 
 		/* If we found our drives, there's nothing left to do */
@@ -223,7 +223,7 @@
 			continue; 
 
 		if(entry.IsDirectory()) { 
-			if(strcmp(e.name, "floppy") == 0) 
+			if(SDL_strcmp(e.name, "floppy") == 0) 
 				continue; /* ignore floppy (it is not silent)  */
 			int devfd = try_dir(name);
 			if(devfd >= 0)
@@ -233,7 +233,7 @@
 			int devfd; 
 			device_geometry g; 
 
-			if(strcmp(e.name, "raw") != 0) 
+			if(SDL_strcmp(e.name, "raw") != 0) 
 				continue; /* ignore partitions */
 
 			devfd = open(name, O_RDONLY); 
@@ -401,7 +401,7 @@
 
 	if ( SDL_numcds > 0 ) {
 		for ( i=0; i<SDL_numcds; ++i ) {
-			free(SDL_cdlist[i]);
+			SDL_free(SDL_cdlist[i]);
 		}
 		SDL_numcds = 0;
 	}
--- a/src/cdrom/bsdi/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/bsdi/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -229,12 +229,12 @@
 
 		/* Add this drive to our list */
 		i = SDL_numcds;
-		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+		SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
 		if ( SDL_cdlist[i] == NULL ) {
 			SDL_OutOfMemory();
 			return;
 		}
-		strcpy(SDL_cdlist[i], drive);
+		SDL_strcpy(SDL_cdlist[i], drive);
 		SDL_cdmode[i] = stbuf->st_rdev;
 		++SDL_numcds;
 #ifdef DEBUG_CDROM
@@ -267,15 +267,15 @@
 	SDL_CDcaps.Close = SDL_SYS_CDClose;
 
 	/* Look in the environment for our CD-ROM drive list */
-	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
+	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
 	if ( SDLcdrom != NULL ) {
 		char *cdpath, *delim;
-		cdpath = malloc(strlen(SDLcdrom)+1);
+		cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
 		if ( cdpath != NULL ) {
-			strcpy(cdpath, SDLcdrom);
+			SDL_strcpy(cdpath, SDLcdrom);
 			SDLcdrom = cdpath;
 			do {
-				delim = strchr(SDLcdrom, ':');
+				delim = SDL_strchr(SDLcdrom, ':');
 				if ( delim ) {
 					*delim++ = '\0';
 				}
@@ -288,7 +288,7 @@
 					SDLcdrom = NULL;
 				}
 			} while ( SDLcdrom );
-			free(cdpath);
+			SDL_free(cdpath);
 		}
 
 		/* If we found our drives, there's nothing left to do */
@@ -304,7 +304,7 @@
 			exists = 1;
 			for ( j=checklist[i][1]; exists; ++j ) {
 				sprintf(drive, "/dev/%sc", &checklist[i][3]);
-				insert = strchr(drive, '?');
+				insert = SDL_strchr(drive, '?');
 				if ( insert != NULL ) {
 					*insert = j;
 				}
@@ -360,7 +360,7 @@
 	ntracks = last_track - first_track + 1;
 	cdrom->numtracks = ntracks;
 	toc_size = 4 + (ntracks + 1) * 8;
-	toc = (u_char *)malloc(toc_size);
+	toc = (u_char *)SDL_malloc(toc_size);
 	if	(toc == NULL)
 		return(-1);
 	bzero(cdb, sizeof (cdb));
@@ -373,7 +373,7 @@
 			&sus);
 	if	(sts < 0)
 		{
-		free(toc);
+		SDL_free(toc);
 		return(-1);
 		}
 
@@ -393,7 +393,7 @@
 			cdrom->track[i-1].length = cdrom->track[i].offset -
 						   cdrom->track[i-1].offset;
 		}
-	free(toc);
+	SDL_free(toc);
 	return(0);
 	}
 
@@ -535,7 +535,7 @@
 
 	if ( SDL_numcds > 0 ) {
 		for ( i=0; i<SDL_numcds; ++i ) {
-			free(SDL_cdlist[i]);
+			SDL_free(SDL_cdlist[i]);
 			}
 		}
 	SDL_numcds = 0;
--- a/src/cdrom/freebsd/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/freebsd/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -114,12 +114,12 @@
 
 		/* Add this drive to our list */
 		i = SDL_numcds;
-		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+		SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
 		if ( SDL_cdlist[i] == NULL ) {
 			SDL_OutOfMemory();
 			return;
 		}
-		strcpy(SDL_cdlist[i], drive);
+		SDL_strcpy(SDL_cdlist[i], drive);
 		SDL_cdmode[i] = stbuf->st_rdev;
 		++SDL_numcds;
 #ifdef DEBUG_CDROM
@@ -153,15 +153,15 @@
 	SDL_CDcaps.Close = SDL_SYS_CDClose;
 
 	/* Look in the environment for our CD-ROM drive list */
-	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
+	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
 	if ( SDLcdrom != NULL ) {
 		char *cdpath, *delim;
-		cdpath = malloc(strlen(SDLcdrom)+1);
+		cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
 		if ( cdpath != NULL ) {
-			strcpy(cdpath, SDLcdrom);
+			SDL_strcpy(cdpath, SDLcdrom);
 			SDLcdrom = cdpath;
 			do {
-				delim = strchr(SDLcdrom, ':');
+				delim = SDL_strchr(SDLcdrom, ':');
 				if ( delim ) {
 					*delim++ = '\0';
 				}
@@ -174,7 +174,7 @@
 					SDLcdrom = NULL;
 				}
 			} while ( SDLcdrom );
-			free(cdpath);
+			SDL_free(cdpath);
 		}
 
 		/* If we found our drives, there's nothing left to do */
@@ -190,7 +190,7 @@
 			exists = 1;
 			for ( j=checklist[i][1]; exists; ++j ) {
 				sprintf(drive, "/dev/%sc", &checklist[i][3]);
-				insert = strchr(drive, '?');
+				insert = SDL_strchr(drive, '?');
 				if ( insert != NULL ) {
 					*insert = j;
 				}
@@ -398,7 +398,7 @@
 
 	if ( SDL_numcds > 0 ) {
 		for ( i=0; i<SDL_numcds; ++i ) {
-			free(SDL_cdlist[i]);
+			SDL_free(SDL_cdlist[i]);
 		}
 		SDL_numcds = 0;
 	}
--- a/src/cdrom/linux/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/linux/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -142,7 +142,7 @@
 		}
 #ifdef USE_MNTENT
 		/* Even if we can't read it, it might be mounted */
-		else if ( mnttype && (strcmp(mnttype, MNTTYPE_CDROM) == 0) ) {
+		else if ( mnttype && (SDL_strcmp(mnttype, MNTTYPE_CDROM) == 0) ) {
 			is_cd = 1;
 		}
 #endif
@@ -170,12 +170,12 @@
 
 		/* Add this drive to our list */
 		i = SDL_numcds;
-		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+		SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
 		if ( SDL_cdlist[i] == NULL ) {
 			SDL_OutOfMemory();
 			return;
 		}
-		strcpy(SDL_cdlist[i], drive);
+		SDL_strcpy(SDL_cdlist[i], drive);
 		SDL_cdmode[i] = stbuf->st_rdev;
 		++SDL_numcds;
 #ifdef DEBUG_CDROM
@@ -198,45 +198,45 @@
 		char *mnt_dev;
 
 		while ( (mntent=getmntent(mntfp)) != NULL ) {
-			mnt_type = malloc(strlen(mntent->mnt_type) + 1);
+			mnt_type = SDL_malloc(SDL_strlen(mntent->mnt_type) + 1);
 			if (mnt_type == NULL)
 				continue;  /* maybe you'll get lucky next time. */
 
-			mnt_dev = malloc(strlen(mntent->mnt_fsname) + 1);
+			mnt_dev = SDL_malloc(SDL_strlen(mntent->mnt_fsname) + 1);
 			if (mnt_dev == NULL) {
-				free(mnt_type);
+				SDL_free(mnt_type);
 				continue;
 			}
 
-			strcpy(mnt_type, mntent->mnt_type);
-			strcpy(mnt_dev, mntent->mnt_fsname);
+			SDL_strcpy(mnt_type, mntent->mnt_type);
+			SDL_strcpy(mnt_dev, mntent->mnt_fsname);
 
 			/* Handle "supermount" filesystem mounts */
-			if ( strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) {
-				tmp = strstr(mntent->mnt_opts, "fs=");
+			if ( SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) {
+				tmp = SDL_strstr(mntent->mnt_opts, "fs=");
 				if ( tmp ) {
-					free(mnt_type);
-					mnt_type = strdup(tmp + strlen("fs="));
+					SDL_free(mnt_type);
+					mnt_type = strdup(tmp + SDL_strlen("fs="));
 					if ( mnt_type ) {
-						tmp = strchr(mnt_type, ',');
+						tmp = SDL_strchr(mnt_type, ',');
 						if ( tmp ) {
 							*tmp = '\0';
 						}
 					}
 				}
-				tmp = strstr(mntent->mnt_opts, "dev=");
+				tmp = SDL_strstr(mntent->mnt_opts, "dev=");
 				if ( tmp ) {
-					free(mnt_dev);
-					mnt_dev = strdup(tmp + strlen("dev="));
+					SDL_free(mnt_dev);
+					mnt_dev = strdup(tmp + SDL_strlen("dev="));
 					if ( mnt_dev ) {
-						tmp = strchr(mnt_dev, ',');
+						tmp = SDL_strchr(mnt_dev, ',');
 						if ( tmp ) {
 							*tmp = '\0';
 						}
 					}
 				}
 			}
-			if ( strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) {
+			if ( SDL_strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) {
 #ifdef DEBUG_CDROM
   fprintf(stderr, "Checking mount path from %s: %s mounted on %s of %s\n",
 	mtab, mnt_dev, mntent->mnt_dir, mnt_type);
@@ -245,8 +245,8 @@
 					AddDrive(mnt_dev, &stbuf);
 				}
 			}
-			free(mnt_dev);
-			free(mnt_type);
+			SDL_free(mnt_dev);
+			SDL_free(mnt_type);
 		}
 		endmntent(mntfp);
 	}
@@ -277,15 +277,15 @@
 	SDL_CDcaps.Close = SDL_SYS_CDClose;
 
 	/* Look in the environment for our CD-ROM drive list */
-	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
+	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
 	if ( SDLcdrom != NULL ) {
 		char *cdpath, *delim;
-		cdpath = malloc(strlen(SDLcdrom)+1);
+		cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
 		if ( cdpath != NULL ) {
-			strcpy(cdpath, SDLcdrom);
+			SDL_strcpy(cdpath, SDLcdrom);
 			SDLcdrom = cdpath;
 			do {
-				delim = strchr(SDLcdrom, ':');
+				delim = SDL_strchr(SDLcdrom, ':');
 				if ( delim ) {
 					*delim++ = '\0';
 				}
@@ -301,7 +301,7 @@
 					SDLcdrom = NULL;
 				}
 			} while ( SDLcdrom );
-			free(cdpath);
+			SDL_free(cdpath);
 		}
 
 		/* If we found our drives, there's nothing left to do */
@@ -337,7 +337,7 @@
 			exists = 1;
 			for ( j=checklist[i][1]; exists; ++j ) {
 				sprintf(drive, "/dev/%s", &checklist[i][3]);
-				insert = strchr(drive, '?');
+				insert = SDL_strchr(drive, '?');
 				if ( insert != NULL ) {
 					*insert = j;
 				}
@@ -551,7 +551,7 @@
 
 	if ( SDL_numcds > 0 ) {
 		for ( i=0; i<SDL_numcds; ++i ) {
-			free(SDL_cdlist[i]);
+			SDL_free(SDL_cdlist[i]);
 		}
 		SDL_numcds = 0;
 	}
--- a/src/cdrom/macos/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/macos/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -160,7 +160,7 @@
 	long				i, leadout;
 
 	/* Get the number of tracks on the CD by examining the TOC */
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kReadTOC;
@@ -181,7 +181,7 @@
 
 
 	/* Get the lead out area of the CD by examining the TOC */
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kReadTOC;
@@ -197,8 +197,8 @@
 			SDL_SYS_BCDToShort(cdpb.csParam.bytes[2]));
 
 	/* Get an array of track locations by examining the TOC */
-	memset(tracks, 0, sizeof(tracks));
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(tracks, 0, sizeof(tracks));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kReadTOC;
@@ -255,7 +255,7 @@
 	if ( ! get_drivenum(cdrom->id) ) {
 		return(CD_TRAYEMPTY);
 	}
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kReadTOC;
@@ -276,7 +276,7 @@
 
 	if (1 || SDL_cdlist[cdrom->id].hasAudio) {
 		/* Get the current playback status */
-		memset(&cdpb, 0, sizeof(cdpb));
+		SDL_memset(&cdpb, 0, sizeof(cdpb));
 		cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 		cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 		cdpb.csCode = kAudioStatus;
@@ -335,7 +335,7 @@
 	}
 
 	/* Specify the AudioCD playback mode */
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kSetPlayMode;
@@ -346,7 +346,7 @@
 
 #if 1
 	/* Specify the end of audio playback */
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kAudioStop;
@@ -358,7 +358,7 @@
 	}
 
 	/* Specify the start of audio playback, and start it */
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kAudioPlay;
@@ -373,7 +373,7 @@
 #else
 	/* Specify the end of audio playback */
 	FRAMES_TO_MSF(start+length, &m, &s, &f);
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kAudioStop;
@@ -388,7 +388,7 @@
 
 	/* Specify the start of audio playback, and start it */
 	FRAMES_TO_MSF(start, &m, &s, &f);
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kAudioPlay;
@@ -411,7 +411,7 @@
 {
 	CDCntrlParam cdpb;
 
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kAudioPause;
@@ -429,7 +429,7 @@
 {
 	CDCntrlParam cdpb;
 
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kAudioPause;
@@ -447,7 +447,7 @@
 {
 	CDCntrlParam cdpb;
 
-	memset(&cdpb, 0, sizeof(cdpb));
+	SDL_memset(&cdpb, 0, sizeof(cdpb));
 	cdpb.ioVRefNum = SDL_cdlist[cdrom->id].driveNum;
 	cdpb.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 	cdpb.csCode = kAudioStop;
@@ -481,7 +481,7 @@
 		}
 	
 		/* Does drive contain mounted volume? If not, skip */
-		memset(&hpb, 0, sizeof(hpb));
+		SDL_memset(&hpb, 0, sizeof(hpb));
 		hpb.volumeParam.ioVRefNum = driveElem->dQDrive;
 		if ( PBHGetVInfoSync(&hpb) != noErr ) {
 			continue;
@@ -495,7 +495,7 @@
 
 	/* If no disk is present, just eject the tray */
 	if (! disk) {
-		memset(&cpb, 0, sizeof(cpb));
+		SDL_memset(&cpb, 0, sizeof(cpb));
 		cpb.cntrlParam.ioVRefNum = 0; /* No Drive */
 		cpb.cntrlParam.ioCRefNum = SDL_cdlist[cdrom->id].dRefNum;
 		cpb.cntrlParam.csCode = kEjectTheDisc;
@@ -516,6 +516,6 @@
 void SDL_SYS_CDQuit(void)
 {
 	while(SDL_numcds--) 
-		memset(SDL_cdlist + SDL_numcds, 0, sizeof(SDL_cdlist[0]));
+		SDL_memset(SDL_cdlist + SDL_numcds, 0, sizeof(SDL_cdlist[0]));
 }
 
--- a/src/cdrom/macosx/AudioFilePlayer.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/macosx/AudioFilePlayer.c	Tue Feb 07 06:59:48 2006 +0000
@@ -64,7 +64,7 @@
     if (afp->mConnected)
         return 0 ;
 
-    memcpy(&afp->mPlayUnit, inDestUnit, sizeof (afp->mPlayUnit));
+    SDL_memcpy(&afp->mPlayUnit, inDestUnit, sizeof (afp->mPlayUnit));
 
     OSStatus result = noErr;
     
@@ -155,7 +155,7 @@
             FSClose (afp->mForkRefNum);
             afp->mForkRefNum = 0;
         }
-        free(afp);
+        SDL_free(afp);
     }
 }
 
@@ -304,10 +304,10 @@
 {
     SInt64 fileDataSize  = 0;
 
-    AudioFilePlayer *afp = (AudioFilePlayer *) malloc(sizeof (AudioFilePlayer));
+    AudioFilePlayer *afp = (AudioFilePlayer *) SDL_malloc(sizeof (AudioFilePlayer));
     if (afp == NULL)
         return NULL;
-    memset(afp, '\0', sizeof (*afp));
+    SDL_memset(afp, '\0', sizeof (*afp));
 
     #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m
     SET_AUDIOFILEPLAYER_METHOD(SetDestination);
@@ -326,7 +326,7 @@
 
     if (!afp->OpenFile (afp, inFileRef, &fileDataSize))
     {
-        free(afp);
+        SDL_free(afp);
         return NULL;
     }
         
--- a/src/cdrom/macosx/AudioFileReaderThread.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/macosx/AudioFileReaderThread.c	Tue Feb 07 06:59:48 2006 +0000
@@ -86,7 +86,7 @@
         FileData *i = frt->mFileData;
         FileData *prev = NULL;
 
-        FileData *newfd = (FileData *) malloc(sizeof (FileData));
+        FileData *newfd = (FileData *) SDL_malloc(sizeof (FileData));
         newfd->obj = inItem;
         newfd->next = NULL;
 
@@ -136,7 +136,7 @@
                     frt->mFileData = next;
                 else
                     prev->next = next;
-                free(i);
+                SDL_free(i);
             }
             i = next;
         }
@@ -279,7 +279,7 @@
             {
                 FileData *next = frt->mFileData->next;
                 theItem = frt->mFileData->obj;
-                free(frt->mFileData);
+                SDL_free(frt->mFileData);
                 frt->mFileData = next;
             }
 
@@ -330,21 +330,21 @@
     if (frt != NULL)
     {
         delete_SDLOSXCAGuard(frt->mGuard);
-        free(frt);
+        SDL_free(frt);
     }
 }
 
 FileReaderThread *new_FileReaderThread ()
 {
-    FileReaderThread *frt = (FileReaderThread *) malloc(sizeof (FileReaderThread));
+    FileReaderThread *frt = (FileReaderThread *) SDL_malloc(sizeof (FileReaderThread));
     if (frt == NULL)
         return NULL;
-    memset(frt, '\0', sizeof (*frt));
+    SDL_memset(frt, '\0', sizeof (*frt));
 
     frt->mGuard = new_SDLOSXCAGuard();
     if (frt->mGuard == NULL)
     {
-        free(frt);
+        SDL_free(frt);
         return NULL;
     }
 
@@ -549,7 +549,7 @@
             free (afm->mFileBuffer);
         }
 
-        free(afm);
+        SDL_free(afm);
     }
 }
 
@@ -568,10 +568,10 @@
             return NULL;
     }
 
-    afm = (AudioFileManager *) malloc(sizeof (AudioFileManager));
+    afm = (AudioFileManager *) SDL_malloc(sizeof (AudioFileManager));
     if (afm == NULL)
         return NULL;
-    memset(afm, '\0', sizeof (*afm));
+    SDL_memset(afm, '\0', sizeof (*afm));
 
     #define SET_AUDIOFILEMANAGER_METHOD(m) afm->m = AudioFileManager_##m
     SET_AUDIOFILEMANAGER_METHOD(Disconnect);
--- a/src/cdrom/macosx/SDLOSXCAGuard.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/macosx/SDLOSXCAGuard.c	Tue Feb 07 06:59:48 2006 +0000
@@ -147,10 +147,10 @@
 
 SDLOSXCAGuard *new_SDLOSXCAGuard(void)
 {
-    SDLOSXCAGuard *cag = (SDLOSXCAGuard *) malloc(sizeof (SDLOSXCAGuard));
+    SDLOSXCAGuard *cag = (SDLOSXCAGuard *) SDL_malloc(sizeof (SDLOSXCAGuard));
     if (cag == NULL)
         return NULL;
-    memset(cag, '\0', sizeof (*cag));
+    SDL_memset(cag, '\0', sizeof (*cag));
 
     #define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m
     SET_SDLOSXCAGUARD_METHOD(Lock);
@@ -176,7 +176,7 @@
     {
         pthread_mutex_destroy(&cag->mMutex);
         pthread_cond_destroy(&cag->mCondVar);
-        free(cag);
+        SDL_free(cag);
     }
 }
 
--- a/src/cdrom/openbsd/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/openbsd/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -119,12 +119,12 @@
 
 		/* Add this drive to our list */
 		i = SDL_numcds;
-		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+		SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
 		if ( SDL_cdlist[i] == NULL ) {
 			SDL_OutOfMemory();
 			return;
 		}
-		strcpy(SDL_cdlist[i], drive);
+		SDL_strcpy(SDL_cdlist[i], drive);
 		SDL_cdmode[i] = stbuf->st_rdev;
 		++SDL_numcds;
 #ifdef DEBUG_CDROM
@@ -162,15 +162,15 @@
 	SDL_CDcaps.Close = SDL_SYS_CDClose;
 
 	/* Look in the environment for our CD-ROM drive list */
-	SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
+	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
 	if ( SDLcdrom != NULL ) {
 		char *cdpath, *delim;
-		cdpath = malloc(strlen(SDLcdrom)+1);
+		cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
 		if ( cdpath != NULL ) {
-			strcpy(cdpath, SDLcdrom);
+			SDL_strcpy(cdpath, SDLcdrom);
 			SDLcdrom = cdpath;
 			do {
-				delim = strchr(SDLcdrom, ':');
+				delim = SDL_strchr(SDLcdrom, ':');
 				if ( delim ) {
 					*delim++ = '\0';
 				}
@@ -183,7 +183,7 @@
 					SDLcdrom = NULL;
 				}
 			} while ( SDLcdrom );
-			free(cdpath);
+			SDL_free(cdpath);
 		}
 
 		/* If we found our drives, there's nothing left to do */
@@ -199,7 +199,7 @@
 			exists = 1;
 			for ( j=checklist[i][1]; exists; ++j ) {
 				sprintf(drive, "/dev/%s", &checklist[i][3]);
-				insert = strchr(drive, '?');
+				insert = SDL_strchr(drive, '?');
 				if ( insert != NULL ) {
 					*insert = j;
 				}
@@ -407,7 +407,7 @@
 
 	if ( SDL_numcds > 0 ) {
 		for ( i=0; i<SDL_numcds; ++i ) {
-			free(SDL_cdlist[i]);
+			SDL_free(SDL_cdlist[i]);
 		}
 		SDL_numcds = 0;
 	}
--- a/src/cdrom/os2/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/os2/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -81,7 +81,7 @@
 
 /* Get the number of CD ROMs in the System */
 /* Clean SysInfo structure */
-memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS));
+SDL_memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS));
 /* Prepare structure to Ask Numer of Audio CDs */
 msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;	/* CD Audio Type */
 msp.pszReturn = (PSZ)&SysInfoRet; 	/* Return Structure */
@@ -98,13 +98,13 @@
 	{
 	msp.ulNumber = i+1;
 	mciSendCommand(0,MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT,&msp, 0);
-	SDL_cdlist[i] = (char *)malloc(strlen(SysInfoRet)+1);
+	SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(SysInfoRet)+1);
 	if ( SDL_cdlist[i] == NULL )
 		{
 		SDL_OutOfMemory();
 		return(-1);
 		}
-	strcpy(SDL_cdlist[i], SysInfoRet);
+	SDL_strcpy(SDL_cdlist[i], SysInfoRet);
 	}
 return(0);
 }
@@ -166,7 +166,7 @@
 	cdrom->numtracks = SDL_MAX_TRACKS;
 	}
 /* Alocate space for TOC data */
-mtr = (MCI_TOC_REC *)malloc(cdrom->numtracks*sizeof(MCI_TOC_REC));
+mtr = (MCI_TOC_REC *)SDL_malloc(cdrom->numtracks*sizeof(MCI_TOC_REC));
 if ( mtr == NULL )
 	{
 	SDL_OutOfMemory();
@@ -178,7 +178,7 @@
 if (LOUSHORT(mciSendCommand(cdrom->id,MCI_GETTOC,MCI_WAIT,&mtp, 0)) != MCIERR_SUCCESS)
 	{
 	SDL_OutOfMemory();
-	free(mtr);
+	SDL_free(mtr);
 	return(CD_ERROR);
 	}
 /* Fill SDL Tracks Structure */
@@ -193,7 +193,7 @@
 	msp.ulValue = (ULONG)((mtr+i)->TrackNum); /* Track Number? */
 	if (LOUSHORT(mciSendCommand(cdrom->id,MCI_STATUS,MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM,&msp, 0)) != MCIERR_SUCCESS)
 		{
-		free(mtr);
+		SDL_free(mtr);
 		return (CD_ERROR);
 		}
 	if (msp.ulReturn==MCI_CD_TRACK_AUDIO) cdrom->track[i].type = SDL_AUDIO_TRACK;
@@ -203,7 +203,7 @@
 	/* Set Track Offset */
 	cdrom->track[i].offset = FRAMESFROMMM((mtr+i)->ulStartAddr);
 	}
-free(mtr);
+SDL_free(mtr);
 return(0);
 }
 
@@ -386,7 +386,7 @@
 	{
 	for ( i=0; i<SDL_numcds; ++i )
 		{
-		free(SDL_cdlist[i]);
+		SDL_free(SDL_cdlist[i]);
 		}
 	SDL_numcds = 0;
 	}
--- a/src/cdrom/osf/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/osf/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -125,13 +125,13 @@
 
 	/* Add this drive to our list */
 	i = SDL_numcds;
-	SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+	SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
 	if ( SDL_cdlist[i] == NULL ) {
 	    SDL_OutOfMemory();
 	    return;
 	}
 
-	strcpy(SDL_cdlist[i], drive);
+	SDL_strcpy(SDL_cdlist[i], drive);
 	SDL_cdmode[i] = stbuf->st_rdev;
 	++SDL_numcds;
 #ifdef DEBUG_CDROM
@@ -177,15 +177,15 @@
 
 
     /* Look in the environment for our CD-ROM drive list */
-    SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
+    SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
     if ( SDLcdrom != NULL ) {
 	char *cdpath, *delim;
-	cdpath = malloc(strlen(SDLcdrom)+1);
+	cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
 	if ( cdpath != NULL ) {
-	    strcpy(cdpath, SDLcdrom);
+	    SDL_strcpy(cdpath, SDLcdrom);
 	    SDLcdrom = cdpath;
 	    do {
-		delim = strchr(SDLcdrom, ':');
+		delim = SDL_strchr(SDLcdrom, ':');
 		if ( delim ) {
 		    *delim++ = '\0';
 		}
@@ -198,7 +198,7 @@
 		    SDLcdrom = NULL;
 		}
 	    } while ( SDLcdrom );
-	    free(cdpath);
+	    SDL_free(cdpath);
 	}
 
 	/* If we found our drives, there's nothing left to do */
@@ -214,9 +214,9 @@
 
 	devdir = opendir(checklist[i].dir);
 	if (devdir) {
-	    name_len = strlen(checklist[i].name);
+	    name_len = SDL_strlen(checklist[i].name);
 	    while (devent = readdir(devdir))
-		if (memcmp(checklist[i].name, devent->d_name, name_len) == 0)
+		if (SDL_memcmp(checklist[i].name, devent->d_name, name_len) == 0)
 		    if (devent->d_name[devent->d_namlen-1] == 'c') {
 			sprintf(drive, "%s/%s", checklist[i].dir, devent->d_name);
 #ifdef DEBUG_CDROM
@@ -234,8 +234,8 @@
     }
 
 /*
-    SDLcdrom=malloc(sizeof(char) * 32);
-    strcpy(SDLcdrom,"/dev/rdisk/cdrom0c");
+    SDLcdrom=SDL_malloc(sizeof(char) * 32);
+    SDL_strcpy(SDLcdrom,"/dev/rdisk/cdrom0c");
     SDL_cdlist[0] = SDLcdrom;
     stat(SDLcdrom, &stbuf);
     SDL_cdmode[0] = stbuf.st_rdev;
@@ -449,7 +449,7 @@
 
     if ( SDL_numcds > 0 ) {
 	for ( i=0; i<SDL_numcds; ++i ) {
-	    free(SDL_cdlist[i]);
+	    SDL_free(SDL_cdlist[i]);
 	}
 	SDL_numcds = 0;
     }
--- a/src/cdrom/qnx/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/qnx/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -128,13 +128,13 @@
         /* Add this drive to our list */
 
         i = SDL_numcds;
-        SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+        SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
         if (SDL_cdlist[i] == NULL)
         {
             SDL_OutOfMemory();
             return;
         }
-        strcpy(SDL_cdlist[i], drive);
+        SDL_strcpy(SDL_cdlist[i], drive);
         SDL_cdmode[i] = stbuf->st_rdev;
         ++SDL_numcds;
     }
@@ -169,18 +169,18 @@
     }
 
     /* Look in the environment for our CD-ROM drive list */
-    SDLcdrom = getenv("SDL_CDROM");	/* ':' separated list of devices */
+    SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
     if ( SDLcdrom != NULL )
     {
         char *cdpath, *delim;
 
-        cdpath = malloc(strlen(SDLcdrom)+1);
+        cdpath = SDL_malloc(SDL_strlen(SDLcdrom)+1);
         if (cdpath != NULL)
         {
-            strcpy(cdpath, SDLcdrom);
+            SDL_strcpy(cdpath, SDLcdrom);
             SDLcdrom = cdpath;
             do {
-                delim = strchr(SDLcdrom, ':');
+                delim = SDL_strchr(SDLcdrom, ':');
                 if (delim)
                 {
                     *delim++ = '\0';
@@ -198,7 +198,7 @@
                     SDLcdrom = NULL;
                 }
             } while (SDLcdrom);
-            free(cdpath);
+            SDL_free(cdpath);
         }
 
         /* If we found our drives, there's nothing left to do */
@@ -219,7 +219,7 @@
             for ( j=checklist[i][1]; exists; ++j )
             {
                 sprintf(drive, "/dev/%s", &checklist[i][3]);
-                insert = strchr(drive, '?');
+                insert = SDL_strchr(drive, '?');
                 if (insert != NULL)
                 {
                     *insert = j;
@@ -346,7 +346,7 @@
 
     /* if media exists, then do other stuff */
 
-    memset(&info, 0x00, sizeof(info));
+    SDL_memset(&info, 0x00, sizeof(info));
     info.subch_command.data_format = CDROM_SUBCH_CURRENT_POSITION;
 
     do {
@@ -544,7 +544,7 @@
     {
         for (i=0; i<SDL_numcds; ++i)
         {
-            free(SDL_cdlist[i]);
+            SDL_free(SDL_cdlist[i]);
         }
         SDL_numcds = 0;
     }
--- a/src/cdrom/win32/SDL_syscdrom.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/cdrom/win32/SDL_syscdrom.c	Tue Feb 07 06:59:48 2006 +0000
@@ -66,12 +66,12 @@
 	if ( SDL_numcds < MAX_DRIVES ) {
 		/* Add this drive to our list */
 		i = SDL_numcds;
-		SDL_cdlist[i] = (char *)malloc(strlen(drive)+1);
+		SDL_cdlist[i] = (char *)SDL_malloc(SDL_strlen(drive)+1);
 		if ( SDL_cdlist[i] == NULL ) {
 			SDL_OutOfMemory();
 			return;
 		}
-		strcpy(SDL_cdlist[i], drive);
+		SDL_strcpy(SDL_cdlist[i], drive);
 		++SDL_numcds;
 #ifdef CDROM_DEBUG
   fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
@@ -99,12 +99,12 @@
 
 	/* Scan the system for CD-ROM drives */
 	for ( i='A'; i<='Z'; ++i ) {
-		snprintf(drive, SDL_arraysize(drive), "%c:\\", i);
+		SDL_snprintf(drive, SDL_arraysize(drive), "%c:\\", i);
 		if ( GetDriveType(drive) == DRIVE_CDROM ) {
 			AddDrive(drive);
 		}
 	}
-	memset(SDL_mciID, 0, sizeof(SDL_mciID));
+	SDL_memset(SDL_mciID, 0, sizeof(SDL_mciID));
 	return(0);
 }
 
@@ -377,7 +377,7 @@
 
 	if ( SDL_numcds > 0 ) {
 		for ( i=0; i<SDL_numcds; ++i ) {
-			free(SDL_cdlist[i]);
+			SDL_free(SDL_cdlist[i]);
 		}
 		SDL_numcds = 0;
 	}
--- a/src/events/SDL_active.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/events/SDL_active.c	Tue Feb 07 06:59:48 2006 +0000
@@ -73,7 +73,7 @@
 	posted = 0;
 	if ( SDL_ProcessEvents[SDL_ACTIVEEVENT] == SDL_ENABLE ) {
 		SDL_Event event;
-		memset(&event, 0, sizeof(event));
+		SDL_memset(&event, 0, sizeof(event));
 		event.type = SDL_ACTIVEEVENT;
 		event.active.gain = gain;
 		event.active.state = state;
--- a/src/events/SDL_events.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/events/SDL_events.c	Tue Feb 07 06:59:48 2006 +0000
@@ -151,7 +151,7 @@
 {
 	/* Reset everything to zero */
 	SDL_EventThread = NULL;
-	memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));
+	SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));
 
 	/* Create the lock and set ourselves active */
 #ifndef DISABLE_THREADS
@@ -239,7 +239,7 @@
 
 	/* No filter to start with, process most event types */
 	SDL_EventOK = NULL;
-	memset(SDL_ProcessEvents,SDL_ENABLE,sizeof(SDL_ProcessEvents));
+	SDL_memset(SDL_ProcessEvents,SDL_ENABLE,sizeof(SDL_ProcessEvents));
 	SDL_eventstate = ~0;
 	/* It's not save to call SDL_EventState() yet */
 	SDL_eventstate &= ~(0x00000001 << SDL_SYSWMEVENT);
@@ -306,7 +306,7 @@
 	{
 		int here, next;
 
-		/* This can probably be optimized with memcpy() -- careful! */
+		/* This can probably be optimized with SDL_memcpy() -- careful! */
 		if ( --SDL_EventQ.tail < 0 ) {
 			SDL_EventQ.tail = MAXEVENTS-1;
 		}
@@ -493,7 +493,7 @@
 	posted = 0;
 	if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
 		SDL_Event event;
-		memset(&event, 0, sizeof(event));
+		SDL_memset(&event, 0, sizeof(event));
 		event.type = SDL_SYSWMEVENT;
 		event.syswm.msg = message;
 		if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
--- a/src/events/SDL_keyboard.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/events/SDL_keyboard.c	Tue Feb 07 06:59:48 2006 +0000
@@ -60,8 +60,8 @@
 
 	/* Initialize the tables */
 	SDL_ModState = KMOD_NONE;
-	memset(keynames, 0, sizeof(keynames));
-	memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
+	SDL_memset(keynames, 0, sizeof(keynames));
+	SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
 	video->InitOSKeymap(this);
 
 	SDL_EnableKeyRepeat(0, 0);
@@ -319,7 +319,7 @@
 	SDL_keysym keysym;
 	SDLKey key;
 
-	memset(&keysym, 0, (sizeof keysym));
+	SDL_memset(&keysym, 0, (sizeof keysym));
 	for ( key=SDLK_FIRST; key<SDLK_LAST; ++key ) {
 		if ( SDL_KeyState[key] == SDL_PRESSED ) {
 			keysym.sym = key;
@@ -376,7 +376,7 @@
 	int posted, repeatable;
 	Uint16 modstate;
 
-	memset(&event, 0, sizeof(event));
+	SDL_memset(&event, 0, sizeof(event));
 
 #if 0
 printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym), 
--- a/src/events/SDL_mouse.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/events/SDL_mouse.c	Tue Feb 07 06:59:48 2006 +0000
@@ -182,7 +182,7 @@
 	posted = 0;
 	if ( SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE ) {
 		SDL_Event event;
-		memset(&event, 0, sizeof(event));
+		SDL_memset(&event, 0, sizeof(event));
 		event.type = SDL_MOUSEMOTION;
 		event.motion.state = buttonstate;
 		event.motion.x = X;
@@ -204,7 +204,7 @@
 	int move_mouse;
 	Uint8 buttonstate;
 
-	memset(&event, 0, sizeof(event));
+	SDL_memset(&event, 0, sizeof(event));
 
 	/* Check parameters */
 	if ( x || y ) {
--- a/src/events/SDL_sysevents.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/events/SDL_sysevents.h	Tue Feb 07 06:59:48 2006 +0000
@@ -2,7 +2,7 @@
     SDL - Simple DirectMedia Layer
     Copyright (C) 1997-2006 Sam Lantinga
 
-    This library is free software; you can redistribute it and/or
+    This library is SDL_free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
     version 2.1 of the License, or (at your option) any later version.
--- a/src/file/SDL_rwops.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/file/SDL_rwops.c	Tue Feb 07 06:59:48 2006 +0000
@@ -120,7 +120,7 @@
 		total_bytes = mem_available;
 	}
 
-	memcpy(ptr, context->hidden.mem.here, total_bytes);
+	SDL_memcpy(ptr, context->hidden.mem.here, total_bytes);
 	context->hidden.mem.here += total_bytes;
 
 	return (total_bytes / size);
@@ -130,7 +130,7 @@
 	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
 		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
 	}
-	memcpy(context->hidden.mem.here, ptr, num*size);
+	SDL_memcpy(context->hidden.mem.here, ptr, num*size);
 	context->hidden.mem.here += num*size;
 	return(num);
 }
@@ -162,8 +162,8 @@
  */
 static char *unix_to_mac(const char *file)
 {
-	int flen = strlen(file);
-	char *path = malloc(flen + 2);
+	int flen = SDL_strlen(file);
+	char *path = SDL_malloc(flen + 2);
 	const char *src = file;
 	char *dst = path;
 	if(*src == '/') {
@@ -175,7 +175,7 @@
 			*dst++ = ':';   /* relative paths begin with ':' */
 	}
 	while(src < file + flen) {
-		const char *end = strchr(src, '/');
+		const char *end = SDL_strchr(src, '/');
 		int len;
 		if(!end)
 			end = file + flen; /* last component */
@@ -186,7 +186,7 @@
 			if(len == 2 && src[0] == '.' && src[1] == '.') {
 				/* replace .. with the empty string */
 			} else {
-				memcpy(dst, src, len);
+				SDL_memcpy(dst, src, len);
 				dst += len;
 			}
 			if(end < file + flen)
@@ -209,7 +209,7 @@
 	{
 		char *mpath = unix_to_mac(file);
 		fp = fopen(mpath, mode);
-		free(mpath);
+		SDL_free(mpath);
 	}
 #else
 	fp = fopen(file, mode);
@@ -292,7 +292,7 @@
 {
 	SDL_RWops *area;
 
-	area = (SDL_RWops *)malloc(sizeof *area);
+	area = (SDL_RWops *)SDL_malloc(sizeof *area);
 	if ( area == NULL ) {
 		SDL_OutOfMemory();
 	}
@@ -301,5 +301,5 @@
 
 void SDL_FreeRW(SDL_RWops *area)
 {
-	free(area);
+	SDL_free(area);
 }
--- a/src/joystick/SDL_joystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/SDL_joystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -51,11 +51,11 @@
 	status = SDL_SYS_JoystickInit();
 	if ( status >= 0 ) {
 		arraylen = (status+1)*sizeof(*SDL_joysticks);
-		SDL_joysticks = (SDL_Joystick **)malloc(arraylen);
+		SDL_joysticks = (SDL_Joystick **)SDL_malloc(arraylen);
 		if ( SDL_joysticks == NULL ) {
 			SDL_numjoysticks = 0;
 		} else {
-			memset(SDL_joysticks, 0, arraylen);
+			SDL_memset(SDL_joysticks, 0, arraylen);
 			SDL_numjoysticks = status;
 		}
 		status = 0;
@@ -113,28 +113,28 @@
 	}
 
 	/* Create and initialize the joystick */
-	joystick = (SDL_Joystick *)malloc((sizeof *joystick));
+	joystick = (SDL_Joystick *)SDL_malloc((sizeof *joystick));
 	if ( joystick != NULL ) {
-		memset(joystick, 0, (sizeof *joystick));
+		SDL_memset(joystick, 0, (sizeof *joystick));
 		joystick->index = device_index;
 		if ( SDL_SYS_JoystickOpen(joystick) < 0 ) {
-			free(joystick);
+			SDL_free(joystick);
 			joystick = NULL;
 		} else {
 			if ( joystick->naxes > 0 ) {
-				joystick->axes = (Sint16 *)malloc
+				joystick->axes = (Sint16 *)SDL_malloc
 					(joystick->naxes*sizeof(Sint16));
 			}
 			if ( joystick->nhats > 0 ) {
-				joystick->hats = (Uint8 *)malloc
+				joystick->hats = (Uint8 *)SDL_malloc
 					(joystick->nhats*sizeof(Uint8));
 			}
 			if ( joystick->nballs > 0 ) {
-				joystick->balls = (struct balldelta *)malloc
+				joystick->balls = (struct balldelta *)SDL_malloc
 				  (joystick->nballs*sizeof(*joystick->balls));
 			}
 			if ( joystick->nbuttons > 0 ) {
-				joystick->buttons = (Uint8 *)malloc
+				joystick->buttons = (Uint8 *)SDL_malloc
 					(joystick->nbuttons*sizeof(Uint8));
 			}
 			if ( ((joystick->naxes > 0) && !joystick->axes)
@@ -146,19 +146,19 @@
 				joystick = NULL;
 			}
 			if ( joystick->axes ) {
-				memset(joystick->axes, 0,
+				SDL_memset(joystick->axes, 0,
 					joystick->naxes*sizeof(Sint16));
 			}
 			if ( joystick->hats ) {
-				memset(joystick->hats, 0,
+				SDL_memset(joystick->hats, 0,
 					joystick->nhats*sizeof(Uint8));
 			}
 			if ( joystick->balls ) {
-				memset(joystick->balls, 0,
+				SDL_memset(joystick->balls, 0,
 				  joystick->nballs*sizeof(*joystick->balls));
 			}
 			if ( joystick->buttons ) {
-				memset(joystick->buttons, 0,
+				SDL_memset(joystick->buttons, 0,
 					joystick->nbuttons*sizeof(Uint8));
 			}
 		}
@@ -375,7 +375,7 @@
 	/* Remove joystick from list */
 	for ( i=0; SDL_joysticks[i]; ++i ) {
 		if ( joystick == SDL_joysticks[i] ) {
-			memcpy(&SDL_joysticks[i], &SDL_joysticks[i+1],
+			SDL_memcpy(&SDL_joysticks[i], &SDL_joysticks[i+1],
 			       (SDL_numjoysticks-i)*sizeof(joystick));
 			break;
 		}
@@ -386,18 +386,18 @@
 
 	/* Free the data associated with this joystick */
 	if ( joystick->axes ) {
-		free(joystick->axes);
+		SDL_free(joystick->axes);
 	}
 	if ( joystick->hats ) {
-		free(joystick->hats);
+		SDL_free(joystick->hats);
 	}
 	if ( joystick->balls ) {
-		free(joystick->balls);
+		SDL_free(joystick->balls);
 	}
 	if ( joystick->buttons ) {
-		free(joystick->buttons);
+		SDL_free(joystick->buttons);
 	}
-	free(joystick);
+	SDL_free(joystick);
 }
 
 void SDL_JoystickQuit(void)
@@ -410,7 +410,7 @@
 	/* Quit the joystick setup */
 	SDL_SYS_JoystickQuit();
 	if ( SDL_joysticks ) {
-		free(SDL_joysticks);
+		SDL_free(SDL_joysticks);
 		SDL_joysticks = NULL;
 	}
 }
--- a/src/joystick/SDL_sysjoystick.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/SDL_sysjoystick.h	Tue Feb 07 06:59:48 2006 +0000
@@ -2,7 +2,7 @@
     SDL - Simple DirectMedia Layer
     Copyright (C) 1997-2006 Sam Lantinga
 
-    This library is free software; you can redistribute it and/or
+    This library is SDL_free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
     version 2.1 of the License, or (at your option) any later version.
--- a/src/joystick/amigaos/SDL_sysjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/amigaos/SDL_sysjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -116,7 +116,7 @@
 	ULONG temp,i;
 	D(bug("Opening joystick %ld\n",joystick->index));
 
-	if(!(joystick->hwdata=malloc(sizeof(struct joystick_hwdata))))
+	if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata))))
 		return -1;
 
 /* This loop is to check if the controller is a joypad */
@@ -215,7 +215,7 @@
 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
 {
 	if(joystick->hwdata)
-		free(joystick->hwdata);
+		SDL_free(joystick->hwdata);
 	return;
 }
 
--- a/src/joystick/beos/SDL_bejoystick.cc	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/beos/SDL_bejoystick.cc	Tue Feb 07 06:59:48 2006 +0000
@@ -67,8 +67,8 @@
 	/* Search for attached joysticks */
 	nports = joystick.CountDevices();
 	numjoysticks = 0;
-	memset(SDL_joyport, 0, (sizeof SDL_joyport));
-	memset(SDL_joyname, 0, (sizeof SDL_joyname));
+	SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
+	SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
 	for ( i=0; (SDL_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i ) {
 		if ( joystick.GetDeviceName(i, name) == B_OK ) {
 			if ( joystick.Open(name) != B_ERROR ) {
@@ -102,12 +102,12 @@
 
 	/* Create the joystick data structure */
 	joystick->hwdata = (struct joystick_hwdata *)
-	                   malloc(sizeof(*joystick->hwdata));
+	                   SDL_malloc(sizeof(*joystick->hwdata));
 	if ( joystick->hwdata == NULL ) {
 		SDL_OutOfMemory();
 		return(-1);
 	}
-	memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+	SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
 	stick = new BJoystick;
 	joystick->hwdata->stick = stick;
 
@@ -127,9 +127,9 @@
 	joystick->nhats = stick->CountHats();
 
 	joystick->hwdata->new_axes = (int16 *)
-	                  malloc(joystick->naxes*sizeof(int16));
+	                  SDL_malloc(joystick->naxes*sizeof(int16));
 	joystick->hwdata->new_hats = (uint8 *)
-	                  malloc(joystick->nhats*sizeof(uint8));
+	                  SDL_malloc(joystick->nhats*sizeof(uint8));
 	if ( ! joystick->hwdata->new_hats || ! joystick->hwdata->new_axes ) {
 		SDL_OutOfMemory();
 		SDL_SYS_JoystickClose(joystick);
@@ -208,12 +208,12 @@
 		joystick->hwdata->stick->Close();
 		delete joystick->hwdata->stick;
 		if ( joystick->hwdata->new_hats ) {
-			free(joystick->hwdata->new_hats);
+			SDL_free(joystick->hwdata->new_hats);
 		}
 		if ( joystick->hwdata->new_axes ) {
-			free(joystick->hwdata->new_axes);
+			SDL_free(joystick->hwdata->new_axes);
 		}
-		free(joystick->hwdata);
+		SDL_free(joystick->hwdata);
 		joystick->hwdata = NULL;
 	}
 }
@@ -224,12 +224,12 @@
 	int i;
 
 	for ( i=0; SDL_joyport[i]; ++i ) {
-		free(SDL_joyport[i]);
+		SDL_free(SDL_joyport[i]);
 	}
 	SDL_joyport[0] = NULL;
 
 	for ( i=0; SDL_joyname[i]; ++i ) {
-		free(SDL_joyname[i]);
+		SDL_free(SDL_joyname[i]);
 	}
 	SDL_joyname[0] = NULL;
 }
--- a/src/joystick/bsd/SDL_sysjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/bsd/SDL_sysjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -139,8 +139,8 @@
 
 	SDL_numjoysticks = 0;
 
-	memset(joynames, 0, sizeof(joynames));
-	memset(joydevnames, 0, sizeof(joydevnames));
+	SDL_memset(joynames, 0, sizeof(joynames));
+	SDL_memset(joydevnames, 0, sizeof(joydevnames));
 
 	for (i = 0; i < MAX_UHID_JOYS; i++) {
 		SDL_Joystick nj;
@@ -154,7 +154,7 @@
 			SDL_SYS_JoystickClose(&nj);
 			SDL_numjoysticks++;
 		} else {
-			free(joynames[nj.index]);
+			SDL_free(joynames[nj.index]);
 			joynames[nj.index] = NULL;
 		}
 	}
@@ -241,7 +241,7 @@
 		return (-1);
 	}
 
-	hw = (struct joystick_hwdata *)malloc(sizeof(struct joystick_hwdata));
+	hw = (struct joystick_hwdata *)SDL_malloc(sizeof(struct joystick_hwdata));
 	if (hw == NULL) {
 		SDL_OutOfMemory();
 		close(fd);
@@ -250,7 +250,7 @@
 	joy->hwdata = hw;
 	hw->fd = fd;
 	hw->path = strdup(path);
-	if (! strncmp(path, "/dev/joy", 8)) {
+	if (! SDL_strncmp(path, "/dev/joy", 8)) {
 		hw->type = BSDJOY_JOY;
 		joy->naxes = 2;
 		joy->nbuttons = 2;
@@ -311,7 +311,7 @@
 				case HUG_JOYSTICK:
 				case HUG_GAME_PAD:
 					s = hid_usage_in_page(hitem.usage);
-					sp = malloc(strlen(s) + 5);
+					sp = SDL_malloc(SDL_strlen(s) + 5);
 					sprintf(sp, "%s (%d)", s,
 					    joy->index);
 					joydevnames[joy->index] = sp;
@@ -351,8 +351,8 @@
 	return (0);
 usberr:
 	close(hw->fd);
-	free(hw->path);
-	free(hw);
+	SDL_free(hw->path);
+	SDL_free(hw);
 	return (-1);
 }
 
@@ -482,13 +482,13 @@
 void
 SDL_SYS_JoystickClose(SDL_Joystick *joy)
 {
-	if (strncmp(joy->hwdata->path, "/dev/joy", 8))	{
+	if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8))	{
 		report_free(&joy->hwdata->inreport);
 		hid_dispose_report_desc(joy->hwdata->repdesc);
 	}
 	close(joy->hwdata->fd);
-	free(joy->hwdata->path);
-	free(joy->hwdata);
+	SDL_free(joy->hwdata->path);
+	SDL_free(joy->hwdata);
 
 	return;
 }
@@ -500,9 +500,9 @@
 
 	for (i = 0; i < MAX_JOYS; i++) {
 		if (joynames[i] != NULL)
-			free(joynames[i]);
+			SDL_free(joynames[i]);
 		if (joydevnames[i] != NULL)
-			free(joydevnames[i]);
+			SDL_free(joydevnames[i]);
 	}
 
 	return;
@@ -538,7 +538,7 @@
 	r->size = len;
 
 	if (r->size > 0) {
-		r->buf = malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
+		r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
 		    r->size);
 		if (r->buf == NULL) {
 			SDL_OutOfMemory();
@@ -556,7 +556,7 @@
 report_free(struct report *r)
 {
 	if (r->buf != NULL) {
-		free(r->buf);
+		SDL_free(r->buf);
 	}
 	r->status = SREPORT_UNINIT;
 }
--- a/src/joystick/dc/SDL_sysjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/dc/SDL_sysjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -90,13 +90,13 @@
 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
 {
 	/* allocate memory for system specific hardware data */
-	joystick->hwdata = (struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata));
+	joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
 	if (joystick->hwdata == NULL)
 	{
 		SDL_OutOfMemory();
 		return(-1);
 	}
-	memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+	SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
 
 	/* fill nbuttons, naxes, and nhats fields */
 	joystick->nbuttons = MAX_BUTTONS;
@@ -182,7 +182,7 @@
 {
 	if (joystick->hwdata != NULL) {
 		/* free system specific hardware data */
-		free(joystick->hwdata);
+		SDL_free(joystick->hwdata);
 	}
 }
 
--- a/src/joystick/linux/SDL_sysjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -23,7 +23,7 @@
 /* This is the system specific header for the SDL joystick API */
 
 #include <stdio.h>		/* For the definition of NULL */
-#include <stdlib.h>		/* For getenv() prototype */
+#include <stdlib.h>		/* For SDL_getenv() prototype */
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -187,9 +187,9 @@
 {
 	char *newstring;
 
-	newstring = (char *)malloc(strlen(string)+1);
+	newstring = (char *)SDL_malloc(SDL_strlen(string)+1);
 	if ( newstring ) {
-		strcpy(newstring, string);
+		SDL_strcpy(newstring, string);
 	}
 	return(newstring);
 }
@@ -209,7 +209,7 @@
 
       if (name) {
          for(j = 0; j < SDL_TABLESIZE(joystick_logicalmap); j++) {
-            if (!strcmp(name, joystick_logicalmap[j].name)) {
+            if (!SDL_strcmp(name, joystick_logicalmap[j].name)) {
 
                prev = i;
                SDL_joylist[prev].map = joystick_logicalmap+j;
@@ -243,7 +243,7 @@
       "20212223242526272829303132";
    const char* suffix;
 
-   slen = strlen(namebuf);
+   slen = SDL_strlen(namebuf);
 
    suffix = NULL;
 
@@ -306,8 +306,8 @@
 	numjoysticks = 0;
 
 	/* First see if the user specified a joystick to use */
-	if ( getenv("SDL_JOYSTICK_DEVICE") != NULL ) {
-		strncpy(path, getenv("SDL_JOYSTICK_DEVICE"), sizeof(path));
+	if ( SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL ) {
+		SDL_strncpy(path, SDL_getenv("SDL_JOYSTICK_DEVICE"), sizeof(path));
 		path[sizeof(path)-1] = '\0';
 		if ( stat(path, &sb) == 0 ) {
 			fd = open(path, O_RDONLY, 0);
@@ -426,7 +426,7 @@
 {
 	int i;
 
-	joystick->hwdata->hats = (struct hwdata_hat *)malloc(
+	joystick->hwdata->hats = (struct hwdata_hat *)SDL_malloc(
 		joystick->nhats * sizeof(struct hwdata_hat));
 	if ( joystick->hwdata->hats == NULL ) {
 		return(-1);
@@ -442,7 +442,7 @@
 {
 	int i;
 
-	joystick->hwdata->balls = (struct hwdata_ball *)malloc(
+	joystick->hwdata->balls = (struct hwdata_ball *)SDL_malloc(
 		joystick->nballs * sizeof(struct hwdata_ball));
 	if ( joystick->hwdata->balls == NULL ) {
 		return(-1);
@@ -481,8 +481,8 @@
 	old_axes = joystick->naxes;
 
 	/* Generic analog joystick support */
-	if ( strstr(name, "Analog") == name && strstr(name, "-hat") ) {
-		if ( sscanf(name,"Analog %d-axis %*d-button %d-hat",
+	if ( SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat") ) {
+		if ( SDL_sscanf(name,"Analog %d-axis %*d-button %d-hat",
 			&tmp_naxes, &tmp_nhats) == 2 ) {
 
 			joystick->naxes = tmp_naxes;
@@ -494,7 +494,7 @@
 
 	/* Special joystick support */
 	for ( i=0; i < SDL_TABLESIZE(special_joysticks); ++i ) {
-		if ( strcmp(name, special_joysticks[i].name) == 0 ) {
+		if ( SDL_strcmp(name, special_joysticks[i].name) == 0 ) {
 
 			joystick->naxes = special_joysticks[i].naxes;
 			joystick->nhats = special_joysticks[i].nhats;
@@ -506,16 +506,16 @@
 	}
 
 	/* User environment joystick support */
-	if ( (env = getenv("SDL_LINUX_JOYSTICK")) ) {
-		strcpy(env_name, "");
-		if ( *env == '\'' && sscanf(env, "'%[^']s'", env_name) == 1 )
-			env += strlen(env_name)+2;
-		else if ( sscanf(env, "%s", env_name) == 1 )
-			env += strlen(env_name);
+	if ( (env = SDL_getenv("SDL_LINUX_JOYSTICK")) ) {
+		SDL_strcpy(env_name, "");
+		if ( *env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1 )
+			env += SDL_strlen(env_name)+2;
+		else if ( SDL_sscanf(env, "%s", env_name) == 1 )
+			env += SDL_strlen(env_name);
 
-		if ( strcmp(name, env_name) == 0 ) {
+		if ( SDL_strcmp(name, env_name) == 0 ) {
 
-			if ( sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats,
+			if ( SDL_sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats,
 				&tmp_nballs) == 3 ) {
 
 				joystick->naxes = tmp_naxes;
@@ -697,13 +697,13 @@
 		return(-1);
 	}
 	joystick->hwdata = (struct joystick_hwdata *)
-	                   malloc(sizeof(*joystick->hwdata));
+	                   SDL_malloc(sizeof(*joystick->hwdata));
 	if ( joystick->hwdata == NULL ) {
 		SDL_OutOfMemory();
 		close(fd);
 		return(-1);
 	}
-	memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+	SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
 	joystick->hwdata->fd = fd;
 
 	/* Set the joystick to non-blocking read mode */
@@ -1064,12 +1064,12 @@
 #endif
 		close(joystick->hwdata->fd);
 		if ( joystick->hwdata->hats ) {
-			free(joystick->hwdata->hats);
+			SDL_free(joystick->hwdata->hats);
 		}
 		if ( joystick->hwdata->balls ) {
-			free(joystick->hwdata->balls);
+			SDL_free(joystick->hwdata->balls);
 		}
-		free(joystick->hwdata);
+		SDL_free(joystick->hwdata);
 		joystick->hwdata = NULL;
 	}
 }
@@ -1080,7 +1080,7 @@
 	int i;
 
 	for ( i=0; SDL_joylist[i].fname; ++i ) {
-		free(SDL_joylist[i].fname);
+		SDL_free(SDL_joylist[i].fname);
 	}
 	SDL_joylist[0].fname = NULL;
 }
--- a/src/joystick/macos/SDL_sysjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/macos/SDL_sysjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -137,7 +137,7 @@
     if ( len >= sizeof(name) ) {
         len = (sizeof(name) - 1);
     }
-    memcpy(name, &SYS_DevDef[index].deviceName[1], len);
+    SDL_memcpy(name, &SYS_DevDef[index].deviceName[1], len);
     name[len] = '\0';
 
     return name;
@@ -161,14 +161,14 @@
     index = joystick->index;
 
     /* allocate memory for system specific hardware data */
-    joystick->hwdata = (struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata));
+    joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
     if (joystick->hwdata == NULL)
     {
 		SDL_OutOfMemory();
 		return(-1);
     }
-    memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
-    strcpy(joystick->hwdata->name, SDL_SYS_JoystickName(index));
+    SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+    SDL_strcpy(joystick->hwdata->name, SDL_SYS_JoystickName(index));
     joystick->name = joystick->hwdata->name;
 
     ISpElementList_ExtractByKind(
--- a/src/joystick/mint/SDL_sysjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/mint/SDL_sysjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -162,13 +162,13 @@
 {
 	int i;
 	unsigned long cookie_mch;
-	const char *envr=getenv("SDL_JOYSTICK_ATARI");
+	const char *envr=SDL_getenv("SDL_JOYSTICK_ATARI");
 	
 #define TEST_JOY_ENABLED(env,idstring,num) \
-	if (strstr(env,idstring"-off")) { \
+	if (SDL_strstr(env,idstring"-off")) { \
 		atarijoysticks[num].enabled=SDL_FALSE; \
 	} \
-	if (strstr(env,idstring"-on")) { \
+	if (SDL_strstr(env,idstring"-on")) { \
 		atarijoysticks[num].enabled=SDL_TRUE; \
 	}
 
--- a/src/joystick/os2/SDL_sysjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/os2/SDL_sysjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -326,14 +326,14 @@
 int i;			/* Generic Counter */
 
 /* allocate memory for system specific hardware data */
-joystick->hwdata = (struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata));
+joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
 if (joystick->hwdata == NULL)
 	{
 	SDL_OutOfMemory();
 	return(-1);
 	}
 /* Reset Hardware Data */
-memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
 
 /* ShortCut Pointer */
 index = joystick->index;
@@ -517,7 +517,7 @@
 if (joystick->hwdata != NULL)
 	{
 	/* free system specific hardware data */
-	free(joystick->hwdata);
+	SDL_free(joystick->hwdata);
 	}
 }
 
@@ -602,7 +602,7 @@
 char *joyenv;				/* Pointer to tested character */
 char tempnumber[5];		/* Temporary place to put numeric texts */
 
-joyenv = getenv("SDL_OS2_JOYSTICK");
+joyenv = SDL_getenv("SDL_OS2_JOYSTICK");
 if (joyenv == NULL) return 0;
 /* Joystick Environment is defined! */
 while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
--- a/src/joystick/riscos/SDL_sysjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/riscos/SDL_sysjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -89,7 +89,7 @@
 {
 	_kernel_swi_regs regs;
 
-	if(!(joystick->hwdata=malloc(sizeof(struct joystick_hwdata))))
+	if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata))))
 		return -1;
 
 	regs.r[0] = joystick->index;
@@ -161,7 +161,7 @@
 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
 {
 	if(joystick->hwdata)
-		free(joystick->hwdata);
+		SDL_free(joystick->hwdata);
 	return;
 }
 
--- a/src/joystick/win32/SDL_mmjoystick.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/joystick/win32/SDL_mmjoystick.c	Tue Feb 07 06:59:48 2006 +0000
@@ -82,7 +82,7 @@
 	unsigned char regvalue[256];
 	unsigned char regname[256];
 
-	snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s\\%s",
+	SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s\\%s",
 		REGSTR_PATH_JOYCONFIG,
 		szRegKey,
 		REGSTR_KEY_JOYCURR);
@@ -95,7 +95,7 @@
 			joystick's properties
 		*/
 		regsize = sizeof(regname);
-		snprintf((char *) regvalue, SDL_arraysize(regvalue),
+		SDL_snprintf((char *) regvalue, SDL_arraysize(regvalue),
 			"Joystick%d%s", index+1,
 			REGSTR_VAL_JOYOEMNAME);
 		regresult = RegQueryValueExA(hKey,
@@ -105,7 +105,7 @@
 		if (regresult == ERROR_SUCCESS)
 		{
 			/* open that registry key */
-			snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s",
+			SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s",
 				REGSTR_PATH_JOYOEM, regname);
 			regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
 				(char *) regkey, 0, KEY_READ, &hKey);
@@ -124,7 +124,7 @@
 						allocate enough memory
 						for the OEM name text ...
 					*/
-					name = (char *) malloc(regsize);
+					name = (char *) SDL_malloc(regsize);
 					/* ... and read it from the registry */
 					regresult =
 						RegQueryValueExA(hKey,
@@ -227,13 +227,13 @@
 	axis_max[5] = SYS_Joystick[index].wVmax;
 
 	/* allocate memory for system specific hardware data */
-	joystick->hwdata = (struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata));
+	joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
 	if (joystick->hwdata == NULL)
 	{
 		SDL_OutOfMemory();
 		return(-1);
 	}
-	memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+	SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
 
 	/* set hardware data */
 	joystick->hwdata->id = SYS_JoystickID[index];
@@ -359,7 +359,7 @@
 {
 	if (joystick->hwdata != NULL) {
 		/* free system specific hardware data */
-		free(joystick->hwdata);
+		SDL_free(joystick->hwdata);
 	}
 }
 
@@ -369,7 +369,7 @@
 	int i;
 	for (i = 0; i < MAX_JOYSTICKS; i++) {
 		if ( SYS_JoystickName[i] != NULL ) {
-			free(SYS_JoystickName[i]);
+			SDL_free(SYS_JoystickName[i]);
 		}
 	}
 }
@@ -406,14 +406,14 @@
 		break;
 
 		default:
-			snprintf(errbuf, SDL_arraysize(errbuf),
+			SDL_snprintf(errbuf, SDL_arraysize(errbuf),
 			         "%s: Unknown Multimedia system error: 0x%x",
 								function, code);
 		break;
 	}
 
 	if ( ! errbuf[0] ) {
-		snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
+		SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
 	}
 	SDL_SetError("%s", errbuf);
 }
--- a/src/loadso/macos/SDL_loadso.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/loadso/macos/SDL_loadso.c	Tue Feb 07 06:59:48 2006 +0000
@@ -52,7 +52,7 @@
 	OSErr error;
 	char psofile[512];
 
-	strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
+	SDL_strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
 	psofile[SDL_TABLESIZE(psofile)-1] = '\0';
 	error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
 			kLoadCFrag, &library_id, &mainAddr, errName);
@@ -90,7 +90,7 @@
 	CFragConnectionID library_id = (CFragConnectionID)handle;
 	char pname[512];
 
-	strncpy(pname, name, SDL_TABLESIZE(pname));
+	SDL_strncpy(pname, name, SDL_TABLESIZE(pname));
 	pname[SDL_TABLESIZE(pname)-1] = '\0';
 	if ( FindSymbol(library_id, C2PStr(pname),
 	                (char **)&symbol, &class) != noErr ) {
--- a/src/loadso/macosx/SDL_loadso.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/loadso/macosx/SDL_loadso.c	Tue Feb 07 06:59:48 2006 +0000
@@ -282,7 +282,7 @@
 	va_start(arg, str);
 	tss = pthread_getspecific(dlerror_key);
 	err_str = tss->errstr;
-	strncpy(err_str, "dlcompat: ", ERR_STR_LEN);
+	SDL_strncpy(err_str, "dlcompat: ", ERR_STR_LEN);
 	vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
 	va_end(arg);
 	debug("ERROR: %s\n", err_str);
@@ -298,7 +298,7 @@
 
 static const char *safegetenv(const char *s)
 {
-	const char *ss = getenv(s);
+	const char *ss = SDL_getenv(s);
 	return ss ? ss : "";
 }
 
@@ -338,7 +338,7 @@
 	debug("Module name: %s", mod_name);
 	for (i = 0; i < count; i++)
 	{
-		if (!strcmp(mod_name, _dyld_get_image_name(i)))
+		if (!SDL_strcmp(mod_name, _dyld_get_image_name(i)))
 		{
 			mh = _dyld_get_image_header(i);
 			break;
@@ -362,14 +362,14 @@
 	static char *buf=NULL;
 	const char *ldlp = safegetenv("LD_LIBRARY_PATH");
 	const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
-	const char *stdpath = getenv("DYLD_FALLBACK_LIBRARY_PATH");
+	const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH");
 	if (!stdpath)
 		stdpath = "/usr/local/lib:/lib:/usr/lib";
 	if (!buf)
 	{	
-		buf_size = strlen(ldlp) + strlen(dyldlp) + strlen(stdpath) + 4;
-		buf = malloc(buf_size);
-		snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
+		buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4;
+		buf = SDL_malloc(buf_size);
+		SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
 				 stdpath, '\0');
 	}
 	return buf;
@@ -383,7 +383,7 @@
 	static int end = 0;
 	static int numsize = MAX_SEARCH_PATHS;
 	static char **tmp;
-	/* So we can call free() in the "destructor" we use i=-1 to return the alloc'd array */
+	/* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
 	if (i == -1)
 	{
 		return (const char*)path;
@@ -400,8 +400,8 @@
 		tmp = (char **)calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
 		if (tmp)
 		{
-			memcpy(tmp, path, sizeof(char **) * numsize);
-			free(path);
+			SDL_memcpy(tmp, path, sizeof(char **) * numsize);
+			SDL_free(path);
 			path = tmp;
 			numsize += MAX_SEARCH_PATHS;
 		}
@@ -428,7 +428,7 @@
 	const char *path = getSearchPath(i);
 	if (path)
 	{
-		snprintf(buf, PATH_MAX, "%s/%s", path, file);
+		SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file);
 	}
 	return path ? buf : 0;
 }
@@ -446,7 +446,7 @@
 	*fullPath = file;
 	if (0 == stat(file, &sbuf))
 		return &sbuf;
-	if (strchr(file, '/'))
+	if (SDL_strchr(file, '/'))
 		return 0;				/* If the path had a / we don't look in env var places */
 	fileName = NULL;
 	if (!fileName)
@@ -567,7 +567,7 @@
 		for (j = 0; j < i; j++)
 		{
 			id = _dyld_get_image_name(j);
-			if (!strcmp(id, name))
+			if (!SDL_strcmp(id, name))
 			{
 				mh = _dyld_get_image_header(j);
 				break;
@@ -620,7 +620,7 @@
 	return nssym;
 }
 
-/* Up to the caller to free() returned string */
+/* Up to the caller to SDL_free() returned string */
 static inline const char *dyld_error_str()
 {
 	NSLinkEditErrors dylder;
@@ -629,10 +629,10 @@
 	const char *dyldfile;
 	const char* retStr = NULL;
 	NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
-	if (dylderrstr && strlen(dylderrstr))
+	if (dylderrstr && SDL_strlen(dylderrstr))
 	{
-		retStr = malloc(strlen(dylderrstr) +1);
-		strcpy((char*)retStr,dylderrstr);
+		retStr = SDL_malloc(SDL_strlen(dylderrstr) +1);
+		SDL_strcpy((char*)retStr,dylderrstr);
 	}
 	return retStr;
 }
@@ -735,21 +735,21 @@
 			else
 			{
 				if (savedErrorStr)
-					free((char*)savedErrorStr);			
-				savedErrorStr = malloc(256);
-				snprintf((char*)savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);	
+					SDL_free((char*)savedErrorStr);			
+				savedErrorStr = SDL_malloc(256);
+				SDL_snprintf((char*)savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);	
 			}
 		}
 	}
 	/* Error reporting */
 	if (!nssym)
 	{
-		if (!savedErrorStr || !strlen(savedErrorStr))
+		if (!savedErrorStr || !SDL_strlen(savedErrorStr))
 		{
 			if (savedErrorStr)
-				free((char*)savedErrorStr);
-			savedErrorStr = malloc(256);
-			snprintf((char*)savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
+				SDL_free((char*)savedErrorStr);
+			savedErrorStr = SDL_malloc(256);
+			SDL_snprintf((char*)savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
 		}
 		if (canSetError)
 		{
@@ -760,7 +760,7 @@
 			debug(savedErrorStr);
 		}
 		if (savedErrorStr)
-			free((char*)savedErrorStr);
+			SDL_free((char*)savedErrorStr);
 		return NULL;
 	}
 	return NSAddressOfSymbol(nssym);
@@ -839,13 +839,13 @@
 		if (!(dls->module))
 		{
 			NSLinkEditError(&ler, &lerno, &file, &errstr);
-			if (!errstr || (!strlen(errstr)))
+			if (!errstr || (!SDL_strlen(errstr)))
 				error("Can't open this file type");
 			else
 				error(errstr);
 			if ((dls->flags & DL_IN_LIST) == 0)
 			{
-				free(dls);
+				SDL_free(dls);
 			}
 			return NULL;
 		}
@@ -867,7 +867,7 @@
 		NSLinkEditError(&ler, &lerno, &file, &errstr);
 		if ((dls->flags & DL_IN_LIST) == 0)
 		{
-			free(dls);
+			SDL_free(dls);
 		}
 		error(errstr);
 		return NULL;
@@ -917,7 +917,7 @@
 
 static void dlerrorfree(void *data)
 {
-	free(data);
+	SDL_free(data);
 }
 
 /* We kind of want a recursive lock here, but meet a little trouble
@@ -932,7 +932,7 @@
 	tss = pthread_getspecific(dlerror_key);
 	if (!tss)
 	{
-		tss = malloc(sizeof(struct dlthread));
+		tss = SDL_malloc(sizeof(struct dlthread));
 		tss->lockcnt = 0;
 		tss->errset = 0;
 		if (pthread_setspecific(dlerror_key, tss))
@@ -1010,16 +1010,16 @@
 #if !FINK_BUILD
 static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
 {
-	int sym_len = strlen(symbol);
+	int sym_len = SDL_strlen(symbol);
 	void *value = NULL;
 	char *malloc_sym = NULL;
 	dolock();
-	malloc_sym = malloc(sym_len + 2);
+	malloc_sym = SDL_malloc(sym_len + 2);
 	if (malloc_sym)
 	{
 		sprintf(malloc_sym, "_%s", symbol);
 		value = dlsymIntern(handle, malloc_sym, 1);
-		free(malloc_sym);
+		SDL_free(malloc_sym);
 	}
 	else
 	{
@@ -1056,15 +1056,15 @@
  *	the underscore always, or not at all. These global functions need to go away
  *	for opendarwin.
  */
-	int sym_len = strlen(symbol);
+	int sym_len = SDL_strlen(symbol);
 	void *value = NULL;
 	char *malloc_sym = NULL;
-	malloc_sym = malloc(sym_len + 2);
+	malloc_sym = SDL_malloc(sym_len + 2);
 	if (malloc_sym)
 	{
 		sprintf(malloc_sym, "_%s", symbol);
 		value = dlsymIntern(handle, malloc_sym, 1);
-		free(malloc_sym);
+		SDL_free(malloc_sym);
 	}
 	else
 	{
@@ -1273,7 +1273,7 @@
 	{
 		if (LC_SEGMENT == lc->cmd)
 		{
-			if (!strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
+			if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
 				break;
 		}
 	}
@@ -1341,15 +1341,15 @@
 		void *d;
 		dlfunc_t f;
 	} rv;
-	int sym_len = strlen(symbol);
+	int sym_len = SDL_strlen(symbol);
 	char *malloc_sym = NULL;
 	dolock();
-	malloc_sym = malloc(sym_len + 2);
+	malloc_sym = SDL_malloc(sym_len + 2);
 	if (malloc_sym)
 	{
 		sprintf(malloc_sym, "_%s", symbol);
 		rv.d = dlsymIntern(handle, malloc_sym, 1);
-		free(malloc_sym);
+		SDL_free(malloc_sym);
 	}
 	else
 	{
--- a/src/loadso/windows/SDL_loadso.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/loadso/windows/SDL_loadso.c	Tue Feb 07 06:59:48 2006 +0000
@@ -45,8 +45,8 @@
 #if defined(_WIN32_WCE)
 	char errbuf[512];
 
-	wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
-	wchar_t *sofile_t = malloc((MAX_PATH+1) * sizeof(wchar_t));
+	wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t));
+	wchar_t *sofile_t = SDL_malloc((MAX_PATH+1) * sizeof(wchar_t));
 
 	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sofile, -1, sofile_t, MAX_PATH);
 	handle = (void *)LoadLibrary(sofile_t);
@@ -62,8 +62,8 @@
 		loaderror = errbuf;
 	}
 
-	free(sofile_t);
-	free(errbuf_t);
+	SDL_free(sofile_t);
+	SDL_free(errbuf_t);
 
 #else /*if defined(WIN32)*/
 	char errbuf[512];
@@ -94,10 +94,10 @@
 
 #if defined(_WIN32_WCE)
 	char errbuf[512];
-	int length = strlen(name);
+	int length = SDL_strlen(name);
 
-	wchar_t *name_t = malloc((length + 1) * sizeof(wchar_t));
-	wchar_t *errbuf_t = malloc(512 * sizeof(wchar_t));
+	wchar_t *name_t = SDL_malloc((length + 1) * sizeof(wchar_t));
+	wchar_t *errbuf_t = SDL_malloc(512 * sizeof(wchar_t));
 
 	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, name_t, length);
 
@@ -112,8 +112,8 @@
 		loaderror = errbuf;
 	}
 
-	free(name_t);
-	free(errbuf_t);
+	SDL_free(name_t);
+	SDL_free(errbuf_t);
 
 #else /*if defined(WIN32)*/
 	char errbuf[512];
--- a/src/main/macos/SDL_main.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/main/macos/SDL_main.c	Tue Feb 07 06:59:48 2006 +0000
@@ -589,7 +589,7 @@
 
     /* Parse C-string into argv and argc */
     nargs = ParseCommandLine (commandLine, NULL);
-    args = (char **)malloc((nargs+1)*(sizeof *args));
+    args = (char **)SDL_malloc((nargs+1)*(sizeof *args));
     if ( args == NULL ) {
 		exit(-1);
 	}
--- a/src/main/win32/SDL_win32_main.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/main/win32/SDL_win32_main.c	Tue Feb 07 06:59:48 2006 +0000
@@ -5,12 +5,12 @@
 */
 
 #include <stdio.h>
-#include <string.h>
-#include <ctype.h>
 #include <stdlib.h>
 
-#include <windows.h>
-#include <malloc.h>			/* For _alloca() */
+#include "SDL_windows.h"
+
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 
 #ifdef _WIN32_WCE
 # define DIR_SEPERATOR TEXT("\\")
@@ -56,7 +56,7 @@
 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
 
 /* seems to be undefined in Win CE although in online help */
-char *strrchr(char *str, int c)
+char *SDL_strrchr(char *str, int c)
 {
 	char *p;
 
@@ -195,15 +195,15 @@
 
 	/* Get the class name from argv[0] */
 	appname = argv[0];
-	if ( (bufp=strrchr(argv[0], '\\')) != NULL ) {
+	if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) {
 		appname = bufp+1;
 	} else
-	if ( (bufp=strrchr(argv[0], '/')) != NULL ) {
+	if ( (bufp=SDL_strrchr(argv[0], '/')) != NULL ) {
 		appname = bufp+1;
 	}
 
-	if ( (bufp=strrchr(appname, '.')) == NULL )
-		n = strlen(appname);
+	if ( (bufp=SDL_strrchr(appname, '.')) == NULL )
+		n = SDL_strlen(appname);
 	else
 		n = (bufp-appname);
 
@@ -211,7 +211,7 @@
 	if ( bufp == NULL ) {
 		return OutOfMemory();
 	}
-	strncpy(bufp, appname, n);
+	SDL_strncpy(bufp, appname, n);
 	bufp[n] = '\0';
 	appname = bufp;
 
@@ -298,8 +298,8 @@
 	}
 	path[pathlen] = '\0';
 
-	strcpy( stdoutPath, path );
-	strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE );
+	SDL_strcpy( stdoutPath, path );
+	SDL_strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE );
     
 	/* Redirect standard input and standard output */
 	newfp = freopen(stdoutPath, TEXT("w"), stdout);
@@ -317,8 +317,8 @@
 	}
 #endif /* _WIN32_WCE */
 
-	strcpy( stderrPath, path );
-	strcat( stderrPath, DIR_SEPERATOR STDERR_FILE );
+	SDL_strcpy( stderrPath, path );
+	SDL_strcat( stderrPath, DIR_SEPERATOR STDERR_FILE );
 
 	newfp = freopen(stderrPath, TEXT("w"), stderr);
 #ifndef _WIN32_WCE
@@ -354,11 +354,11 @@
 #else
 	/* Grab the command line (use alloca() on Windows) */
 	bufp = GetCommandLine();
-	cmdline = (char *)alloca(strlen(bufp)+1);
+	cmdline = (char *)alloca(SDL_strlen(bufp)+1);
 	if ( cmdline == NULL ) {
 		return OutOfMemory();
 	}
-	strcpy(cmdline, bufp);
+	SDL_strcpy(cmdline, bufp);
 #endif
 
 	/* Parse it into argv and argc */
--- a/src/stdlib/SDL_getenv.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/stdlib/SDL_getenv.c	Tue Feb 07 06:59:48 2006 +0000
@@ -42,20 +42,20 @@
 	char *value;
 	const char *sep;
 
-	sep = strchr(variable, '=');
+	sep = SDL_strchr(variable, '=');
 	if ( sep == NULL ) {
 		return -1;
 	}
-	bufferlen = strlen(variable)+1;
+	bufferlen = SDL_strlen(variable)+1;
 	if ( bufferlen > SDL_envmemlen ) {
-		char *newmem = (char *)realloc(SDL_envmem, bufferlen);
+		char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
 		if ( newmem == NULL ) {
 			return -1;
 		}
 		SDL_envmem = newmem;
 		SDL_envmemlen = bufferlen;
 	}
-	strcpy(SDL_envmem, variable);
+	SDL_strcpy(SDL_envmem, variable);
 	value = SDL_envmem + (sep - variable);
 	*value++ = '\0';
 	if ( !SetEnvironmentVariable(SDL_envmem, *value ? value : NULL) ) {
@@ -74,7 +74,7 @@
 		return NULL;
 	}
 	if ( bufferlen > SDL_envmemlen ) {
-		char *newmem = (char *)realloc(SDL_envmem, bufferlen);
+		char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
 		if ( newmem == NULL ) {
 			return NULL;
 		}
@@ -140,7 +140,7 @@
 
 	/* Didn't find it in the environment, expand and add */
 	if ( ! added ) {
-		new_env = realloc(SDL_env, (i+2)*sizeof(char *));
+		new_env = SDL_realloc(SDL_env, (i+2)*sizeof(char *));
 		if ( new_env ) {
 			SDL_env = new_env;
 			SDL_env[i++] = new_variable;
--- a/src/stdlib/SDL_malloc.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/stdlib/SDL_malloc.c	Tue Feb 07 06:59:48 2006 +0000
@@ -39,6 +39,11 @@
 #define LACKS_ERRNO_H
 #define LACKS_STDLIB_H
 #define ABORT
+#define memset	SDL_memset
+#define memcpy	SDL_memcpy
+#define malloc	SDL_malloc
+#define realloc	SDL_realloc
+#define free	SDL_free
 
 /*
   This is a version (aka dlmalloc) of malloc/free/realloc written by
--- a/src/stdlib/SDL_qsort.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/stdlib/SDL_qsort.c	Tue Feb 07 06:59:48 2006 +0000
@@ -233,9 +233,9 @@
       /* Shift everything in [test,first)	\
        * up by one, and place |first|		\
        * where |test| is. */			\
-      memcpy(pivot,first,size);			\
-      memmove(test+size,test,first-test);	\
-      memcpy(test,pivot,size);			\
+      SDL_memcpy(pivot,first,size);			\
+      SDL_memmove(test+size,test,first-test);	\
+      SDL_memcpy(test,pivot,size);			\
     }						\
   }
 
@@ -298,7 +298,7 @@
   stack_entry stack[STACK_SIZE];
   int stacktop=0;
   char *first,*last;
-  char *pivot=malloc(size);
+  char *pivot=SDL_malloc(size);
   size_t trunc=TRUNC_nonaligned*size;
   assert(pivot!=0);
 
@@ -310,7 +310,7 @@
       /* Select pivot */
       { char * mid=first+size*((last-first)/size >> 1);
         Pivot(SWAP_nonaligned,size);
-        memcpy(pivot,mid,size);
+        SDL_memcpy(pivot,mid,size);
       }
       /* Partition. */
       Partition(SWAP_nonaligned,size);
@@ -320,7 +320,7 @@
   }
   PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size);
   Insertion(SWAP_nonaligned);
-  free(pivot);
+  SDL_free(pivot);
 }
 
 static void qsort_aligned(void *base, size_t nmemb, size_t size,
@@ -329,7 +329,7 @@
   stack_entry stack[STACK_SIZE];
   int stacktop=0;
   char *first,*last;
-  char *pivot=malloc(size);
+  char *pivot=SDL_malloc(size);
   size_t trunc=TRUNC_aligned*size;
   assert(pivot!=0);
 
@@ -341,7 +341,7 @@
       /* Select pivot */
       { char * mid=first+size*((last-first)/size >> 1);
         Pivot(SWAP_aligned,size);
-        memcpy(pivot,mid,size);
+        SDL_memcpy(pivot,mid,size);
       }
       /* Partition. */
       Partition(SWAP_aligned,size);
@@ -351,7 +351,7 @@
   }
   PreInsertion(SWAP_aligned,TRUNC_aligned,size);
   Insertion(SWAP_aligned);
-  free(pivot);
+  SDL_free(pivot);
 }
 
 static void qsort_words(void *base, size_t nmemb,
@@ -360,7 +360,7 @@
   stack_entry stack[STACK_SIZE];
   int stacktop=0;
   char *first,*last;
-  char *pivot=malloc(WORD_BYTES);
+  char *pivot=SDL_malloc(WORD_BYTES);
   assert(pivot!=0);
 
   first=(char*)base; last=first+(nmemb-1)*WORD_BYTES;
@@ -398,7 +398,7 @@
       *pr=*pl; }
     if (pr!=(int*)first) *pr=*(int*)pivot;
   }
-  free(pivot);
+  SDL_free(pivot);
 }
 
 /* ---------------------------------------------------------------------- */
--- a/src/stdlib/SDL_string.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/stdlib/SDL_string.c	Tue Feb 07 06:59:48 2006 +0000
@@ -375,7 +375,7 @@
 #ifndef HAVE_STRRCHR
 char *SDL_strrchr(const char *string, int c)
 {
-    const char *bufp = string + strlen(string) - 1;
+    const char *bufp = string + SDL_strlen(string) - 1;
     while ( bufp >= string ) {
         if ( *bufp == c ) {
             return (char *)bufp;
@@ -388,9 +388,9 @@
 #ifndef HAVE_STRSTR
 char *SDL_strstr(const char *haystack, const char *needle)
 {
-    size_t length = strlen(needle);
+    size_t length = SDL_strlen(needle);
     while ( *haystack ) {
-        if ( strncmp(haystack, needle, length) == 0 ) {
+        if ( SDL_strncmp(haystack, needle, length) == 0 ) {
             return (char *)haystack;
         }
     }
@@ -429,9 +429,9 @@
 
     /* The numbers went into the string backwards. :) */
     if ( *string == '-' ) {
-        _strrev(string+1);
+        SDL_strrev(string+1);
     } else {
-        _strrev(string);
+        SDL_strrev(string);
     }
 
     return string;
@@ -454,7 +454,7 @@
     *bufp = '\0';
 
     /* The numbers went into the string backwards. :) */
-    _strrev(string);
+    SDL_strrev(string);
 
     return string;
 }
@@ -497,9 +497,9 @@
 
     /* The numbers went into the string backwards. :) */
     if ( *string == '-' ) {
-        _strrev(string+1);
+        SDL_strrev(string+1);
     } else {
-        _strrev(string);
+        SDL_strrev(string);
     }
 
     return string;
@@ -522,7 +522,7 @@
     *bufp = '\0';
 
     /* The numbers went into the string backwards. :) */
-    _strrev(string);
+    SDL_strrev(string);
 
     return string;
 }
@@ -878,12 +878,12 @@
     char num[130];
     size_t size;
 
-    _ltoa(value, num, radix);
+    SDL_ltoa(value, num, radix);
     size = SDL_strlen(num);
     if ( size > maxlen ) {
         size = maxlen;
     }
-    strncpy(text, num, size);
+    SDL_strncpy(text, num, size);
 
     return size;
 }
@@ -892,12 +892,12 @@
     char num[130];
     size_t size;
 
-    _ultoa(value, num, radix);
+    SDL_ultoa(value, num, radix);
     size = SDL_strlen(num);
     if ( size > maxlen ) {
         size = maxlen;
     }
-    strncpy(text, num, size);
+    SDL_strncpy(text, num, size);
 
     return size;
 }
@@ -907,12 +907,12 @@
     char num[130];
     size_t size;
 
-    _i64toa(value, num, radix);
+    SDL_lltoa(value, num, radix);
     size = SDL_strlen(num);
     if ( size > maxlen ) {
         size = maxlen;
     }
-    strncpy(text, num, size);
+    SDL_strncpy(text, num, size);
 
     return size;
 }
@@ -921,12 +921,12 @@
     char num[130];
     size_t size;
 
-    _ui64toa(value, num, radix);
+    SDL_ulltoa(value, num, radix);
     size = SDL_strlen(num);
     if ( size > maxlen ) {
         size = maxlen;
     }
-    strncpy(text, num, size);
+    SDL_strncpy(text, num, size);
 
     return size;
 }
@@ -1076,7 +1076,7 @@
                                 break;
                         }
                         if ( do_lowercase ) {
-                            _strlwr(text);
+                            SDL_strlwr(text);
                         }
                         done = SDL_TRUE;
                         break;
--- a/src/thread/SDL_thread.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/SDL_thread.c	Tue Feb 07 06:59:48 2006 +0000
@@ -99,16 +99,16 @@
 			SDL_numthreads, SDL_maxthreads);
 #endif
 	if ( SDL_numthreads == SDL_maxthreads ) {
-		threads=(SDL_Thread **)malloc((SDL_maxthreads+ARRAY_CHUNKSIZE)*
+		threads=(SDL_Thread **)SDL_malloc((SDL_maxthreads+ARRAY_CHUNKSIZE)*
 		                              (sizeof *threads));
 		if ( threads == NULL ) {
 			SDL_OutOfMemory();
 			goto done;
 		}
-		memcpy(threads, SDL_Threads, SDL_numthreads*(sizeof *threads));
+		SDL_memcpy(threads, SDL_Threads, SDL_numthreads*(sizeof *threads));
 		SDL_maxthreads += ARRAY_CHUNKSIZE;
 		if ( SDL_Threads ) {
-			free(SDL_Threads);
+			SDL_free(SDL_Threads);
 		}
 		SDL_Threads = threads;
 	}
@@ -136,7 +136,7 @@
 				}
 			} else {
 				SDL_maxthreads = 0;
-				free(SDL_Threads);
+				SDL_free(SDL_Threads);
 				SDL_Threads = NULL;
 			}
 #ifdef DEBUG_THREADS
@@ -223,19 +223,19 @@
 	int ret;
 
 	/* Allocate memory for the thread info structure */
-	thread = (SDL_Thread *)malloc(sizeof(*thread));
+	thread = (SDL_Thread *)SDL_malloc(sizeof(*thread));
 	if ( thread == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(thread, 0, (sizeof *thread));
+	SDL_memset(thread, 0, (sizeof *thread));
 	thread->status = -1;
 
 	/* Set up the arguments for the thread */
-	args = (thread_args *)malloc(sizeof(*args));
+	args = (thread_args *)SDL_malloc(sizeof(*args));
 	if ( args == NULL ) {
 		SDL_OutOfMemory();
-		free(thread);
+		SDL_free(thread);
 		return(NULL);
 	}
 	args->func = fn;
@@ -243,8 +243,8 @@
 	args->info = thread;
 	args->wait = SDL_CreateSemaphore(0);
 	if ( args->wait == NULL ) {
-		free(thread);
-		free(args);
+		SDL_free(thread);
+		SDL_free(args);
 		return(NULL);
 	}
 
@@ -263,11 +263,11 @@
 	} else {
 		/* Oops, failed.  Gotta free everything */
 		SDL_DelThread(thread);
-		free(thread);
+		SDL_free(thread);
 		thread = NULL;
 	}
 	SDL_DestroySemaphore(args->wait);
-	free(args);
+	SDL_free(args);
 
 	/* Everything is running now */
 	return(thread);
@@ -281,7 +281,7 @@
 			*status = thread->status;
 		}
 		SDL_DelThread(thread);
-		free(thread);
+		SDL_free(thread);
 	}
 }
 
--- a/src/thread/amigaos/SDL_syssem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/amigaos/SDL_syssem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -44,7 +44,7 @@
 {
 	SDL_sem *sem;
 
-	sem = (SDL_sem *)malloc(sizeof(*sem));
+	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
 
 	if ( ! sem ) {
 		SDL_OutOfMemory();
@@ -53,7 +53,7 @@
 
 	D(bug("Creating semaphore %lx...\n",sem));
 
-	memset(sem,0,sizeof(*sem));
+	SDL_memset(sem,0,sizeof(*sem));
 
 	InitSemaphore(&sem->Sem);
 
@@ -66,7 +66,7 @@
 
 	if ( sem ) {
 // Condizioni per liberare i task in attesa?
-		free(sem);
+		SDL_free(sem);
 	}
 }
 
--- a/src/thread/amigaos/SDL_thread.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/amigaos/SDL_thread.c	Tue Feb 07 06:59:48 2006 +0000
@@ -84,16 +84,16 @@
 			SDL_numthreads, SDL_maxthreads);
 #endif
 	if ( SDL_numthreads == SDL_maxthreads ) {
-		threads=(SDL_Thread **)malloc((SDL_maxthreads+ARRAY_CHUNKSIZE)*
+		threads=(SDL_Thread **)SDL_malloc((SDL_maxthreads+ARRAY_CHUNKSIZE)*
 		                              (sizeof *threads));
 		if ( threads == NULL ) {
 			SDL_OutOfMemory();
 			goto done;
 		}
-		memcpy(threads, SDL_Threads, SDL_numthreads*(sizeof *threads));
+		SDL_memcpy(threads, SDL_Threads, SDL_numthreads*(sizeof *threads));
 		SDL_maxthreads += ARRAY_CHUNKSIZE;
 		if ( SDL_Threads ) {
-			free(SDL_Threads);
+			SDL_free(SDL_Threads);
 		}
 		SDL_Threads = threads;
 	}
@@ -198,19 +198,19 @@
 	int ret;
 
 	/* Allocate memory for the thread info structure */
-	thread = (SDL_Thread *)malloc(sizeof(*thread));
+	thread = (SDL_Thread *)SDL_malloc(sizeof(*thread));
 	if ( thread == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(thread, 0, (sizeof *thread));
+	SDL_memset(thread, 0, (sizeof *thread));
 	thread->status = -1;
 
 	/* Set up the arguments for the thread */
-	args = (thread_args *)malloc(sizeof(*args));
+	args = (thread_args *)SDL_malloc(sizeof(*args));
 	if ( args == NULL ) {
 		SDL_OutOfMemory();
-		free(thread);
+		SDL_free(thread);
 		return(NULL);
 	}
 	args->func = fn;
@@ -218,8 +218,8 @@
 	args->info = thread;
 	args->wait = FindTask(NULL);
 	if ( args->wait == NULL ) {
-		free(thread);
-		free(args);
+		SDL_free(thread);
+		SDL_free(args);
 		SDL_OutOfMemory();
 		return(NULL);
 	}
@@ -239,10 +239,10 @@
 	} else {
 		/* Oops, failed.  Gotta free everything */
 		SDL_DelThread(thread);
-		free(thread);
+		SDL_free(thread);
 		thread = NULL;
 	}
-	free(args);
+	SDL_free(args);
 
 	/* Everything is running now */
 	return(thread);
@@ -256,7 +256,7 @@
 			*status = thread->status;
 		}
 		SDL_DelThread(thread);
-		free(thread);
+		SDL_free(thread);
 	}
 }
 
--- a/src/thread/beos/SDL_syssem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/beos/SDL_syssem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -37,12 +37,12 @@
 {
 	SDL_sem *sem;
 
-	sem = (SDL_sem *)malloc(sizeof(*sem));
+	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
 	if ( sem ) {
 		sem->id = create_sem(initial_value, "SDL semaphore");
 		if ( sem->id < B_NO_ERROR ) {
 			SDL_SetError("create_sem() failed");
-			free(sem);
+			SDL_free(sem);
 			sem = NULL;
 		}
 	} else {
@@ -58,7 +58,7 @@
 		if ( sem->id >= B_NO_ERROR ) {
 			delete_sem(sem->id);
 		}
-		free(sem);
+		SDL_free(sem);
 	}
 }
 
--- a/src/thread/bsdi/SDL_syssem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/bsdi/SDL_syssem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -113,11 +113,11 @@
 /* Create a semaphore, initialized with value */
 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
 {
-	SDL_sem *sem = (SDL_sem *) malloc(sizeof(SDL_sem));
+	SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
 	if ( sem ) {
 		if ( sem_init(&sem->sem_data, 0, initial_value) < 0 ) {
 			SDL_SetError("sem_init() failed");
-			free(sem);
+			SDL_free(sem);
 			sem = NULL;
 		} else {
 			sem->sem = &sem->sem_data;
@@ -132,7 +132,7 @@
 {
 	if ( sem ) {
 		sem_destroy(sem->sem);
-		free(sem);
+		SDL_free(sem);
 	}
 }
 
@@ -322,7 +322,7 @@
 		goto RETURN;
 	}
 
-	*sem = (sem_t)malloc(sizeof(struct sem));
+	*sem = (sem_t)SDL_malloc(sizeof(struct sem));
 	if (*sem == NULL) {
 		errno = ENOSPC;
 		retval = -1;
@@ -333,7 +333,7 @@
 	 * Initialize the semaphore.
 	 */
 	if (pthread_mutex_init(&(*sem)->lock, NULL) != 0) {
-		free(*sem);
+		SDL_free(*sem);
 		errno = ENOSPC;
 		retval = -1;
 		goto RETURN;
@@ -341,7 +341,7 @@
 
 	if (pthread_cond_init(&(*sem)->gtzero, NULL) != 0) {
 		pthread_mutex_destroy(&(*sem)->lock);
-		free(*sem);
+		SDL_free(*sem);
 		errno = ENOSPC;
 		retval = -1;
 		goto RETURN;
@@ -377,7 +377,7 @@
 	pthread_cond_destroy(&(*sem)->gtzero);
 	(*sem)->magic = 0;
 
-	free(*sem);
+	SDL_free(*sem);
 
 	retval = 0;
   RETURN:
--- a/src/thread/dc/SDL_syscond.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/dc/SDL_syscond.c	Tue Feb 07 06:59:48 2006 +0000
@@ -46,7 +46,7 @@
 {
 	SDL_cond *cond;
 
-	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
+	cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
 	if ( cond ) {
 		cond->lock = SDL_CreateMutex();
 		cond->wait_sem = SDL_CreateSemaphore(0);
@@ -75,7 +75,7 @@
 		if ( cond->lock ) {
 			SDL_DestroyMutex(cond->lock);
 		}
-		free(cond);
+		SDL_free(cond);
 	}
 }
 
--- a/src/thread/dc/SDL_sysmutex.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/dc/SDL_sysmutex.c	Tue Feb 07 06:59:48 2006 +0000
@@ -43,7 +43,7 @@
 	SDL_mutex *mutex;
 
 	/* Allocate mutex memory */
-	mutex = (SDL_mutex *)malloc(sizeof(*mutex));
+	mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
 	if ( mutex ) {
 		spinlock_init(&mutex->mutex);
 		mutex->recursive = 0;
@@ -58,7 +58,7 @@
 void SDL_DestroyMutex(SDL_mutex *mutex)
 {
 	if ( mutex ) {
-		free(mutex);
+		SDL_free(mutex);
 	}
 }
 
--- a/src/thread/generic/SDL_syscond.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/generic/SDL_syscond.c	Tue Feb 07 06:59:48 2006 +0000
@@ -44,7 +44,7 @@
 {
 	SDL_cond *cond;
 
-	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
+	cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
 	if ( cond ) {
 		cond->lock = SDL_CreateMutex();
 		cond->wait_sem = SDL_CreateSemaphore(0);
@@ -73,7 +73,7 @@
 		if ( cond->lock ) {
 			SDL_DestroyMutex(cond->lock);
 		}
-		free(cond);
+		SDL_free(cond);
 	}
 }
 
--- a/src/thread/generic/SDL_sysmutex.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/generic/SDL_sysmutex.c	Tue Feb 07 06:59:48 2006 +0000
@@ -40,14 +40,14 @@
 	SDL_mutex *mutex;
 
 	/* Allocate mutex memory */
-	mutex = (SDL_mutex *)malloc(sizeof(*mutex));
+	mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
 	if ( mutex ) {
 		/* Create the mutex semaphore, with initial value 1 */
 		mutex->sem = SDL_CreateSemaphore(1);
 		mutex->recursive = 0;
 		mutex->owner = 0;
 		if ( ! mutex->sem ) {
-			free(mutex);
+			SDL_free(mutex);
 			mutex = NULL;
 		}
 	} else {
@@ -63,7 +63,7 @@
 		if ( mutex->sem ) {
 			SDL_DestroySemaphore(mutex->sem);
 		}
-		free(mutex);
+		SDL_free(mutex);
 	}
 }
 
--- a/src/thread/generic/SDL_syssem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/generic/SDL_syssem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -85,7 +85,7 @@
 {
 	SDL_sem *sem;
 
-	sem = (SDL_sem *)malloc(sizeof(*sem));
+	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
 	if ( ! sem ) {
 		SDL_OutOfMemory();
 		return(0);
@@ -118,7 +118,7 @@
 		SDL_mutexP(sem->count_lock);
 		SDL_mutexV(sem->count_lock);
 		SDL_DestroyMutex(sem->count_lock);
-		free(sem);
+		SDL_free(sem);
 	}
 }
 
--- a/src/thread/linux/SDL_syscond.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/linux/SDL_syscond.c	Tue Feb 07 06:59:48 2006 +0000
@@ -62,11 +62,11 @@
 {
 	SDL_cond *cond;
 
-	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
+	cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
 	if ( cond ) {
 		if ( pthread_cond_init(&cond->cond, NULL) < 0 ) {
 			SDL_SetError("pthread_cond_init() failed");
-			free(cond);
+			SDL_free(cond);
 			cond = NULL;
 		}
 	}
@@ -78,7 +78,7 @@
 {
 	if ( cond ) {
 		pthread_cond_destroy(&cond->cond);
-		free(cond);
+		SDL_free(cond);
 	}
 }
 
--- a/src/thread/linux/SDL_sysmutex.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/linux/SDL_sysmutex.c	Tue Feb 07 06:59:48 2006 +0000
@@ -71,7 +71,7 @@
 #endif /* PTHREAD_RECURSIVE_MUTEX */
 		if ( pthread_mutex_init(&mutex->id, &attr) != 0 ) {
 			SDL_SetError("pthread_mutex_init() failed");
-			free(mutex);
+			SDL_free(mutex);
 			mutex = NULL;
 		}
 	} else {
@@ -84,7 +84,7 @@
 {
 	if ( mutex ) {
 		pthread_mutex_destroy(&mutex->id);
-		free(mutex);
+		SDL_free(mutex);
 	}
 }
 
--- a/src/thread/linux/SDL_syssem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/linux/SDL_syssem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -68,7 +68,7 @@
 /* Create a semaphore, initialized with value */
 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
 {
-	SDL_sem *sem = (SDL_sem *) malloc(sizeof(SDL_sem));
+	SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
 	if ( sem ) {
 #ifdef USE_NAMED_SEMAPHORES
 		static int semnum = 0;
@@ -78,7 +78,7 @@
 		sem->sem = sem_open(name, O_CREAT, 0600, initial_value);
 		if ( sem->sem == (sem_t *)SEM_FAILED ) {
 			SDL_SetError("sem_open(%s) failed", name);
-			free(sem);
+			SDL_free(sem);
 			sem = NULL;
 		} else {
 			sem_unlink(name);
@@ -86,7 +86,7 @@
 #else
 		if ( sem_init(&sem->sem_data, 0, initial_value) < 0 ) {
 			SDL_SetError("sem_init() failed");
-			free(sem);
+			SDL_free(sem);
 			sem = NULL;
 		} else {
 			sem->sem = &sem->sem_data;
@@ -106,7 +106,7 @@
 #else
 		sem_destroy(sem->sem);
 #endif
-		free(sem);
+		SDL_free(sem);
 	}
 }
 
@@ -245,7 +245,7 @@
 	union semun init;
 	key_t key;
 
-	sem = (SDL_sem *)malloc(sizeof(*sem));
+	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
 	if ( sem == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
@@ -269,7 +269,7 @@
 	/* Report the error if we eventually failed */
 	if ( sem->id < 0 ) {
 		SDL_SetError("Couldn't create semaphore");
-		free(sem);
+		SDL_free(sem);
 		return(NULL);
 	}
 	init.val = initial_value;	/* Initialize semaphore */
@@ -287,7 +287,7 @@
 		dummy.val = 0;
 		semctl(sem->id, 0, IPC_RMID, dummy);
 #endif
-		free(sem);
+		SDL_free(sem);
 	}
 }
 
--- a/src/thread/linux/SDL_systhread.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/linux/SDL_systhread.c	Tue Feb 07 06:59:48 2006 +0000
@@ -172,7 +172,7 @@
 	void *stack;
 
 	/* Allocate memory for thread stack */
-	stack = malloc(STACKSIZE);
+	stack = SDL_malloc(STACKSIZE);
 	if ( stack == (void *)0 ) {
 		SDL_OutOfMemory();
 		return(-1);
@@ -186,7 +186,7 @@
 	thread->handle = clone(RunThread, stack,
 			(CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND), args);
 	if ( thread->handle < 0 ) {
-		free(thread->data);
+		SDL_free(thread->data);
 		SDL_SetError("Not enough resources to create thread");
 		return(-1);
 	}
@@ -233,7 +233,7 @@
 	while ( system(command) == 0 )
 		sleep(1);
 #endif
-	free(thread->data);
+	SDL_free(thread->data);
 }
 
 void SDL_SYS_KillThread(SDL_Thread *thread)
--- a/src/thread/os2/SDL_syscond.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/os2/SDL_syscond.c	Tue Feb 07 06:59:48 2006 +0000
@@ -46,7 +46,7 @@
 {
 	SDL_cond *cond;
 
-	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
+	cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
 	if ( cond ) {
 		cond->lock = SDL_CreateMutex();
 		cond->wait_sem = SDL_CreateSemaphore(0);
@@ -75,7 +75,7 @@
 		if ( cond->lock ) {
 			SDL_DestroyMutex(cond->lock);
 		}
-		free(cond);
+		SDL_free(cond);
 	}
 }
 
--- a/src/thread/os2/SDL_sysmutex.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/os2/SDL_sysmutex.c	Tue Feb 07 06:59:48 2006 +0000
@@ -43,7 +43,7 @@
   APIRET ulrc;
 
   /* Allocate mutex memory */
-  mutex = (SDL_mutex *)malloc(sizeof(*mutex));
+  mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
   if (mutex)
   {
     /* Create the mutex, with initial value signaled */
@@ -54,7 +54,7 @@
     if (ulrc!=NO_ERROR)
     {
       SDL_SetError("Couldn't create mutex");
-      free(mutex);
+      SDL_free(mutex);
       mutex = NULL;
     }
   } else {
@@ -73,7 +73,7 @@
       DosCloseMutexSem(mutex->hmtxID);
       mutex->hmtxID = 0;
     }
-    free(mutex);
+    SDL_free(mutex);
   }
 }
 
--- a/src/thread/os2/SDL_syssem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/os2/SDL_syssem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -48,13 +48,13 @@
         ULONG ulrc;
 
         /* Allocate sem memory */
-        sem = (SDL_sem *)malloc(sizeof(*sem));
+        sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
         if ( sem ) {
                 /* Create the mutex semaphore */
                 ulrc = DosCreateMutexSem(NULL,&(sem->id),0,TRUE);
                 if ( ulrc ) {
                         SDL_SetError("Couldn't create semaphore");
-                        free(sem);
+                        SDL_free(sem);
                         sem = NULL;
                 } else
                 {
@@ -77,7 +77,7 @@
                         DosCloseMutexSem(sem->id);
                         sem->id = 0;
                 }
-                free(sem);
+                SDL_free(sem);
         }
 }
 
--- a/src/thread/os2/SDL_systhread.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/os2/SDL_systhread.c	Tue Feb 07 06:59:48 2006 +0000
@@ -51,7 +51,7 @@
   if (pThreadParms)
   {
     pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread;
-    free(pThreadParms);
+    SDL_free(pThreadParms);
   }
   // Call endthread!
   if (pfnCurrentEndThread)
@@ -60,7 +60,7 @@
 
 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
 {
-  pThreadStartParms pThreadParms = malloc(sizeof(tThreadStartParms));
+  pThreadStartParms pThreadParms = SDL_malloc(sizeof(tThreadStartParms));
   if (!pThreadParms)
   {
     SDL_SetError("Not enough memory to create thread");
--- a/src/thread/pth/SDL_syscond.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/pth/SDL_syscond.c	Tue Feb 07 06:59:48 2006 +0000
@@ -18,11 +18,11 @@
 {
 	SDL_cond *cond;
 
-	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
+	cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
 	if ( cond ) {
 		if ( pth_cond_init(&(cond->condpth_p)) < 0 ) {
 			SDL_SetError("pthread_cond_init() failed");
-			free(cond);
+			SDL_free(cond);
 			cond = NULL;
 		}
 	} else {
@@ -35,7 +35,7 @@
 void SDL_DestroyCond(SDL_cond *cond)
 {
 	if ( cond ) {
-		free(cond);
+		SDL_free(cond);
 	}
 }
 
--- a/src/thread/pth/SDL_sysmutex.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/pth/SDL_sysmutex.c	Tue Feb 07 06:59:48 2006 +0000
@@ -18,12 +18,12 @@
 	SDL_mutex *mutex;
 
 	/* Allocate mutex memory */
-	mutex = (SDL_mutex *)malloc(sizeof(*mutex));
+	mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
 	if ( mutex ) {
 		/* Create the mutex, with initial value signaled */
 	    if (!pth_mutex_init(&(mutex->mutexpth_p))) {
 			SDL_SetError("Couldn't create mutex");
-			free(mutex);
+			SDL_free(mutex);
 			mutex = NULL;
 		}
 	} else {
@@ -36,7 +36,7 @@
 void SDL_DestroyMutex(SDL_mutex *mutex)
 {
 	if ( mutex ) {
-		free(mutex);
+		SDL_free(mutex);
 	}
 }
 
--- a/src/thread/riscos/SDL_syscond.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/riscos/SDL_syscond.c	Tue Feb 07 06:59:48 2006 +0000
@@ -45,11 +45,11 @@
 {
 	SDL_cond *cond;
 
-	cond = (SDL_cond *) malloc(sizeof(SDL_cond));
+	cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
 	if ( cond ) {
 		if ( pthread_cond_init(&cond->cond, NULL) < 0 ) {
 			SDL_SetError("pthread_cond_init() failed");
-			free(cond);
+			SDL_free(cond);
 			cond = NULL;
 		}
 	}
@@ -61,7 +61,7 @@
 {
 	if ( cond ) {
 		pthread_cond_destroy(&cond->cond);
-		free(cond);
+		SDL_free(cond);
 	}
 }
 
--- a/src/thread/riscos/SDL_sysmutex.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/riscos/SDL_sysmutex.c	Tue Feb 07 06:59:48 2006 +0000
@@ -57,7 +57,7 @@
 #endif /* PTHREAD_NO_RECURSIVE_MUTEX */
 		if ( pthread_mutex_init(&mutex->id, &attr) != 0 ) {
 			SDL_SetError("pthread_mutex_init() failed");
-			free(mutex);
+			SDL_free(mutex);
 			mutex = NULL;
 		}
 	} else {
@@ -70,7 +70,7 @@
 {
 	if ( mutex ) {
 		pthread_mutex_destroy(&mutex->id);
-		free(mutex);
+		SDL_free(mutex);
 	}
 }
 
--- a/src/thread/riscos/SDL_syssem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/riscos/SDL_syssem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -90,11 +90,11 @@
 /* Create a semaphore, initialized with value */
 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
 {
-	SDL_sem *sem = (SDL_sem *) malloc(sizeof(SDL_sem));
+	SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
 	if ( sem ) {
 		if ( sem_init(&sem->sem_data, 0, initial_value) < 0 ) {
 			SDL_SetError("sem_init() failed");
-			free(sem);
+			SDL_free(sem);
 			sem = NULL;
 		} else {
 			sem->sem = &sem->sem_data;
@@ -109,7 +109,7 @@
 {
 	if ( sem ) {
 		sem_destroy(sem->sem);
-		free(sem);
+		SDL_free(sem);
 	}
 }
 
--- a/src/thread/win32/SDL_sysmutex.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/win32/SDL_sysmutex.c	Tue Feb 07 06:59:48 2006 +0000
@@ -39,13 +39,13 @@
 	SDL_mutex *mutex;
 
 	/* Allocate mutex memory */
-	mutex = (SDL_mutex *)malloc(sizeof(*mutex));
+	mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
 	if ( mutex ) {
 		/* Create the mutex, with initial value signaled */
 		mutex->id = CreateMutex(NULL, FALSE, NULL);
 		if ( ! mutex->id ) {
 			SDL_SetError("Couldn't create mutex");
-			free(mutex);
+			SDL_free(mutex);
 			mutex = NULL;
 		}
 	} else {
@@ -62,7 +62,7 @@
 			CloseHandle(mutex->id);
 			mutex->id = 0;
 		}
-		free(mutex);
+		SDL_free(mutex);
 	}
 }
 
--- a/src/thread/win32/SDL_syssem.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/win32/SDL_syssem.c	Tue Feb 07 06:59:48 2006 +0000
@@ -48,7 +48,7 @@
 	SDL_sem *sem;
 
 	/* Allocate sem memory */
-	sem = (SDL_sem *)malloc(sizeof(*sem));
+	sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
 	if ( sem ) {
 		/* Create the semaphore, with max value 32K */
 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
@@ -59,7 +59,7 @@
 		sem->count = initial_value;
 		if ( ! sem->id ) {
 			SDL_SetError("Couldn't create semaphore");
-			free(sem);
+			SDL_free(sem);
 			sem = NULL;
 		}
 	} else {
@@ -80,7 +80,7 @@
 #endif
 			sem->id = 0;
 		}
-		free(sem);
+		SDL_free(sem);
 	}
 }
 
--- a/src/thread/win32/SDL_systhread.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/thread/win32/SDL_systhread.c	Tue Feb 07 06:59:48 2006 +0000
@@ -47,7 +47,7 @@
   if (pThreadParms)
   {
     pfnCurrentEndThread = pThreadParms->pfnCurrentEndThread;
-    free(pThreadParms);
+    SDL_free(pThreadParms);
   }
   // Call endthread!
   if (pfnCurrentEndThread)
@@ -58,7 +58,7 @@
 int SDL_SYS_CreateThread(SDL_Thread *thread, void *args, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
 {
 	unsigned threadid;
-    pThreadStartParms pThreadParms = (pThreadStartParms)malloc(sizeof(tThreadStartParms));
+    pThreadStartParms pThreadParms = (pThreadStartParms)SDL_malloc(sizeof(tThreadStartParms));
     if (!pThreadParms) {
 		SDL_OutOfMemory();
         return(-1);
--- a/src/timer/SDL_timer.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/timer/SDL_timer.c	Tue Feb 07 06:59:48 2006 +0000
@@ -148,7 +148,7 @@
 					} else {
 						SDL_timers = next;
 					}
-					free(t);
+					SDL_free(t);
 					--SDL_timer_running;
 					removed = SDL_TRUE;
 				}
@@ -165,7 +165,7 @@
 static SDL_TimerID SDL_AddTimerInternal(Uint32 interval, SDL_NewTimerCallback callback, void *param)
 {
 	SDL_TimerID t;
-	t = (SDL_TimerID) malloc(sizeof(struct _SDL_TimerID));
+	t = (SDL_TimerID) SDL_malloc(sizeof(struct _SDL_TimerID));
 	if ( t ) {
 		t->interval = ROUND_RESOLUTION(interval);
 		t->cb = callback;
@@ -218,7 +218,7 @@
 			} else {
 				SDL_timers = t->next;
 			}
-			free(t);
+			SDL_free(t);
 			--SDL_timer_running;
 			removed = SDL_TRUE;
 			list_changed = SDL_TRUE;
@@ -256,7 +256,7 @@
 			while ( SDL_timers ) {
 				SDL_TimerID freeme = SDL_timers;
 				SDL_timers = SDL_timers->next;
-				free(freeme);
+				SDL_free(freeme);
 			}
 			SDL_timer_running = 0;
 			list_changed = SDL_TRUE;
--- a/src/timer/linux/SDL_systimer.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/timer/linux/SDL_systimer.c	Tue Feb 07 06:59:48 2006 +0000
@@ -256,7 +256,7 @@
 	struct sigaction action;
 
 	/* Set the alarm handler (Linux specific) */
-	memset(&action, 0, sizeof(action));
+	SDL_memset(&action, 0, sizeof(action));
 	action.sa_handler = HandleAlarm;
 	action.sa_flags = SA_RESTART;
 	sigemptyset(&action.sa_mask);
@@ -285,7 +285,7 @@
 {
 	struct itimerval timer;
 
-	memset(&timer, 0, (sizeof timer));
+	SDL_memset(&timer, 0, (sizeof timer));
 	setitimer(ITIMER_REAL, &timer, NULL);
 }
 
--- a/src/video/SDL_RLEaccel.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_RLEaccel.c	Tue Feb 07 06:59:48 2006 +0000
@@ -1467,7 +1467,7 @@
     }
 
     maxsize += sizeof(RLEDestFormat);
-    rlebuf = (Uint8 *)malloc(maxsize);
+    rlebuf = (Uint8 *)SDL_malloc(maxsize);
     if(!rlebuf) {
 	SDL_OutOfMemory();
 	return -1;
@@ -1597,13 +1597,13 @@
     /* Now that we have it encoded, release the original pixels */
     if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC
        && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
-	free( surface->pixels );
+	SDL_free( surface->pixels );
 	surface->pixels = NULL;
     }
 
     /* realloc the buffer to release unused memory */
     {
-	Uint8 *p = realloc(rlebuf, dst - rlebuf);
+	Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
 	if(!p)
 	    p = rlebuf;
 	surface->map->sw_data->aux_data = p;
@@ -1675,7 +1675,7 @@
 	    break;
 	}
 
-	rlebuf = (Uint8 *)malloc(maxsize);
+	rlebuf = (Uint8 *)SDL_malloc(maxsize);
 	if ( rlebuf == NULL ) {
 		SDL_OutOfMemory();
 		return(-1);
@@ -1731,14 +1731,14 @@
 		}
 		len = MIN(run, maxn);
 		ADD_COUNTS(skip, len);
-		memcpy(dst, srcbuf + runstart * bpp, len * bpp);
+		SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
 		dst += len * bpp;
 		run -= len;
 		runstart += len;
 		while(run) {
 		    len = MIN(run, maxn);
 		    ADD_COUNTS(0, len);
-		    memcpy(dst, srcbuf + runstart * bpp, len * bpp);
+		    SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
 		    dst += len * bpp;
 		    runstart += len;
 		    run -= len;
@@ -1757,14 +1757,14 @@
 	/* Now that we have it encoded, release the original pixels */
 	if((surface->flags & SDL_PREALLOC) != SDL_PREALLOC
 	   && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
-	    free( surface->pixels );
+	    SDL_free( surface->pixels );
 	    surface->pixels = NULL;
 	}
 
 	/* realloc the buffer to release unused memory */
 	{
 	    /* If realloc returns NULL, the original block is left intact */
-	    Uint8 *p = realloc(rlebuf, dst - rlebuf);
+	    Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
 	    if(!p)
 		p = rlebuf;
 	    surface->map->sw_data->aux_data = p;
@@ -1845,12 +1845,12 @@
 	uncopy_opaque = uncopy_transl = uncopy_32;
     }
 
-    surface->pixels = malloc(surface->h * surface->pitch);
+    surface->pixels = SDL_malloc(surface->h * surface->pitch);
     if ( !surface->pixels ) {
         return(SDL_FALSE);
     }
     /* fill background with transparent pixels */
-    memset(surface->pixels, 0, surface->h * surface->pitch);
+    SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
 
     dst = surface->pixels;
     srcbuf = (Uint8 *)(df + 1);
@@ -1909,7 +1909,7 @@
 		unsigned alpha_flag;
 
 		/* re-create the original surface */
-		surface->pixels = malloc(surface->h * surface->pitch);
+		surface->pixels = SDL_malloc(surface->h * surface->pitch);
 		if ( !surface->pixels ) {
 			/* Oh crap... */
 			surface->flags |= SDL_RLEACCEL;
@@ -1937,7 +1937,7 @@
 	}
 
 	if ( surface->map && surface->map->sw_data->aux_data ) {
-	    free(surface->map->sw_data->aux_data);
+	    SDL_free(surface->map->sw_data->aux_data);
 	    surface->map->sw_data->aux_data = NULL;
 	}
     }
--- a/src/video/SDL_blit_0.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_blit_0.c	Tue Feb 07 06:59:48 2006 +0000
@@ -297,7 +297,7 @@
 			}
 			bit = (byte&0x80)>>7;
 			if ( bit != ckey ) {
-				memcpy(dst, &palmap[bit*4], 3);
+				SDL_memcpy(dst, &palmap[bit*4], 3);
 			}
 			byte <<= 1;
 			dst += 3;
--- a/src/video/SDL_blit_N.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_blit_N.c	Tue Feb 07 06:59:48 2006 +0000
@@ -817,10 +817,10 @@
     static Uint32 features = 0xffffffff;
     if (features == 0xffffffff) {
         /* Provide an override for testing .. */
-        char *override = getenv("SDL_ALTIVEC_BLIT_FEATURES");
+        char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES");
         if (override) {
             features = 0;
-            sscanf(override, "%u", &features);
+            SDL_sscanf(override, "%u", &features);
         } else {
             features = ( 0
                 /* Feature 1 is has-MMX */
--- a/src/video/SDL_bmp.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_bmp.c	Tue Feb 07 06:59:48 2006 +0000
@@ -98,7 +98,7 @@
 		was_error = 1;
 		goto done;
 	}
-	if ( strncmp(magic, "BM", 2) != 0 ) {
+	if ( SDL_strncmp(magic, "BM", 2) != 0 ) {
 		SDL_SetError("File is not a Windows BMP file");
 		was_error = 1;
 		goto done;
@@ -135,7 +135,7 @@
 	}
 
 	/* Check for read error */
-	if ( strcmp(SDL_GetError(), "") != 0 ) {
+	if ( SDL_strcmp(SDL_GetError(), "") != 0 ) {
 		was_error = 1;
 		goto done;
 	}
@@ -519,7 +519,7 @@
 	if ( freedst && dst ) {
 		SDL_RWclose(dst);
 	}
-	return((strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
+	return((SDL_strcmp(SDL_GetError(), "") == 0) ? 0 : -1);
 }
 
 #endif /* ENABLE_FILE */
--- a/src/video/SDL_cursor.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_cursor.c	Tue Feb 07 06:59:48 2006 +0000
@@ -125,7 +125,7 @@
 	}
 
 	/* Allocate memory for the cursor */
-	cursor = (SDL_Cursor *)malloc(sizeof *cursor);
+	cursor = (SDL_Cursor *)SDL_malloc(sizeof *cursor);
 	if ( cursor == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
@@ -137,9 +137,9 @@
 	cursor->area.h = h;
 	cursor->hot_x = hot_x;
 	cursor->hot_y = hot_y;
-	cursor->data = (Uint8 *)malloc((w/8)*h*2);
+	cursor->data = (Uint8 *)SDL_malloc((w/8)*h*2);
 	cursor->mask = cursor->data+((w/8)*h);
-	cursor->save[0] = (Uint8 *)malloc(savelen*2);
+	cursor->save[0] = (Uint8 *)SDL_malloc(savelen*2);
 	cursor->save[1] = cursor->save[0] + savelen;
 	cursor->wm_cursor = NULL;
 	if ( ! cursor->data || ! cursor->save[0] ) {
@@ -151,7 +151,7 @@
 		cursor->data[i] = data[i];
 		cursor->mask[i] = mask[i] | data[i];
 	}
-	memset(cursor->save[0], 0, savelen*2);
+	SDL_memset(cursor->save[0], 0, savelen*2);
 
 	/* If the window manager gives us a good cursor, we're done! */
 	if ( video->CreateWMCursor ) {
@@ -244,15 +244,15 @@
 			SDL_VideoDevice *this  = current_video;
 
 			if ( cursor->data ) {
-				free(cursor->data);
+				SDL_free(cursor->data);
 			}
 			if ( cursor->save[0] ) {
-				free(cursor->save[0]);
+				SDL_free(cursor->save[0]);
 			}
 			if ( video && cursor->wm_cursor ) {
 				video->FreeWMCursor(this, cursor->wm_cursor);
 			}
-			free(cursor);
+			SDL_free(cursor);
 		}
 	}
 }
@@ -448,7 +448,7 @@
 				datab = *data++;
 				for ( i=0; i<8; ++i ) {
 					if ( maskb & 0x80 ) {
-						memset(dst,pixels[datab>>7],3);
+						SDL_memset(dst,pixels[datab>>7],3);
 					}
 					maskb <<= 1;
 					datab <<= 1;
@@ -523,7 +523,7 @@
 				}
 				if ( (x >= minx) && (x < maxx) ) {
 					if ( maskb & 0x80 ) {
-						memset(dst, pixels8[datab>>7], dstbpp);
+						SDL_memset(dst, pixels8[datab>>7], dstbpp);
 					}
 				}
 				maskb <<= 1;
@@ -541,7 +541,7 @@
 				}
 				if ( (x >= minx) && (x < maxx) ) {
 					if ( maskb & 0x80 ) {
-						memset(dst, pixels[datab>>7], dstbpp);
+						SDL_memset(dst, pixels[datab>>7], dstbpp);
 					}
 				}
 				maskb <<= 1;
@@ -616,7 +616,7 @@
 	  w = area.w*screenbpp;
 	  h = area.h;
 	  while ( h-- ) {
-		  memcpy(dst, src, w);
+		  SDL_memcpy(dst, src, w);
 		  dst += w;
 		  src += screen->pitch;
 	  }
@@ -694,7 +694,7 @@
 	  w = area.w*screenbpp;
 	  h = area.h;
 	  while ( h-- ) {
-		  memcpy(dst, src, w);
+		  SDL_memcpy(dst, src, w);
 		  src += w;
 		  dst += screen->pitch;
 	  }
@@ -748,6 +748,6 @@
 		savelen = SDL_cursor->area.w*4*SDL_cursor->area.h;
 		SDL_cursor->area.x = 0;
 		SDL_cursor->area.y = 0;
-		memset(SDL_cursor->save[0], 0, savelen);
+		SDL_memset(SDL_cursor->save[0], 0, savelen);
 	}
 }
--- a/src/video/SDL_gamma.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_gamma.c	Tue Feb 07 06:59:48 2006 +0000
@@ -165,13 +165,13 @@
 
 	/* Fill the gamma table with the new values */
 	if ( red ) {
-		memcpy(&video->gamma[0*256], red, 256*sizeof(*video->gamma));
+		SDL_memcpy(&video->gamma[0*256], red, 256*sizeof(*video->gamma));
 	}
 	if ( green ) {
-		memcpy(&video->gamma[1*256], green, 256*sizeof(*video->gamma));
+		SDL_memcpy(&video->gamma[1*256], green, 256*sizeof(*video->gamma));
 	}
 	if ( blue ) {
-		memcpy(&video->gamma[2*256], blue, 256*sizeof(*video->gamma));
+		SDL_memcpy(&video->gamma[2*256], blue, 256*sizeof(*video->gamma));
 	}
 
 	/* Gamma correction always possible on split palettes */
@@ -204,7 +204,7 @@
 
 	/* Lazily allocate the gamma table */
 	if ( ! video->gamma ) {
-		video->gamma = malloc(3*256*sizeof(*video->gamma));
+		video->gamma = SDL_malloc(3*256*sizeof(*video->gamma));
 		if ( ! video->gamma ) {
 			SDL_OutOfMemory();
 			return -1;
@@ -225,13 +225,13 @@
 
 	/* Just copy from our internal table */
 	if ( red ) {
-		memcpy(red, &video->gamma[0*256], 256*sizeof(*red));
+		SDL_memcpy(red, &video->gamma[0*256], 256*sizeof(*red));
 	}
 	if ( green ) {
-		memcpy(green, &video->gamma[1*256], 256*sizeof(*green));
+		SDL_memcpy(green, &video->gamma[1*256], 256*sizeof(*green));
 	}
 	if ( blue ) {
-		memcpy(blue, &video->gamma[2*256], 256*sizeof(*blue));
+		SDL_memcpy(blue, &video->gamma[2*256], 256*sizeof(*blue));
 	}
 	return 0;
 }
--- a/src/video/SDL_pixels.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_pixels.c	Tue Feb 07 06:59:48 2006 +0000
@@ -43,12 +43,12 @@
 	Uint32 mask;
 
 	/* Allocate an empty pixel format structure */
-	format = malloc(sizeof(*format));
+	format = SDL_malloc(sizeof(*format));
 	if ( format == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(format, 0, sizeof(*format));
+	SDL_memset(format, 0, sizeof(*format));
 	format->alpha = SDL_ALPHA_OPAQUE;
 
 	/* Set up the format */
@@ -125,14 +125,14 @@
 #ifdef DEBUG_PALETTE
 		fprintf(stderr,"bpp=%d ncolors=%d\n",bpp,ncolors);
 #endif
-		format->palette = (SDL_Palette *)malloc(sizeof(SDL_Palette));
+		format->palette = (SDL_Palette *)SDL_malloc(sizeof(SDL_Palette));
 		if ( format->palette == NULL ) {
 			SDL_FreeFormat(format);
 			SDL_OutOfMemory();
 			return(NULL);
 		}
 		(format->palette)->ncolors = ncolors;
-		(format->palette)->colors = (SDL_Color *)malloc(
+		(format->palette)->colors = (SDL_Color *)SDL_malloc(
 				(format->palette)->ncolors*sizeof(SDL_Color));
 		if ( (format->palette)->colors == NULL ) {
 			SDL_FreeFormat(format);
@@ -217,7 +217,7 @@
 			format->palette->colors[1].b = 0x00;
 		} else {
 			/* Create an empty palette */
-			memset((format->palette)->colors, 0,
+			SDL_memset((format->palette)->colors, 0,
 				(format->palette)->ncolors*sizeof(SDL_Color));
 		}
 	}
@@ -255,11 +255,11 @@
 	if ( format ) {
 		if ( format->palette ) {
 			if ( format->palette->colors ) {
-				free(format->palette->colors);
+				SDL_free(format->palette->colors);
 			}
-			free(format->palette);
+			SDL_free(format->palette);
 		}
-		free(format);
+		SDL_free(format);
 	}
 }
 /*
@@ -438,7 +438,7 @@
 	if ( identical ) {
 		if ( src->ncolors <= dst->ncolors ) {
 			/* If an identical palette, no need to map */
-			if ( memcmp(src->colors, dst->colors, src->ncolors*
+			if ( SDL_memcmp(src->colors, dst->colors, src->ncolors*
 						sizeof(SDL_Color)) == 0 ) {
 				*identical = 1;
 				return(NULL);
@@ -446,7 +446,7 @@
 		}
 		*identical = 0;
 	}
-	map = (Uint8 *)malloc(src->ncolors);
+	map = (Uint8 *)SDL_malloc(src->ncolors);
 	if ( map == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
@@ -466,7 +466,7 @@
 	unsigned alpha;
 
 	bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
-	map = (Uint8 *)malloc(src->ncolors*bpp);
+	map = (Uint8 *)SDL_malloc(src->ncolors*bpp);
 	if ( map == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
@@ -490,7 +490,7 @@
 	
 	/* SDL_DitherColors does not initialize the 'unused' component of colors,
 	   but Map1to1 compares it against dst, so we should initialize it. */  
-	memset(colors, 0, sizeof(colors));
+	SDL_memset(colors, 0, sizeof(colors));
 
 	dithered.ncolors = 256;
 	SDL_DitherColors(colors, 8);
@@ -503,21 +503,21 @@
 	SDL_BlitMap *map;
 
 	/* Allocate the empty map */
-	map = (SDL_BlitMap *)malloc(sizeof(*map));
+	map = (SDL_BlitMap *)SDL_malloc(sizeof(*map));
 	if ( map == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(map, 0, sizeof(*map));
+	SDL_memset(map, 0, sizeof(*map));
 
 	/* Allocate the software blit data */
-	map->sw_data = (struct private_swaccel *)malloc(sizeof(*map->sw_data));
+	map->sw_data = (struct private_swaccel *)SDL_malloc(sizeof(*map->sw_data));
 	if ( map->sw_data == NULL ) {
 		SDL_FreeBlitMap(map);
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(map->sw_data, 0, sizeof(*map->sw_data));
+	SDL_memset(map->sw_data, 0, sizeof(*map->sw_data));
 
 	/* It's ready to go */
 	return(map);
@@ -530,7 +530,7 @@
 	map->dst = NULL;
 	map->format_version = (unsigned int)-1;
 	if ( map->table ) {
-		free(map->table);
+		SDL_free(map->table);
 		map->table = NULL;
 	}
 }
@@ -615,8 +615,8 @@
 	if ( map ) {
 		SDL_InvalidateMap(map);
 		if ( map->sw_data != NULL ) {
-			free(map->sw_data);
+			SDL_free(map->sw_data);
 		}
-		free(map);
+		SDL_free(map);
 	}
 }
--- a/src/video/SDL_surface.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_surface.c	Tue Feb 07 06:59:48 2006 +0000
@@ -77,7 +77,7 @@
 	}
 
 	/* Allocate the surface */
-	surface = (SDL_Surface *)malloc(sizeof(*surface));
+	surface = (SDL_Surface *)SDL_malloc(sizeof(*surface));
 	if ( surface == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
@@ -103,7 +103,7 @@
 	}
 	surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
 	if ( surface->format == NULL ) {
-		free(surface);
+		SDL_free(surface);
 		return(NULL);
 	}
 	if ( Amask ) {
@@ -125,14 +125,14 @@
 	if ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) || 
 				(video->AllocHWSurface(this, surface) < 0) ) {
 		if ( surface->w && surface->h ) {
-			surface->pixels = malloc(surface->h*surface->pitch);
+			surface->pixels = SDL_malloc(surface->h*surface->pitch);
 			if ( surface->pixels == NULL ) {
 				SDL_FreeSurface(surface);
 				SDL_OutOfMemory();
 				return(NULL);
 			}
 			/* This is important for bitmaps */
-			memset(surface->pixels, 0, surface->h*surface->pitch);
+			SDL_memset(surface->pixels, 0, surface->h*surface->pitch);
 		}
 	}
 
@@ -615,7 +615,7 @@
 		} else {
 #ifdef __powerpc__
 			/*
-			 * memset() on PPC (both glibc and codewarrior) uses
+			 * SDL_memset() on PPC (both glibc and codewarrior) uses
 			 * the dcbz (Data Cache Block Zero) instruction, which
 			 * causes an alignment exception if the destination is
 			 * uncachable, so only use it on software surfaces
@@ -627,7 +627,7 @@
 					 * efficient to uncached video memory
 					 */
 					double fill;
-					memset(&fill, color, (sizeof fill));
+					SDL_memset(&fill, color, (sizeof fill));
 					for(y = dstrect->h; y; y--) {
 						Uint8 *d = row;
 						unsigned n = x;
@@ -679,7 +679,7 @@
 #endif /* __powerpc__ */
 			{
 				for(y = dstrect->h; y; y--) {
-					memset(row, color, x);
+					SDL_memset(row, color, x);
 					row += dst->pitch;
 				}
 			}
@@ -711,7 +711,7 @@
 			for ( y=dstrect->h; y; --y ) {
 				Uint8 *pixels = row;
 				for ( x=dstrect->w; x; --x ) {
-					memcpy(pixels, &color, 3);
+					SDL_memcpy(pixels, &color, 3);
 					pixels += 3;
 				}
 				row += dst->pitch;
@@ -832,7 +832,7 @@
 
 	/* Copy the palette if any */
 	if ( format->palette && convert->format->palette ) {
-		memcpy(convert->format->palette->colors,
+		SDL_memcpy(convert->format->palette->colors,
 				format->palette->colors,
 				format->palette->ncolors*sizeof(SDL_Color));
 		convert->format->palette->ncolors = format->palette->ncolors;
@@ -934,9 +934,9 @@
 	}
 	if ( surface->pixels &&
 	     ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC) ) {
-		free(surface->pixels);
+		SDL_free(surface->pixels);
 	}
-	free(surface);
+	SDL_free(surface);
 #ifdef CHECK_LEAKS
 	--surfaces_allocated;
 #endif
--- a/src/video/SDL_video.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_video.c	Tue Feb 07 06:59:48 2006 +0000
@@ -175,13 +175,13 @@
 	video = NULL;
 	if ( driver_name != NULL ) {
 #if 0	/* This will be replaced with a better driver selection API */
-		if ( strrchr(driver_name, ':') != NULL ) {
-			index = atoi(strrchr(driver_name, ':')+1);
+		if ( SDL_strrchr(driver_name, ':') != NULL ) {
+			index = atoi(SDL_strrchr(driver_name, ':')+1);
 		}
 #endif
 		for ( i=0; bootstrap[i]; ++i ) {
-			if ( strncmp(bootstrap[i]->name, driver_name,
-			             strlen(bootstrap[i]->name)) == 0 ) {
+			if ( SDL_strncmp(bootstrap[i]->name, driver_name,
+			             SDL_strlen(bootstrap[i]->name)) == 0 ) {
 				if ( bootstrap[i]->available() ) {
 					video = bootstrap[i]->create(index);
 					break;
@@ -216,7 +216,7 @@
 	video->wm_icon  = NULL;
 	video->offset_x = 0;
 	video->offset_y = 0;
-	memset(&video->info, 0, (sizeof video->info));
+	SDL_memset(&video->info, 0, (sizeof video->info));
 	
 	video->displayformatalphapixel = NULL;
 
@@ -244,7 +244,7 @@
 	video->gl_config.multisamplesamples = 0;
 	
 	/* Initialize the video subsystem */
-	memset(&vformat, 0, sizeof(vformat));
+	SDL_memset(&vformat, 0, sizeof(vformat));
 	if ( video->VideoInit(video, &vformat) < 0 ) {
 		SDL_VideoQuit();
 		return(-1);
@@ -289,7 +289,7 @@
 char *SDL_VideoDriverName(char *namebuf, int maxlen)
 {
 	if ( current_video != NULL ) {
-		strncpy(namebuf, current_video->name, maxlen-1);
+		SDL_strncpy(namebuf, current_video->name, maxlen-1);
 		namebuf[maxlen-1] = '\0';
 		return(namebuf);
 	}
@@ -389,7 +389,7 @@
 	}
 
 	/* Search through the list valid of modes */
-	memset(&format, 0, sizeof(format));
+	SDL_memset(&format, 0, sizeof(format));
 	supported = 0;
 	table = ((bpp+7)/8)-1;
 	SDL_closest_depths[table][0] = bpp;
@@ -461,7 +461,7 @@
 	}
 
 	/* No exact size match at any depth, look for closest match */
-	memset(&format, 0, sizeof(format));
+	SDL_memset(&format, 0, sizeof(format));
 	supported = 0;
 	table = ((*BitsPerPixel+7)/8)-1;
 	SDL_closest_depths[table][0] = *BitsPerPixel;
@@ -541,7 +541,7 @@
 	if ( SDL_ShadowSurface->format->palette ) {
 		SDL_ShadowSurface->flags |= SDL_HWPALETTE;
 		if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) {
-			memcpy(SDL_ShadowSurface->format->palette->colors,
+			SDL_memcpy(SDL_ShadowSurface->format->palette->colors,
 				SDL_VideoSurface->format->palette->colors,
 				SDL_VideoSurface->format->palette->ncolors*
 							sizeof(SDL_Color));
@@ -649,12 +649,12 @@
 		SDL_FreeSurface(ready_to_go);
 	}
 	if ( video->physpal ) {
-		free(video->physpal->colors);
-		free(video->physpal);
+		SDL_free(video->physpal->colors);
+		SDL_free(video->physpal);
 		video->physpal = NULL;
 	}
 	if( video->gammacols) {
-		free(video->gammacols);
+		SDL_free(video->gammacols);
 		video->gammacols = NULL;
 	}
 
@@ -797,7 +797,7 @@
 		   support the GL_UNSIGNED_SHORT_5_6_5 texture format.
 		 */
 		if ( (bpp == 16) &&
-		     (strstr((const char *)video->glGetString(GL_EXTENSIONS), "GL_EXT_packed_pixels") ||
+		     (SDL_strstr((const char *)video->glGetString(GL_EXTENSIONS), "GL_EXT_packed_pixels") ||
 		     (atof((const char *)video->glGetString(GL_VERSION)) >= 1.2f))
 		   ) {
 			video->is_32bit = 0;
@@ -843,7 +843,7 @@
 		SDL_FreeSurface(mode);
 
 		/* Set the surface completely opaque & white by default */
-		memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch );
+		SDL_memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch );
 		video->glGenTextures( 1, &video->texture );
 		video->glBindTexture( GL_TEXTURE_2D, video->texture );
 		video->glTexImage2D(
@@ -1134,7 +1134,7 @@
 	SDL_Palette *vidpal;
 
 	if ( colors != (pal->colors + firstcolor) ) {
-		memcpy(pal->colors + firstcolor, colors,
+		SDL_memcpy(pal->colors + firstcolor, colors,
 		       ncolors * sizeof(*colors));
 	}
 
@@ -1146,7 +1146,7 @@
 		 * changes to its logical palette so that
 		 * updates are always identity blits
 		 */
-		memcpy(vidpal->colors + firstcolor, colors,
+		SDL_memcpy(vidpal->colors + firstcolor, colors,
 		       ncolors * sizeof(*colors));
 	}
 	SDL_FormatChanged(screen);
@@ -1162,7 +1162,7 @@
 		/* We need to copy the new colors, since we haven't
 		 * already done the copy in the logical set above.
 		 */
-		memcpy(video->physpal->colors + firstcolor,
+		SDL_memcpy(video->physpal->colors + firstcolor,
 		       colors, ncolors * sizeof(*colors));
 	}
 	if ( screen == SDL_ShadowSurface ) {
@@ -1187,7 +1187,7 @@
 					SDL_Palette *pp = video->physpal;
 					if(!pp)
 						pp = screen->format->palette;
-					video->gammacols = malloc(pp->ncolors
+					video->gammacols = SDL_malloc(pp->ncolors
 							  * sizeof(SDL_Color));
 					SDL_ApplyGamma(video->gamma,
 						       pp->colors,
@@ -1284,18 +1284,18 @@
 		if(!video->physpal && !(which & SDL_LOGPAL) ) {
 			/* Lazy physical palette allocation */
 			int size;
-			SDL_Palette *pp = malloc(sizeof(*pp));
+			SDL_Palette *pp = SDL_malloc(sizeof(*pp));
 			if ( !pp ) {
 				return 0;
 			}
 			current_video->physpal = pp;
 			pp->ncolors = pal->ncolors;
 			size = pp->ncolors * sizeof(SDL_Color);
-			pp->colors = malloc(size);
+			pp->colors = SDL_malloc(size);
 			if ( !pp->colors ) {
 				return 0;
 			}
-			memcpy(pp->colors, pal->colors, size);
+			SDL_memcpy(pp->colors, pal->colors, size);
 		}
 		if ( ! SetPalette_physical(screen,
 		                           colors, firstcolor, ncolors) ) {
@@ -1351,24 +1351,24 @@
 
 		/* Clean up miscellaneous memory */
 		if ( video->physpal ) {
-			free(video->physpal->colors);
-			free(video->physpal);
+			SDL_free(video->physpal->colors);
+			SDL_free(video->physpal);
 			video->physpal = NULL;
 		}
 		if ( video->gammacols ) {
-			free(video->gammacols);
+			SDL_free(video->gammacols);
 			video->gammacols = NULL;
 		}
 		if ( video->gamma ) {
-			free(video->gamma);
+			SDL_free(video->gamma);
 			video->gamma = NULL;
 		}
 		if ( video->wm_title != NULL ) {
-			free(video->wm_title);
+			SDL_free(video->wm_title);
 			video->wm_title = NULL;
 		}
 		if ( video->wm_icon != NULL ) {
-			free(video->wm_icon);
+			SDL_free(video->wm_icon);
 			video->wm_icon = NULL;
 		}
 
@@ -1668,20 +1668,20 @@
 	if ( video ) {
 		if ( title ) {
 			if ( video->wm_title ) {
-				free(video->wm_title);
+				SDL_free(video->wm_title);
 			}
-			video->wm_title = (char *)malloc(strlen(title)+1);
+			video->wm_title = (char *)SDL_malloc(SDL_strlen(title)+1);
 			if ( video->wm_title != NULL ) {
-				strcpy(video->wm_title, title);
+				SDL_strcpy(video->wm_title, title);
 			}
 		}
 		if ( icon ) {
 			if ( video->wm_icon ) {
-				free(video->wm_icon);
+				SDL_free(video->wm_icon);
 			}
-			video->wm_icon = (char *)malloc(strlen(icon)+1);
+			video->wm_icon = (char *)SDL_malloc(SDL_strlen(icon)+1);
 			if ( video->wm_icon != NULL ) {
-				strcpy(video->wm_icon, icon);
+				SDL_strcpy(video->wm_icon, icon);
 			}
 		}
 		if ( (title || icon) && (video->SetCaption != NULL) ) {
@@ -1773,18 +1773,18 @@
 		if ( mask == NULL ) {
 			int mask_len = icon->h*(icon->w+7)/8;
 			int flags = 0;
-			mask = (Uint8 *)malloc(mask_len);
+			mask = (Uint8 *)SDL_malloc(mask_len);
 			if ( mask == NULL ) {
 				return;
 			}
-			memset(mask, ~0, mask_len);
+			SDL_memset(mask, ~0, mask_len);
 			if ( icon->flags & SDL_SRCCOLORKEY ) flags |= 1;
 			if ( icon->flags & SDL_SRCALPHA ) flags |= 2;
 			if( flags ) {
 				CreateMaskFromColorKeyOrAlpha(icon, mask, flags);
 			}
 			video->SetIcon(video, icon, mask);
-			free(mask);
+			SDL_free(mask);
 		} else {
 			video->SetIcon(this, icon, mask);
 		}
--- a/src/video/SDL_yuv.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_yuv.c	Tue Feb 07 06:59:48 2006 +0000
@@ -44,7 +44,7 @@
 	}
 
 	/* Display directly on video surface, if possible */
-	if ( getenv("SDL_VIDEO_YUV_DIRECT") ) {
+	if ( SDL_getenv("SDL_VIDEO_YUV_DIRECT") ) {
 		if ( (display == SDL_PublicSurface) &&
 		     ((SDL_VideoSurface->format->BytesPerPixel == 2) ||
 		      (SDL_VideoSurface->format->BytesPerPixel == 4)) ) {
@@ -52,7 +52,7 @@
 		}
 	}
 	overlay = NULL;
-        yuv_hwaccel = getenv("SDL_VIDEO_YUV_HWACCEL");
+        yuv_hwaccel = SDL_getenv("SDL_VIDEO_YUV_HWACCEL");
 	if ( ((display == SDL_VideoSurface) && video->CreateYUVOverlay) &&
 	     (!yuv_hwaccel || (*yuv_hwaccel != '0')) ) {
 		overlay = video->CreateYUVOverlay(this, w, h, format, display);
@@ -85,6 +85,6 @@
 		if ( overlay->hwfuncs ) {
 			overlay->hwfuncs->FreeHW(current_video, overlay);
 		}
-		free(overlay);
+		SDL_free(overlay);
 	}
 }
--- a/src/video/SDL_yuv_sw.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/SDL_yuv_sw.c	Tue Feb 07 06:59:48 2006 +0000
@@ -960,12 +960,12 @@
 	}
 
 	/* Create the overlay structure */
-	overlay = (SDL_Overlay *)malloc(sizeof *overlay);
+	overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay);
 	if ( overlay == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(overlay, 0, (sizeof *overlay));
+	SDL_memset(overlay, 0, (sizeof *overlay));
 
 	/* Fill in the basic members */
 	overlay->format = format;
@@ -976,7 +976,7 @@
 	overlay->hwfuncs = &sw_yuvfuncs;
 
 	/* Create the pixel data and lookup tables */
-	swdata = (struct private_yuvhwdata *)malloc(sizeof *swdata);
+	swdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *swdata);
 	overlay->hwdata = swdata;
 	if ( swdata == NULL ) {
 		SDL_OutOfMemory();
@@ -985,13 +985,13 @@
 	}
 	swdata->stretch = NULL;
 	swdata->display = display;
-	swdata->pixels = (Uint8 *) malloc(width*height*2);
-	swdata->colortab = (int *)malloc(4*256*sizeof(int));
+	swdata->pixels = (Uint8 *) SDL_malloc(width*height*2);
+	swdata->colortab = (int *)SDL_malloc(4*256*sizeof(int));
 	Cr_r_tab = &swdata->colortab[0*256];
 	Cr_g_tab = &swdata->colortab[1*256];
 	Cb_g_tab = &swdata->colortab[2*256];
 	Cb_b_tab = &swdata->colortab[3*256];
-	swdata->rgb_2_pix = (Uint32 *)malloc(3*768*sizeof(Uint32));
+	swdata->rgb_2_pix = (Uint32 *)SDL_malloc(3*768*sizeof(Uint32));
 	r_2_pix_alloc = &swdata->rgb_2_pix[0*768];
 	g_2_pix_alloc = &swdata->rgb_2_pix[1*768];
 	b_2_pix_alloc = &swdata->rgb_2_pix[2*768];
@@ -1279,14 +1279,14 @@
 			SDL_FreeSurface(swdata->stretch);
 		}
 		if ( swdata->pixels ) {
-			free(swdata->pixels);
+			SDL_free(swdata->pixels);
 		}
 		if ( swdata->colortab ) {
-			free(swdata->colortab);
+			SDL_free(swdata->colortab);
 		}
 		if ( swdata->rgb_2_pix ) {
-			free(swdata->rgb_2_pix);
+			SDL_free(swdata->rgb_2_pix);
 		}
-		free(swdata);
+		SDL_free(swdata);
 	}
 }
--- a/src/video/Xext/Xv/Xv.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/Xext/Xv/Xv.c	Tue Feb 07 06:59:48 2006 +0000
@@ -234,7 +234,7 @@
           SyncHandle();
 	  return(XvBadAlloc);
 	}
-      (void)strncpy(name, u.string, size);
+      (void)SDL_strncpy(name, u.string, size);
       name[size] = '\0';
       pa->name = name;
 
@@ -386,7 +386,7 @@
           SyncHandle();
 	  return(XvBadAlloc);
       }
-      strncpy(name, u.string, size);
+      SDL_strncpy(name, u.string, size);
       name[size] = '\0';
       pe->name = name;
       pe++;
@@ -902,7 +902,7 @@
 	      ret[i].id = Info.id;	      
 	      ret[i].type = Info.type;	      
 	      ret[i].byte_order = Info.byte_order;	      
-	      memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16);
+	      SDL_memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16);
 	      ret[i].bits_per_pixel = Info.bpp;	      
   	      ret[i].format = Info.format;	      
    	      ret[i].num_planes = Info.num_planes;	      
@@ -919,7 +919,7 @@
     	      ret[i].vert_y_period = Info.vert_y_period;
     	      ret[i].vert_u_period = Info.vert_u_period;
     	      ret[i].vert_v_period = Info.vert_v_period;
-	      memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32);
+	      SDL_memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32);
     	      ret[i].scanline_order = Info.scanline_order;
 	      (*num)++;
 	  }
--- a/src/video/Xext/Xxf86dga/XF86DGA.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/Xext/Xxf86dga/XF86DGA.c	Tue Feb 07 06:59:48 2006 +0000
@@ -407,12 +407,12 @@
     MapPtr *old;
 
     old = mapList;
-    mapList = realloc(mapList, sizeof(MapPtr) * (numMaps + 1));
+    mapList = SDL_realloc(mapList, sizeof(MapPtr) * (numMaps + 1));
     if (!mapList) {
 	mapList = old;
 	return NULL;
     }
-    mapList[numMaps] = malloc(sizeof(MapRec));
+    mapList[numMaps] = SDL_malloc(sizeof(MapRec));
     if (!mapList[numMaps])
 	return NULL;
     return mapList[numMaps++];
@@ -424,12 +424,12 @@
     ScrPtr *old;
 
     old = scrList;
-    scrList = realloc(scrList, sizeof(ScrPtr) * (numScrs + 1));
+    scrList = SDL_realloc(scrList, sizeof(ScrPtr) * (numScrs + 1));
     if (!scrList) {
 	scrList = old;
 	return NULL;
     }
-    scrList[numScrs] = malloc(sizeof(ScrRec));
+    scrList[numScrs] = SDL_malloc(sizeof(ScrRec));
     if (!scrList[numScrs])
 	return NULL;
     return scrList[numScrs++];
--- a/src/video/aalib/SDL_aavideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/aalib/SDL_aavideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -70,8 +70,8 @@
 
 static void AA_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *AA_CreateDevice(int devindex)
@@ -79,20 +79,20 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	device->VideoInit = AA_VideoInit;
@@ -138,7 +138,7 @@
 
 	/* Initialize all variables that we clean on shutdown */
 	for ( i=0; i<SDL_NUMMODES; ++i ) {
-		SDL_modelist[i] = malloc(sizeof(SDL_Rect));
+		SDL_modelist[i] = SDL_malloc(sizeof(SDL_Rect));
 		SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
 	}
 	/* Modes sorted largest to smallest */
@@ -179,7 +179,7 @@
 
 	fprintf(stderr,"Using AAlib driver: %s (%s)\n", AA_context->driver->name, AA_context->driver->shortname);
 
-	AA_in_x11 = (strcmp(AA_context->driver->shortname,"X11") == 0);
+	AA_in_x11 = (SDL_strcmp(AA_context->driver->shortname,"X11") == 0);
 	/* Determine the screen depth (use default 8-bit depth) */
 	vformat->BitsPerPixel = 8;
 	vformat->BytesPerPixel = 1;
@@ -252,10 +252,10 @@
 	int mode;
 
 	if ( AA_buffer ) {
-		free( AA_buffer );
+		SDL_free( AA_buffer );
 	}
 
-	AA_buffer = malloc(width * height);
+	AA_buffer = SDL_malloc(width * height);
 	if ( ! AA_buffer ) {
 		SDL_SetError("Couldn't allocate buffer for requested mode");
 		return(NULL);
@@ -263,8 +263,8 @@
 
 /* 	printf("Setting mode %dx%d\n", width, height); */
 
-	memset(aa_image(AA_context), 0, aa_imgwidth(AA_context) * aa_imgheight(AA_context));
-	memset(AA_buffer, 0, width * height);
+	SDL_memset(aa_image(AA_context), 0, aa_imgwidth(AA_context) * aa_imgheight(AA_context));
+	SDL_memset(AA_buffer, 0, width * height);
 
 	/* Allocate the new pixel format for the screen */
 	if ( ! SDL_ReallocFormat(current, 8, 0, 0, 0, 0) ) {
@@ -379,7 +379,7 @@
 	/* Free video mode lists */
 	for ( i=0; i<SDL_NUMMODES; ++i ) {
 		if ( SDL_modelist[i] != NULL ) {
-			free(SDL_modelist[i]);
+			SDL_free(SDL_modelist[i]);
 			SDL_modelist[i] = NULL;
 		}
 	}
--- a/src/video/ataricommon/SDL_atarievents.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/ataricommon/SDL_atarievents.c	Tue Feb 07 06:59:48 2006 +0000
@@ -82,25 +82,25 @@
 			break;
 	}
 
-	envr = getenv("SDL_ATARI_EVENTSDRIVER");
+	envr = SDL_getenv("SDL_ATARI_EVENTSDRIVER");
 
  	if (!envr) {
 		return;
 	}
 
-	if (strcmp(envr, "ikbd") == 0) {
+	if (SDL_strcmp(envr, "ikbd") == 0) {
 		this->InitOSKeymap=AtariIkbd_InitOSKeymap;
 		this->PumpEvents=AtariIkbd_PumpEvents;
 		Atari_ShutdownEvents=AtariIkbd_ShutdownEvents;
 	}
 
-	if (strcmp(envr, "gemdos") == 0) {
+	if (SDL_strcmp(envr, "gemdos") == 0) {
 		this->InitOSKeymap=AtariGemdos_InitOSKeymap;
 		this->PumpEvents=AtariGemdos_PumpEvents;
 		Atari_ShutdownEvents=AtariGemdos_ShutdownEvents;
 	}
 
-	if (strcmp(envr, "bios") == 0) {
+	if (SDL_strcmp(envr, "bios") == 0) {
 		this->InitOSKeymap=AtariBios_InitOSKeymap;
 		this->PumpEvents=AtariBios_PumpEvents;
 		Atari_ShutdownEvents=AtariBios_ShutdownEvents;
--- a/src/video/ataricommon/SDL_atarigl.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/ataricommon/SDL_atarigl.c	Tue Feb 07 06:59:48 2006 +0000
@@ -141,7 +141,7 @@
 	handle = SDL_LoadObject(path);
 	if (handle == NULL) {
 		/* Try to load another one */
-		path = getenv("SDL_VIDEO_GL_DRIVER");
+		path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
 		if ( path != NULL ) {
 			handle = SDL_LoadObject(path);
 		}
@@ -223,10 +223,10 @@
 
 	this->gl_config.dll_handle = handle;
 	if ( path ) {
-		strncpy(this->gl_config.driver_path, path,
+		SDL_strncpy(this->gl_config.driver_path, path,
 			sizeof(this->gl_config.driver_path)-1);
 	} else {
-		strcpy(this->gl_config.driver_path, "");
+		SDL_strcpy(this->gl_config.driver_path, "");
 	}
 
 #endif
@@ -697,7 +697,7 @@
 	}
 
 	for (y=0; y<surface->h; y++) {
-		memcpy(dstline, srcline, srcpitch);
+		SDL_memcpy(dstline, srcline, srcpitch);
 
 		srcline += srcpitch;
 		dstline += dstpitch;
--- a/src/video/ataricommon/SDL_biosevents.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/ataricommon/SDL_biosevents.c	Tue Feb 07 06:59:48 2006 +0000
@@ -70,8 +70,8 @@
 	int i, vectors_mask;
 	unsigned long dummy;
 
-	memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
-	memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
+	SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
+	SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
 
 	/* Initialize keymap */
 	for ( i=0; i<sizeof(keymap); i++ )
@@ -117,7 +117,7 @@
 	SDL_keysym keysym;
 
 	/* Update pressed keys */
-	memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
+	SDL_memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
 
 	while (Bconstat(_CON)) {
 		unsigned long key_pressed;
@@ -151,7 +151,7 @@
 	SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
 
 	/* Will be previous table */
-	memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
+	SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
 }
 
 static void UpdateSpecialKeys(int special_keys_state)
--- a/src/video/ataricommon/SDL_gemdosevents.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/ataricommon/SDL_gemdosevents.c	Tue Feb 07 06:59:48 2006 +0000
@@ -75,8 +75,8 @@
 	int i, vectors_mask;
 	unsigned long dummy;
 
-	memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
-	memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
+	SDL_memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
+	SDL_memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
 
 	/* Initialize keymap */
 	for ( i=0; i<sizeof(keymap); i++ )
@@ -122,7 +122,7 @@
 	SDL_keysym keysym;
 
 	/* Update pressed keys */
-	memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
+	SDL_memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
 
 	while (Cconis()!=DEV_BUSY) {
 		unsigned long key_pressed;
@@ -156,7 +156,7 @@
 	SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
 
 	/* Will be previous table */
-	memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS);
+	SDL_memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS);
 }
 
 static void UpdateSpecialKeys(int special_keys_state)
--- a/src/video/ataricommon/SDL_ikbdevents.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/ataricommon/SDL_ikbdevents.c	Tue Feb 07 06:59:48 2006 +0000
@@ -78,7 +78,7 @@
 {
 	int i;
 
-	memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
+	SDL_memset(SDL_AtariIkbd_keyboard, KEY_UNDEFINED, ATARIBIOS_MAXKEYS);
 
 	/* Initialize keymap */
 	for ( i=0; i<sizeof(keymap); i++ )
--- a/src/video/bwindow/SDL_BWin.h	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/bwindow/SDL_BWin.h	Tue Feb 07 06:59:48 2006 +0000
@@ -331,7 +331,7 @@
 
 		if ((uchar)buf[0] > 127) {
 			state = 0;
-			srclen = strlen(buf);
+			srclen = SDL_strlen(buf);
 			dstlen = sizeof(destbuf);
 			convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen, (char *)destbuf, &dstlen, &state);
 			unicode = destbuf[0];
--- a/src/video/bwindow/SDL_sysmouse.cc	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/bwindow/SDL_sysmouse.cc	Tue Feb 07 06:59:48 2006 +0000
@@ -60,14 +60,14 @@
 	}
 
 	/* Allocate the cursor */
-	cursor = (WMcursor *)malloc(sizeof(WMcursor));
+	cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
 	if ( cursor == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	cursor->bits = (char *)malloc(4+2*((allowed_x/8)*allowed_y));
+	cursor->bits = (char *)SDL_malloc(4+2*((allowed_x/8)*allowed_y));
 	if ( cursor->bits == NULL ) {
-		free(cursor);
+		SDL_free(cursor);
 		SDL_OutOfMemory();
 		return(NULL);
 	}
@@ -81,13 +81,13 @@
 	run = PADDED_BITS(w);
 	pad = PADDED_BITS(allowed_x)-run;
 	for ( i=0; i<h; ++i ) {
-		memcpy(cptr, data, run);
-		memset(cptr+run, 0, pad);
+		SDL_memcpy(cptr, data, run);
+		SDL_memset(cptr+run, 0, pad);
 		data += run;
 		cptr += (run+pad);
 	}
 	for ( ; i<allowed_y; ++i ) {
-		memset(cptr, 0, run+pad);
+		SDL_memset(cptr, 0, run+pad);
 		cptr += (run+pad);
 	}
 	for ( i=0; i<h; ++i ) {
@@ -95,13 +95,13 @@
 		   inverted color pixels black, since inverted color pixels
 		   aren't supported under BeOS.
 		 */
-		memcpy(cptr, mask, run);
-		memset(cptr+run, 0, pad);
+		SDL_memcpy(cptr, mask, run);
+		SDL_memset(cptr+run, 0, pad);
 		mask += run;
 		cptr += (run+pad);
 	}
 	for ( ; i<allowed_y; ++i ) {
-		memset(cptr, 0, run+pad);
+		SDL_memset(cptr, 0, run+pad);
 		cptr += (run+pad);
 	}
 	return(cursor);
@@ -124,8 +124,8 @@
 
 void BE_FreeWMCursor(_THIS, WMcursor *cursor)
 {
-	free(cursor->bits);
-	free(cursor);
+	SDL_free(cursor->bits);
+	SDL_free(cursor);
 }
 
 /* Implementation by Christian Bauer <cbauer@student.physik.uni-mainz.de> */
--- a/src/video/bwindow/SDL_sysvideo.cc	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/bwindow/SDL_sysvideo.cc	Tue Feb 07 06:59:48 2006 +0000
@@ -82,8 +82,8 @@
 
 static void BE_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *BE_CreateDevice(int devindex)
@@ -91,20 +91,20 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	/* Initialization/Query functions */
@@ -233,7 +233,7 @@
 	}
 
 	/* Set up the new video mode rectangle */
-	mode = (SDL_Rect *)malloc(sizeof *mode);
+	mode = (SDL_Rect *)SDL_malloc(sizeof *mode);
 	if ( mode == NULL ) {
 		SDL_OutOfMemory();
 		return(-1);
@@ -249,11 +249,11 @@
 	/* Allocate the new list of modes, and fill in the new mode */
 	next_mode = SDL_nummodes[index];
 	SDL_modelist[index] = (SDL_Rect **)
-	       realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
+	       SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
 	if ( SDL_modelist[index] == NULL ) {
 		SDL_OutOfMemory();
 		SDL_nummodes[index] = 0;
-		free(mode);
+		SDL_free(mode);
 		return(-1);
 	}
 	SDL_modelist[index][next_mode] = mode;
@@ -642,7 +642,7 @@
 				if (get_image_symbol((image_id)cookie,"glBegin",B_SYMBOL_TYPE_ANY,&location) == B_OK) {
 					_this->gl_config.dll_handle = (void*)cookie;
 					_this->gl_config.driver_loaded = 1;
-					strncpy(_this->gl_config.driver_path, "libGL.so", sizeof(_this->gl_config.driver_path)-1);
+					SDL_strncpy(_this->gl_config.driver_path, "libGL.so", sizeof(_this->gl_config.driver_path)-1);
 				}
 			}
 		}
@@ -670,7 +670,7 @@
 
 		if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) {
 			_this->gl_config.driver_loaded = 1;
-			strncpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path)-1);
+			SDL_strncpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path)-1);
 		}*/
 	}
 
@@ -679,7 +679,7 @@
 	} else {
 		_this->gl_config.dll_handle = NULL;
 		_this->gl_config.driver_loaded = 0;
-		strcpy(_this->gl_config.driver_path, "");
+		SDL_strcpy(_this->gl_config.driver_path, "");
 		return -1;
 	}
 }
@@ -805,9 +805,9 @@
 	for ( i=0; i<NUM_MODELISTS; ++i ) {
 		if ( SDL_modelist[i] ) {
 			for ( j=0; SDL_modelist[i][j]; ++j ) {
-				free(SDL_modelist[i][j]);
+				SDL_free(SDL_modelist[i][j]);
 			}
-			free(SDL_modelist[i]);
+			SDL_free(SDL_modelist[i]);
 			SDL_modelist[i] = NULL;
 		}
 	}
--- a/src/video/bwindow/SDL_sysyuv.cc	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/bwindow/SDL_sysyuv.cc	Tue Feb 07 06:59:48 2006 +0000
@@ -312,7 +312,7 @@
 
 	delete overlay->hwdata->bbitmap;
 
-    free(overlay->hwdata);
+    SDL_free(overlay->hwdata);
 }
 
 }; // extern "C"
--- a/src/video/cybergfx/SDL_amigamouse.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/cybergfx/SDL_amigamouse.c	Tue Feb 07 06:59:48 2006 +0000
@@ -90,7 +90,7 @@
 						&mouse_accel.numerator, 
 						&mouse_accel.denominator,
 						&mouse_accel.threshold);
-			use_mouse_accel = getenv("SDL_VIDEO_X11_MOUSEACCEL");
+			use_mouse_accel = SDL_getenv("SDL_VIDEO_X11_MOUSEACCEL");
 			if ( use_mouse_accel ) {
 				SetMouseAccel(this, use_mouse_accel);
 			}
--- a/src/video/cybergfx/SDL_cgxaccel.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxaccel.c	Tue Feb 07 06:59:48 2006 +0000
@@ -52,14 +52,14 @@
 	if(surface->hwdata)
 	{
 		if(surface->hwdata->mask)
-			free(surface->hwdata->mask);
+			SDL_free(surface->hwdata->mask);
 
-		if(surface->hwdata->mask=malloc(RASSIZE(surface->w,surface->h)))
+		if(surface->hwdata->mask=SDL_malloc(RASSIZE(surface->w,surface->h)))
 		{
 			Uint32 pitch,ok=0;
 			APTR lock;
 
-			memset(surface->hwdata->mask,255,RASSIZE(surface->w,surface->h));
+			SDL_memset(surface->hwdata->mask,255,RASSIZE(surface->w,surface->h));
 
 			D(bug("Building colorkey mask: color: %ld, size: %ld x %ld, %ld bytes...Bpp:%ld\n",key,surface->w,surface->h,RASSIZE(surface->w,surface->h),surface->format->BytesPerPixel));
 
@@ -155,7 +155,7 @@
 					break;
 					default:
 						D(bug("Pixel mode non supported for color key..."));
-						free(surface->hwdata->mask);
+						SDL_free(surface->hwdata->mask);
 						surface->hwdata->mask=NULL;
 						ok=-1;
 				}
--- a/src/video/cybergfx/SDL_cgximage.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/cybergfx/SDL_cgximage.c	Tue Feb 07 06:59:48 2006 +0000
@@ -57,7 +57,7 @@
 		ULONG pitch;
 
 		if(!screen->hwdata) {
-			if(!(screen->hwdata=malloc(sizeof(struct private_hwdata))))
+			if(!(screen->hwdata=SDL_malloc(sizeof(struct private_hwdata))))
 				return -1;
 
 			D(bug("Creating system accel struct\n"));
@@ -71,7 +71,7 @@
 		if(!(screen->hwdata->lock=LockBitMapTags(screen->hwdata->bmap,
 				LBMI_BASEADDRESS,(ULONG)&screen->pixels,
 				LBMI_BYTESPERROW,(ULONG)&pitch,TAG_DONE))) {
-			free(screen->hwdata);
+			SDL_free(screen->hwdata);
 			screen->hwdata=NULL;
 			return -1;
 		}
@@ -88,7 +88,7 @@
 		return 0;
 	}
 
-	screen->pixels = malloc(screen->h*screen->pitch);
+	screen->pixels = SDL_malloc(screen->h*screen->pitch);
 
 	if ( screen->pixels == NULL ) {
 		SDL_OutOfMemory();
@@ -110,14 +110,14 @@
 void CGX_DestroyImage(_THIS, SDL_Surface *screen)
 {
 	if ( SDL_Ximage ) {
-		free(SDL_Ximage);
+		SDL_free(SDL_Ximage);
 		SDL_Ximage = NULL;
 	}
 	if ( screen ) {
 		screen->pixels = NULL;
 
 		if(screen->hwdata) {
-			free(screen->hwdata);
+			SDL_free(screen->hwdata);
 			screen->hwdata=NULL;
 		}
 	}
@@ -163,7 +163,7 @@
 
 	if(!surface->hwdata)
 	{
-		if(!(surface->hwdata=malloc(sizeof(struct private_hwdata))))
+		if(!(surface->hwdata=SDL_malloc(sizeof(struct private_hwdata))))
 			return -1;
 	}
 
@@ -181,7 +181,7 @@
 	}
 	else
 	{
-		free(surface->hwdata);
+		SDL_free(surface->hwdata);
 		surface->hwdata=NULL;
 	}
 
@@ -194,12 +194,12 @@
 		D(bug("Free hw surface.\n"));
 
 		if(surface->hwdata->mask)
-			free(surface->hwdata->mask);
+			SDL_free(surface->hwdata->mask);
 
 		if(surface->hwdata->bmap&&surface->hwdata->allocated)
 			FreeBitMap(surface->hwdata->bmap);
 
-		free(surface->hwdata);
+		SDL_free(surface->hwdata);
 		surface->hwdata=NULL;
 		surface->pixels=NULL;
 		D(bug("end of free hw surface\n"));
@@ -654,7 +654,7 @@
 
 				for(j=rects[i].h;j;--j)
 				{
-					memcpy(dest,src,srcwidth);
+					SDL_memcpy(dest,src,srcwidth);
 					src+=this->screen->pitch;
 					dest+=destpitch;
 				}
@@ -883,13 +883,13 @@
 
 			if(this->screen->pitch==destpitch)
 			{
-				memcpy(dest,src,this->screen->pitch*this->screen->h);
+				SDL_memcpy(dest,src,this->screen->pitch*this->screen->h);
 			}
 			else
 			{
 				for(j=this->screen->h;j;--j)
 				{
-					memcpy(dest,src,this->screen->pitch);
+					SDL_memcpy(dest,src,this->screen->pitch);
 					src+=this->screen->pitch;
 					dest+=destpitch;
 				}
--- a/src/video/cybergfx/SDL_cgxmodes.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxmodes.c	Tue Feb 07 06:59:48 2006 +0000
@@ -137,12 +137,12 @@
 					{
 						nmodes++;
 
-						SDL_modelist = (SDL_Rect **)realloc(SDL_modelist,(nmodes+1)*sizeof(SDL_Rect *));
+						SDL_modelist = (SDL_Rect **)SDL_realloc(SDL_modelist,(nmodes+1)*sizeof(SDL_Rect *));
 						SDL_modelist[nmodes]=NULL;
 
 						if ( SDL_modelist )
 						{
-							SDL_modelist[nmodes-1] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
+							SDL_modelist[nmodes-1] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
 
 							if ( SDL_modelist[nmodes-1] == NULL )
 								break;
@@ -175,10 +175,10 @@
 	}
 
     if ( SDL_modelist == NULL ) {
-        SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *));
+        SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
         i = 0;
         if ( SDL_modelist ) {
-            SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
+            SDL_modelist[i] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
             if ( SDL_modelist[i] ) {
                 SDL_modelist[i]->x = 0;
                 SDL_modelist[i]->y = 0;
@@ -238,9 +238,9 @@
 
     if ( SDL_modelist ) {
         for ( i=0; SDL_modelist[i]; ++i ) {
-            free(SDL_modelist[i]);
+            SDL_free(SDL_modelist[i]);
         }
-        free(SDL_modelist);
+        SDL_free(SDL_modelist);
         SDL_modelist = NULL;
     }
 }
--- a/src/video/cybergfx/SDL_cgxvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -149,7 +149,7 @@
 			this->hidden->SB[0]=this->hidden->SB[1]=NULL;
 
 			if(SDL_RastPort && SDL_RastPort != &SDL_Display->RastPort)
-				free(SDL_RastPort);
+				SDL_free(SDL_RastPort);
 
 			SDL_RastPort=NULL;
 		}
@@ -181,12 +181,12 @@
 {
 	if ( device ) {
 		if ( device->hidden ) {
-			free(device->hidden);
+			SDL_free(device->hidden);
 		}
 		if ( device->gl_data ) {
-			free(device->gl_data);
+			SDL_free(device->gl_data);
 		}
-		free(device);
+		SDL_free(device);
 	}
 }
 
@@ -195,13 +195,13 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 		device->gl_data = (struct SDL_PrivateGLData *)
-				malloc((sizeof *device->gl_data));
+				SDL_malloc((sizeof *device->gl_data));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ||
 	                         (device->gl_data == NULL) ) {
@@ -210,8 +210,8 @@
 		CGX_DeleteDevice(device);
 		return(0);
 	}
-	memset(device->hidden, 0, sizeof(*device->hidden));
-	memset(device->gl_data, 0, sizeof(*device->gl_data));
+	SDL_memset(device->hidden, 0, sizeof(*device->hidden));
+	SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
 
 	/* Set the driver flags */
 	device->handles_any_size = 1;
@@ -581,7 +581,7 @@
 	}
 
 	/* See if we have been passed a window to use */
-/*	SDL_windowid = getenv("SDL_WINDOWID"); */
+/*	SDL_windowid = SDL_getenv("SDL_WINDOWID"); */
 	SDL_windowid=NULL;
 
 	/* Create the blank cursor */
@@ -649,7 +649,7 @@
 					}
 				}
 			}
-			free(SDL_XPixels);
+			SDL_free(SDL_XPixels);
 			SDL_XPixels = NULL;
 		}
 	}
@@ -664,7 +664,7 @@
 	}
 	if ( flags & SDL_FULLSCREEN ) {
 		flags&=~SDL_RESIZABLE;
-	} else if ( getenv("SDL_VIDEO_CENTERED") ) {
+	} else if ( SDL_getenv("SDL_VIDEO_CENTERED") ) {
 		int display_w, display_h;
 
 		display_w = SDL_Display->Width;
@@ -777,7 +777,7 @@
 	    else
 		ncolors = 1 << screen->format->BitsPerPixel;
 
-	    SDL_XPixels = (Sint32 *)malloc(ncolors * sizeof(Sint32));
+	    SDL_XPixels = (Sint32 *)SDL_malloc(ncolors * sizeof(Sint32));
 
 	    if(SDL_XPixels == NULL) {
 		SDL_OutOfMemory();
@@ -836,7 +836,7 @@
 
 	if(screen->flags & SDL_DOUBLEBUF)
 	{
-		if(SDL_RastPort=malloc(sizeof(struct RastPort)))
+		if(SDL_RastPort=SDL_malloc(sizeof(struct RastPort)))
 		{
 			InitRastPort(SDL_RastPort);
 			SDL_RastPort->BitMap=this->hidden->SB[1]->sb_BitMap;
--- a/src/video/cybergfx/SDL_cgxwm.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxwm.c	Tue Feb 07 06:59:48 2006 +0000
@@ -78,7 +78,7 @@
 	   copy them */
 	if(SDL_Visual == dvis && SDL_XColorMap == SDL_DisplayColormap
 	   && this->screen->format->palette && sicon->format->palette) {
-	    memcpy(sicon->format->palette->colors,
+	    SDL_memcpy(sicon->format->palette->colors,
 		   this->screen->format->palette->colors,
 		   this->screen->format->palette->ncolors * sizeof(SDL_Color));
 	}
@@ -98,21 +98,21 @@
 		XColor wanted;
 
 		palette = sicon->format->palette;
-		color_tried = malloc(palette->ncolors);
+		color_tried = SDL_malloc(palette->ncolors);
 		if ( color_tried == NULL ) {
 			goto done;
 		}
 		if ( SDL_iconcolors != NULL ) {
-			free(SDL_iconcolors);
+			SDL_free(SDL_iconcolors);
 		}
-		SDL_iconcolors = malloc(palette->ncolors
+		SDL_iconcolors = SDL_malloc(palette->ncolors
 					* sizeof(*SDL_iconcolors));
 		if ( SDL_iconcolors == NULL ) {
-			free(color_tried);
+			SDL_free(color_tried);
 			goto done;
 		}
-		memset(color_tried, 0, palette->ncolors);
-		memset(SDL_iconcolors, 0,
+		SDL_memset(color_tried, 0, palette->ncolors);
+		SDL_memset(SDL_iconcolors, 0,
 		       palette->ncolors * sizeof(*SDL_iconcolors));
 
 		p = (Uint8 *)sicon->pixels; 
@@ -132,16 +132,16 @@
 		}
 	}
 	if ( color_tried != NULL ) {
-		free(color_tried);
+		SDL_free(color_tried);
 	}
 
 	/* Translate mask data to LSB order and set the icon mask */
 	i = (sicon->w/8)*sicon->h;
-	LSBmask = (Uint8 *)malloc(i);
+	LSBmask = (Uint8 *)SDL_malloc(i);
 	if ( LSBmask == NULL ) {
 		goto done;
 	}
-	memset(LSBmask, 0, i);
+	SDL_memset(LSBmask, 0, i);
 	while ( --i >= 0 ) {
 		for ( b=0; b<8; ++b )
 			LSBmask[i] |= (((mask[i]>>b)&0x01)<<(7-b));
@@ -163,7 +163,7 @@
 					0, 0, 0, 0, sicon->w, sicon->h);
 	XFreeGC(SDL_Display, GC);
 	XDestroyImage(icon_image);
-	free(LSBmask);
+	SDL_free(LSBmask);
 	sicon->pixels = NULL;
 
 #ifdef USE_ICON_WINDOW
--- a/src/video/cybergfx/SDL_cgxyuv.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxyuv.c	Tue Feb 07 06:59:48 2006 +0000
@@ -89,12 +89,12 @@
 	}
 
 	/* Create the overlay structure */
-	overlay = (SDL_Overlay *)malloc(sizeof *overlay);
+	overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay);
 	if ( overlay == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(overlay, 0, (sizeof *overlay));
+	SDL_memset(overlay, 0, (sizeof *overlay));
 
 	/* Fill in the basic members */
 	overlay->format = format;
@@ -105,7 +105,7 @@
 	overlay->hwfuncs = &x11_yuvfuncs;
 
 	/* Create the pixel data and lookup tables */
-	hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata);
+	hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata);
 	overlay->hwdata = hwdata;
 	if ( hwdata == NULL ) {
 		SDL_OutOfMemory();
@@ -113,7 +113,7 @@
 		return(NULL);
 	}
 	yuvshm = &hwdata->yuvshm;
-	memset(yuvshm, 0, sizeof(*yuvshm));
+	SDL_memset(yuvshm, 0, sizeof(*yuvshm));
 	hwdata->port = xv_port;
 	hwdata->image = XvShmCreateImage(GFX_Display, xv_port, format,
 	                                 0, width, height, yuvshm);
@@ -179,7 +179,7 @@
 		if ( hwdata->image ) {
 			XFree(hwdata->image);
 		}
-		free(hwdata);
+		SDL_free(hwdata);
 	}
 }
 
--- a/src/video/dc/SDL_dcevents.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/dc/SDL_dcevents.c	Tue Feb 07 06:59:48 2006 +0000
@@ -107,7 +107,7 @@
 
 	if (addr!=old_addr) {
 		old_addr = addr;
-		memset(&old_state,0,sizeof(old_state));
+		SDL_memset(&old_state,0,sizeof(old_state));
 	}
 
 	maple_raddr(addr,&port,&unit);
--- a/src/video/dc/SDL_dcvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/dc/SDL_dcvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -76,8 +76,8 @@
 
 static void DC_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *DC_CreateDevice(int devindex)
@@ -85,20 +85,20 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	device->VideoInit = DC_VideoInit;
@@ -386,7 +386,7 @@
 	if (ret) return ret;
 
 	for(i=0;i<sizeof(glfuncs)/sizeof(glfuncs[0]);i++) {
-		if (strcmp(proc,glfuncs[i].name)==0) return glfuncs[i].addr;
+		if (SDL_strcmp(proc,glfuncs[i].name)==0) return glfuncs[i].addr;
 	}
 
 	return NULL;
--- a/src/video/dga/SDL_dgavideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/dga/SDL_dgavideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -78,8 +78,8 @@
 	   and the DGA 2.0+ extension is available, and we can map mem.
 	*/
 	if ( SDL_X11_LoadSymbols() ) {
-		if ( (strncmp(pXDisplayName(display), ":", 1) == 0) ||
-		     (strncmp(pXDisplayName(display), "unix:", 5) == 0) ) {
+		if ( (SDL_strncmp(pXDisplayName(display), ":", 1) == 0) ||
+		     (SDL_strncmp(pXDisplayName(display), "unix:", 5) == 0) ) {
 			dpy = pXOpenDisplay(display);
 			if ( dpy ) {
 				int events, errors, major, minor;
@@ -106,8 +106,8 @@
 static void DGA_DeleteDevice(SDL_VideoDevice *device)
 {
 	if (device != NULL) {
-		free(device->hidden);
-		free(device);
+		SDL_free(device->hidden);
+		SDL_free(device);
 		SDL_X11_UnloadSymbols();
 	}
 }
@@ -118,21 +118,21 @@
 
 	/* Initialize all variables that we clean on shutdown */
 	if (SDL_X11_LoadSymbols()) {
-		device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+		device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 		if ( device ) {
-			memset(device, 0, (sizeof *device));
+			SDL_memset(device, 0, (sizeof *device));
 			device->hidden = (struct SDL_PrivateVideoData *)
-					malloc((sizeof *device->hidden));
+					SDL_malloc((sizeof *device->hidden));
 		}
 		if ( (device == NULL) || (device->hidden == NULL) ) {
 			SDL_OutOfMemory();
 			if ( device ) {
-				free(device);
+				SDL_free(device);
 			}
 			SDL_X11_UnloadSymbols();
 			return(0);
 		}
-		memset(device->hidden, 0, (sizeof *device->hidden));
+		SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 		/* Set the function pointers */
 		device->VideoInit = DGA_VideoInit;
@@ -190,7 +190,7 @@
 	}
 
 	/* Set up the new video mode rectangle */
-	mode = (SDL_Rect *)malloc(sizeof *mode);
+	mode = (SDL_Rect *)SDL_malloc(sizeof *mode);
 	if ( mode == NULL ) {
 		SDL_OutOfMemory();
 		return(-1);
@@ -203,11 +203,11 @@
 	/* Allocate the new list of modes, and fill in the new mode */
 	next_mode = SDL_nummodes[index];
 	SDL_modelist[index] = (SDL_Rect **)
-	       realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
+	       SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
 	if ( SDL_modelist[index] == NULL ) {
 		SDL_OutOfMemory();
 		SDL_nummodes[index] = 0;
-		free(mode);
+		SDL_free(mode);
 		return(-1);
 	}
 	SDL_modelist[index][next_mode] = mode;
@@ -233,7 +233,7 @@
 	proc = fopen("/proc/self/maps", "r");
 	if ( proc ) {
 		while ( fgets(line, sizeof(line)-1, proc) ) {
-			sscanf(line, "%x-%x", &start, &stop);
+			SDL_sscanf(line, "%x-%x", &start, &stop);
 			if ( start == mem ) {
 				size = (Uint32)((stop-start)/1024);
 				break;
@@ -605,7 +605,7 @@
 	surfaces_memleft = size;
 
 	if ( surfaces_memleft > 0 ) {
-		bucket = (vidmem_bucket *)malloc(sizeof(*bucket));
+		bucket = (vidmem_bucket *)SDL_malloc(sizeof(*bucket));
 		if ( bucket == NULL ) {
 			SDL_OutOfMemory();
 			return(-1);
@@ -637,7 +637,7 @@
 	while ( bucket ) {
 		freeable = bucket;
 		bucket = bucket->next;
-		free(freeable);
+		SDL_free(freeable);
 	}
 	surfaces.next = NULL;
 }
@@ -714,7 +714,7 @@
 #ifdef DGA_DEBUG
 	fprintf(stderr, "Adding new free bucket of %d bytes\n", extra);
 #endif
-		newbucket = (vidmem_bucket *)malloc(sizeof(*newbucket));
+		newbucket = (vidmem_bucket *)SDL_malloc(sizeof(*newbucket));
 		if ( newbucket == NULL ) {
 			SDL_OutOfMemory();
 			retval = -1;
@@ -775,7 +775,7 @@
 			if ( bucket->next ) {
 				bucket->next->prev = bucket;
 			}
-			free(freeable);
+			SDL_free(freeable);
 		}
 		if ( bucket->prev && ! bucket->prev->used ) {
 #ifdef DGA_DEBUG
@@ -787,7 +787,7 @@
 			if ( bucket->next ) {
 				bucket->next->prev = bucket->prev;
 			}
-			free(freeable);
+			SDL_free(freeable);
 		}
 	}
 	surface->pixels = NULL;
@@ -1053,9 +1053,9 @@
 		for ( i=0; i<NUM_MODELISTS; ++i ) {
 			if ( SDL_modelist[i] != NULL ) {
 				for ( j=0; SDL_modelist[i][j]; ++j ) {
-					free(SDL_modelist[i][j]);
+					SDL_free(SDL_modelist[i][j]);
 				}
-				free(SDL_modelist[i]);
+				SDL_free(SDL_modelist[i]);
 				SDL_modelist[i] = NULL;
 			}
 		}
--- a/src/video/directfb/SDL_DirectFB_video.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_video.c	Tue Feb 07 06:59:48 2006 +0000
@@ -98,8 +98,8 @@
 
 static void DirectFB_DeleteDevice(SDL_VideoDevice *device)
 {
-  free(device->hidden);
-  free(device);
+  SDL_free(device->hidden);
+  SDL_free(device);
 }
 
 static SDL_VideoDevice *DirectFB_CreateDevice(int devindex)
@@ -107,7 +107,7 @@
   SDL_VideoDevice *device;
 
   /* Initialize all variables that we clean on shutdown */
-  device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+  device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
   if (device)
     {
       memset (device, 0, (sizeof *device));
@@ -467,7 +467,7 @@
   HIDDEN->layer       = layer;
   HIDDEN->eventbuffer = events;
 
-  if (getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL)
+  if (SDL_getenv("SDL_DIRECTFB_MGA_CRTC2") != NULL)
     HIDDEN->enable_mga_crtc2 = 1;
   
   if (HIDDEN->enable_mga_crtc2)
@@ -541,10 +541,10 @@
       HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF );
     
       /* Check if overscan is possibly set */
-      if (getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL)
+      if (SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL)
         {
 	    float overscan = 0;
-	    if (sscanf(getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", &overscan) == 1)
+	    if (SDL_sscanf(SDL_getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", &overscan) == 1)
                if (overscan > 0 && overscan < 2)
 		  HIDDEN->mga_crtc2_stretch_overscan = overscan;
 	}
@@ -714,7 +714,7 @@
 
       HIDDEN->mga_crtc2_stretch = 0;
 
-      if (getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL)
+      if (SDL_getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL)
         {
 	    /* Normally assume a picture aspect ratio of 4:3 */
 	    int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
--- a/src/video/dummy/SDL_nullvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/dummy/SDL_nullvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -73,8 +73,8 @@
 
 static int DUMMY_Available(void)
 {
-	const char *envr = getenv("SDL_VIDEODRIVER");
-	if ((envr) && (strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
+	const char *envr = SDL_getenv("SDL_VIDEODRIVER");
+	if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
 		return(1);
 	}
 
@@ -83,8 +83,8 @@
 
 static void DUMMY_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *DUMMY_CreateDevice(int devindex)
@@ -92,20 +92,20 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	device->VideoInit = DUMMY_VideoInit;
@@ -165,10 +165,10 @@
 				int width, int height, int bpp, Uint32 flags)
 {
 	if ( this->hidden->buffer ) {
-		free( this->hidden->buffer );
+		SDL_free( this->hidden->buffer );
 	}
 
-	this->hidden->buffer = malloc(width * height * (bpp / 8));
+	this->hidden->buffer = SDL_malloc(width * height * (bpp / 8));
 	if ( ! this->hidden->buffer ) {
 		SDL_SetError("Couldn't allocate buffer for requested mode");
 		return(NULL);
@@ -176,11 +176,11 @@
 
 /* 	printf("Setting mode %dx%d\n", width, height); */
 
-	memset(this->hidden->buffer, 0, width * height * (bpp / 8));
+	SDL_memset(this->hidden->buffer, 0, width * height * (bpp / 8));
 
 	/* Allocate the new pixel format for the screen */
 	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
-		free(this->hidden->buffer);
+		SDL_free(this->hidden->buffer);
 		this->hidden->buffer = NULL;
 		SDL_SetError("Couldn't allocate new pixel format for requested mode");
 		return(NULL);
@@ -236,7 +236,7 @@
 {
 	if (this->screen->pixels != NULL)
 	{
-		free(this->screen->pixels);
+		SDL_free(this->screen->pixels);
 		this->screen->pixels = NULL;
 	}
 }
--- a/src/video/epoc/SDL_epocvideo.cpp	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/epoc/SDL_epocvideo.cpp	Tue Feb 07 06:59:48 2006 +0000
@@ -131,8 +131,8 @@
 
 static void EPOC_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *EPOC_CreateDevice(int devindex)
@@ -140,20 +140,20 @@
 	SDL_VideoDevice *device;
 
 	/* Allocate all variables that we free on delete */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	device->VideoInit = EPOC_VideoInit;
@@ -240,7 +240,7 @@
 	/* Initialize all variables that we clean on shutdown */   
 
 	for ( i=0; i<SDL_NUMMODES; ++i ) {
-		Private->SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
+		Private->SDL_modelist[i] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
 		Private->SDL_modelist[i]->x = Private->SDL_modelist[i]->y = 0;
 	}
 	/* Modes sorted largest to smallest !!TODO:sorting order??*/
@@ -357,7 +357,7 @@
     }
 
     if (current && current->pixels) {
-        free(current->pixels);
+        SDL_free(current->pixels);
         current->pixels = NULL;
     }
 	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
@@ -373,8 +373,8 @@
 	current->h = height;
     int numBytesPerPixel = ((bpp-1)>>3) + 1;   
 	current->pitch = numBytesPerPixel * width; // Number of bytes in scanline 
-	current->pixels = malloc(width * height * numBytesPerPixel);
-	memset(current->pixels, 0, width * height * numBytesPerPixel);
+	current->pixels = SDL_malloc(width * height * numBytesPerPixel);
+	SDL_memset(current->pixels, 0, width * height * numBytesPerPixel);
 
 	/* Set the blit function */
 	_this->UpdateRects = EPOC_DirectUpdate;
@@ -622,7 +622,7 @@
 	/* Free video mode lists */
 	for ( i=0; i<SDL_NUMMODES; ++i ) {
 		if ( Private->SDL_modelist[i] != NULL ) {
-			free(Private->SDL_modelist[i]);
+			SDL_free(Private->SDL_modelist[i]);
 			Private->SDL_modelist[i] = NULL;
 		}
 	}
@@ -633,7 +633,7 @@
 	}
 
     if (_this->screen && _this->screen->pixels) {
-        free(_this->screen->pixels);
+        SDL_free(_this->screen->pixels);
         _this->screen->pixels = NULL;
     }
 
--- a/src/video/fbcon/SDL_fbelo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/fbcon/SDL_fbelo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -153,7 +153,7 @@
 
 	while (num_bytes) {
 		if ((*buffer_p == 0) && (buffer[0] != ELO_START_BYTE)) {
-			memcpy(&buffer[0], &buffer[1], num_bytes-1);
+			SDL_memcpy(&buffer[0], &buffer[1], num_bytes-1);
 		}
 		else {
 			if (*buffer_p < ELO_PACKET_SIZE-1) {
@@ -333,19 +333,19 @@
 	struct termios mouse_termios;
 
 	/* try to read the calibration values */
-	buffer = getenv("SDL_ELO_MIN_X");
+	buffer = SDL_getenv("SDL_ELO_MIN_X");
 	if(buffer) {
 		ELO_MIN_X = atoi(buffer);
 	}
-	buffer = getenv("SDL_ELO_MAX_X");
+	buffer = SDL_getenv("SDL_ELO_MAX_X");
 	if(buffer) {
 		ELO_MAX_X = atoi(buffer);
 	}
-	buffer = getenv("SDL_ELO_MIN_Y");
+	buffer = SDL_getenv("SDL_ELO_MIN_Y");
 	if(buffer) {
 		ELO_MIN_Y = atoi(buffer);
 	}
-	buffer = getenv("SDL_ELO_MAX_Y");
+	buffer = SDL_getenv("SDL_ELO_MAX_Y");
 	if(buffer) {
 		ELO_MAX_Y = atoi(buffer);
 	}
@@ -359,7 +359,7 @@
 #endif
 
 	/* set comm params */
-	memset(&mouse_termios, 0, sizeof(mouse_termios));
+	SDL_memset(&mouse_termios, 0, sizeof(mouse_termios));
 	mouse_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
 	mouse_termios.c_cc[VMIN] = 1;
 	result = tcsetattr(fd, TCSANOW, &mouse_termios);
@@ -371,7 +371,7 @@
 		return 0;
 	}
 
-	memset(req, 0, ELO_PACKET_SIZE);
+	SDL_memset(req, 0, ELO_PACKET_SIZE);
 	req[1] = tolower(ELO_PARAMETER);
 	if (!eloSendQuery(req, reply, fd)) {
 #ifdef DEBUG_MOUSE
@@ -379,7 +379,7 @@
 #endif
 	}
 
-	memset(req, 0, ELO_PACKET_SIZE);
+	SDL_memset(req, 0, ELO_PACKET_SIZE);
 	req[1] = tolower(ELO_ID);
 	if (eloSendQuery(req, reply, fd)) {
 #ifdef DEBUG_MOUSE
@@ -393,7 +393,7 @@
 		return 0;
 	}
 
-	memset(req, 0, ELO_PACKET_SIZE);
+	SDL_memset(req, 0, ELO_PACKET_SIZE);
 	req[1] = ELO_MODE;
 	req[3] = ELO_TOUCH_MODE | ELO_STREAM_MODE | ELO_UNTOUCH_MODE;
 	req[4] = ELO_TRACKING_MODE;
@@ -404,7 +404,7 @@
 		return 0;
 	}
 
-	memset(req, 0, ELO_PACKET_SIZE);
+	SDL_memset(req, 0, ELO_PACKET_SIZE);
 	req[1] = ELO_REPORT;
 	req[2] = ELO_UNTOUCH_DELAY;
 	req[3] = ELO_REPORT_DELAY;
--- a/src/video/fbcon/SDL_fbevents.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/fbcon/SDL_fbevents.c	Tue Feb 07 06:59:48 2006 +0000
@@ -81,7 +81,7 @@
 
 	/* Load all the keysym mappings */
 	for ( map=0; map<NUM_VGAKEYMAPS; ++map ) {
-		memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16));
+		SDL_memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16));
 		for ( i=0; i<NR_KEYS; ++i ) {
 			entry.kb_table = map;
 			entry.kb_index = i;
@@ -350,7 +350,7 @@
 			if ( status ) {
 				name[0] = '\0';
 				fscanf(status, "Name: %s", name);
-				if ( strcmp(name, wanted_name) == 0 ) {
+				if ( SDL_strcmp(name, wanted_name) == 0 ) {
 					pid = atoi(entry->d_name);
 				}
 				fclose(status);
@@ -385,10 +385,10 @@
 				len = read(cmdline, args, sizeof(args));
 				arg = args;
 				while ( len > 0 ) {
-					if ( strcmp(arg, "-R") == 0 ) {
+					if ( SDL_strcmp(arg, "-R") == 0 ) {
 						available = 1;
 					}
-					arglen = strlen(arg)+1;
+					arglen = SDL_strlen(arg)+1;
 					len -= arglen;
 					arg += arglen;
 				}
@@ -447,7 +447,7 @@
 
 	imps2 = 0;
 
-	if ( getenv("SDL_MOUSEDEV_IMPS2") ) {
+	if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) {
 		imps2 = 1;
 	}
 	if ( ! imps2 ) {
@@ -499,13 +499,13 @@
 	const char *mousedev;
 	const char *mousedrv;
 
-	mousedrv = getenv("SDL_MOUSEDRV");
-	mousedev = getenv("SDL_MOUSEDEV");
+	mousedrv = SDL_getenv("SDL_MOUSEDRV");
+	mousedev = SDL_getenv("SDL_MOUSEDEV");
 	mouse_fd = -1;
 
 #ifdef HAVE_TSLIB
-	if ((mousedrv != NULL) && (strcmp(mousedrv, "TSLIB") == 0)) {
-		if (mousedev == NULL) mousedev = getenv("TSLIB_TSDEVICE");
+	if ((mousedrv != NULL) && (SDL_strcmp(mousedrv, "TSLIB") == 0)) {
+		if (mousedev == NULL) mousedev = SDL_getenv("TSLIB_TSDEVICE");
 		if (mousedev != NULL) {
 			ts_dev = ts_open(mousedev, 1);
 			if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) {
@@ -524,7 +524,7 @@
 
 	/* ELO TOUCHSCREEN SUPPORT */
 
-	if( (mousedrv != NULL) && (strcmp(mousedrv, "ELO") == 0) ) {
+	if( (mousedrv != NULL) && (SDL_strcmp(mousedrv, "ELO") == 0) ) {
 		mouse_fd = open(mousedev, O_RDWR);
 		if ( mouse_fd >= 0 ) {
 			if(eloInitController(mouse_fd)) {
@@ -839,7 +839,7 @@
 		FB_vgamousecallback(button, relative, dx, dy);
 	}
 	if ( i < nread ) {
-		memcpy(mousebuf, &mousebuf[i], (nread-i));
+		SDL_memcpy(mousebuf, &mousebuf[i], (nread-i));
 		start = (nread-i);
 	} else {
 		start = 0;
@@ -874,9 +874,9 @@
 	wait_idle(this);
 	screen = SDL_VideoSurface;
 	screen_arealen = (screen->h*screen->pitch);
-	screen_contents = (Uint8 *)malloc(screen_arealen);
+	screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
 	if ( screen_contents ) {
-		memcpy(screen_contents, screen->pixels, screen_arealen);
+		SDL_memcpy(screen_contents, screen->pixels, screen_arealen);
 	}
 	FB_SavePaletteTo(this, 256, saved_pal);
 	ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo);
@@ -900,8 +900,8 @@
 	ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
 	FB_RestorePaletteFrom(this, 256, saved_pal);
 	if ( screen_contents ) {
-		memcpy(screen->pixels, screen_contents, screen_arealen);
-		free(screen_contents);
+		SDL_memcpy(screen->pixels, screen_contents, screen_arealen);
+		SDL_free(screen_contents);
 	}
 	SDL_mutexV(hw_lock);
 }
--- a/src/video/fbcon/SDL_fbvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/fbcon/SDL_fbvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -155,7 +155,7 @@
 	int console;
 	const char *SDL_fbdev;
 
-	SDL_fbdev = getenv("SDL_FBDEV");
+	SDL_fbdev = SDL_getenv("SDL_FBDEV");
 	if ( SDL_fbdev == NULL ) {
 		SDL_fbdev = "/dev/fb0";
 	}
@@ -168,8 +168,8 @@
 
 static void FB_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *FB_CreateDevice(int devindex)
@@ -177,20 +177,20 @@
 	SDL_VideoDevice *this;
 
 	/* Initialize all variables that we clean on shutdown */
-	this = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	this = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( this ) {
-		memset(this, 0, (sizeof *this));
+		SDL_memset(this, 0, (sizeof *this));
 		this->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *this->hidden));
+				SDL_malloc((sizeof *this->hidden));
 	}
 	if ( (this == NULL) || (this->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( this ) {
-			free(this);
+			SDL_free(this);
 		}
 		return(0);
 	}
-	memset(this->hidden, 0, (sizeof *this->hidden));
+	SDL_memset(this->hidden, 0, (sizeof *this->hidden));
 	wait_vbl = FB_WaitVBL;
 	wait_idle = FB_WaitIdle;
 	mouse_fd = -1;
@@ -274,17 +274,17 @@
 	do {
 		if (read_fbmodes_line(f, line, sizeof(line))==0)
 			return 0;
-		if (strncmp(line,"geometry",8)==0)
+		if (SDL_strncmp(line,"geometry",8)==0)
 			break;
 	}
 	while(1);
 
-	sscanf(line, "geometry %d %d %d %d %d", &vinfo->xres, &vinfo->yres, 
+	SDL_sscanf(line, "geometry %d %d %d %d %d", &vinfo->xres, &vinfo->yres, 
 			&vinfo->xres_virtual, &vinfo->yres_virtual, &vinfo->bits_per_pixel);
 	if (read_fbmodes_line(f, line, sizeof(line))==0)
 		return 0;
 			
-	sscanf(line, "timings %d %d %d %d %d %d %d", &vinfo->pixclock, 
+	SDL_sscanf(line, "timings %d %d %d %d %d %d %d", &vinfo->pixclock, 
 			&vinfo->left_margin, &vinfo->right_margin, &vinfo->upper_margin, 
 			&vinfo->lower_margin, &vinfo->hsync_len, &vinfo->vsync_len);
 		
@@ -296,38 +296,38 @@
 		if (read_fbmodes_line(f, line, sizeof(line))==0)
 			return 0;
 
-		if (strncmp(line,"hsync",5)==0) {
-			sscanf(line,"hsync %s",option);
-			if (strncmp(option,"high",4)==0)
+		if (SDL_strncmp(line,"hsync",5)==0) {
+			SDL_sscanf(line,"hsync %s",option);
+			if (SDL_strncmp(option,"high",4)==0)
 				vinfo->sync |= FB_SYNC_HOR_HIGH_ACT;
 		}
-		else if (strncmp(line,"vsync",5)==0) {
-			sscanf(line,"vsync %s",option);
-			if (strncmp(option,"high",4)==0)
+		else if (SDL_strncmp(line,"vsync",5)==0) {
+			SDL_sscanf(line,"vsync %s",option);
+			if (SDL_strncmp(option,"high",4)==0)
 				vinfo->sync |= FB_SYNC_VERT_HIGH_ACT;
 		}
-		else if (strncmp(line,"csync",5)==0) {
-			sscanf(line,"csync %s",option);
-			if (strncmp(option,"high",4)==0)
+		else if (SDL_strncmp(line,"csync",5)==0) {
+			SDL_sscanf(line,"csync %s",option);
+			if (SDL_strncmp(option,"high",4)==0)
 				vinfo->sync |= FB_SYNC_COMP_HIGH_ACT;
 		}
-		else if (strncmp(line,"extsync",5)==0) {
-			sscanf(line,"extsync %s",option);
-			if (strncmp(option,"true",4)==0)
+		else if (SDL_strncmp(line,"extsync",5)==0) {
+			SDL_sscanf(line,"extsync %s",option);
+			if (SDL_strncmp(option,"true",4)==0)
 				vinfo->sync |= FB_SYNC_EXT;
 		}
-		else if (strncmp(line,"laced",5)==0) {
-			sscanf(line,"laced %s",option);
-			if (strncmp(option,"true",4)==0)
+		else if (SDL_strncmp(line,"laced",5)==0) {
+			SDL_sscanf(line,"laced %s",option);
+			if (SDL_strncmp(option,"true",4)==0)
 				vinfo->vmode |= FB_VMODE_INTERLACED;
 		}
-		else if (strncmp(line,"double",6)==0) {
-			sscanf(line,"double %s",option);
-			if (strncmp(option,"true",4)==0)
+		else if (SDL_strncmp(line,"double",6)==0) {
+			SDL_sscanf(line,"double %s",option);
+			if (SDL_strncmp(option,"true",4)==0)
 				vinfo->vmode |= FB_VMODE_DOUBLE;
 		}
 	}
-	while(strncmp(line,"endmode",7)!=0);
+	while(SDL_strncmp(line,"endmode",7)!=0);
 
 	return 1;
 }
@@ -393,7 +393,7 @@
 	}
 
 	/* Set up the new video mode rectangle */
-	mode = (SDL_Rect *)malloc(sizeof *mode);
+	mode = (SDL_Rect *)SDL_malloc(sizeof *mode);
 	if ( mode == NULL ) {
 		SDL_OutOfMemory();
 		return(-1);
@@ -409,11 +409,11 @@
 	/* Allocate the new list of modes, and fill in the new mode */
 	next_mode = SDL_nummodes[index];
 	SDL_modelist[index] = (SDL_Rect **)
-	       realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
+	       SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
 	if ( SDL_modelist[index] == NULL ) {
 		SDL_OutOfMemory();
 		SDL_nummodes[index] = 0;
-		free(mode);
+		SDL_free(mode);
 		return(-1);
 	}
 	SDL_modelist[index][next_mode] = mode;
@@ -455,7 +455,7 @@
 	FILE *modesdb;
 
 	/* Initialize the library */
-	SDL_fbdev = getenv("SDL_FBDEV");
+	SDL_fbdev = SDL_getenv("SDL_FBDEV");
 	if ( SDL_fbdev == NULL ) {
 		SDL_fbdev = "/dev/fb0";
 	}
@@ -518,7 +518,7 @@
 
 	/* Check if the user wants to disable hardware acceleration */
 	{ const char *fb_accel;
-		fb_accel = getenv("SDL_FBACCEL");
+		fb_accel = SDL_getenv("SDL_FBACCEL");
 		if ( fb_accel ) {
 			finfo.accel = atoi(fb_accel);
 		}
@@ -589,7 +589,7 @@
 		SDL_nummodes[i] = 0;
 		SDL_modelist[i] = NULL;
 	}
-	if ( getenv("SDL_FB_BROKEN_MODES") != NULL ) {
+	if ( SDL_getenv("SDL_FB_BROKEN_MODES") != NULL ) {
 		FB_AddMode(this, current_index, current_w, current_h, 0);
 	} else if(modesdb) {
 		while ( read_fbmodes_mode(modesdb, &vinfo) ) {
@@ -682,7 +682,7 @@
 	if ( FB_OpenMouse(this) < 0 ) {
 		const char *sdl_nomouse;
 
-		sdl_nomouse = getenv("SDL_NOMOUSE");
+		sdl_nomouse = SDL_getenv("SDL_NOMOUSE");
 		if ( ! sdl_nomouse ) {
 			SDL_SetError("Unable to open mouse");
 			FB_VideoQuit(this);
@@ -867,7 +867,7 @@
 	current->w = vinfo.xres;
 	current->h = vinfo.yres;
 	current->pitch = current->w;
-	current->pixels = malloc(current->h*current->pitch);
+	current->pixels = SDL_malloc(current->h*current->pitch);
 
 	/* Set the update rectangle function */
 	this->UpdateRects = FB_VGA16Update;
@@ -1069,7 +1069,7 @@
 	surfaces_memleft = size;
 
 	if ( surfaces_memleft > 0 ) {
-		bucket = (vidmem_bucket *)malloc(sizeof(*bucket));
+		bucket = (vidmem_bucket *)SDL_malloc(sizeof(*bucket));
 		if ( bucket == NULL ) {
 			SDL_OutOfMemory();
 			return(-1);
@@ -1101,7 +1101,7 @@
 	while ( bucket ) {
 		freeable = bucket;
 		bucket = bucket->next;
-		free(freeable);
+		SDL_free(freeable);
 	}
 	surfaces.next = NULL;
 }
@@ -1152,7 +1152,7 @@
 #ifdef FBCON_DEBUG
 	fprintf(stderr, "Adding new free bucket of %d bytes\n", extra);
 #endif
-		newbucket = (vidmem_bucket *)malloc(sizeof(*newbucket));
+		newbucket = (vidmem_bucket *)SDL_malloc(sizeof(*newbucket));
 		if ( newbucket == NULL ) {
 			SDL_OutOfMemory();
 			return(-1);
@@ -1210,7 +1210,7 @@
 			if ( bucket->next ) {
 				bucket->next->prev = bucket;
 			}
-			free(freeable);
+			SDL_free(freeable);
 		}
 		if ( bucket->prev && ! bucket->prev->used ) {
 #ifdef DGA_DEBUG
@@ -1222,7 +1222,7 @@
 			if ( bucket->next ) {
 				bucket->next->prev = bucket->prev;
 			}
-			free(freeable);
+			SDL_free(freeable);
 		}
 	}
 	surface->pixels = NULL;
@@ -1489,7 +1489,7 @@
 	/* Save hardware palette, if needed */
 	if ( finfo->visual == FB_VISUAL_PSEUDOCOLOR ) {
 		saved_cmaplen = 1<<vinfo->bits_per_pixel;
-		saved_cmap=(__u16 *)malloc(3*saved_cmaplen*sizeof(*saved_cmap));
+		saved_cmap=(__u16 *)SDL_malloc(3*saved_cmaplen*sizeof(*saved_cmap));
 		if ( saved_cmap != NULL ) {
 			FB_SavePaletteTo(this, saved_cmaplen, saved_cmap);
 		}
@@ -1509,7 +1509,7 @@
 
 		/* Save the colormap */
 		saved_cmaplen = 256;
-		saved_cmap=(__u16 *)malloc(3*saved_cmaplen*sizeof(*saved_cmap));
+		saved_cmap=(__u16 *)SDL_malloc(3*saved_cmaplen*sizeof(*saved_cmap));
 		if ( saved_cmap != NULL ) {
 			FB_SavePaletteTo(this, saved_cmaplen, saved_cmap);
 		}
@@ -1529,7 +1529,7 @@
 	/* Restore the original palette */
 	if ( saved_cmap ) {
 		FB_RestorePaletteFrom(this, saved_cmaplen, saved_cmap);
-		free(saved_cmap);
+		SDL_free(saved_cmap);
 		saved_cmap = NULL;
 	}
 }
@@ -1561,9 +1561,9 @@
 		ncolors = this->screen->format->palette->ncolors;
 		cmap.start = 0;
 		cmap.len = ncolors;
-		memset(r, 0, sizeof(r));
-		memset(g, 0, sizeof(g));
-		memset(b, 0, sizeof(b));
+		SDL_memset(r, 0, sizeof(r));
+		SDL_memset(g, 0, sizeof(g));
+		SDL_memset(b, 0, sizeof(b));
 		if ( ioctl(console_fd, FBIOGETCMAP, &cmap) == 0 ) {
 			for ( i=ncolors-1; i>=0; --i ) {
 				colors[i].r = (r[i]>>8);
@@ -1586,12 +1586,12 @@
 	if ( this->screen ) {
 		/* Clear screen and tell SDL not to free the pixels */
 		if ( this->screen->pixels && FB_InGraphicsMode(this) ) {
-#if defined(__powerpc__) || defined(__ia64__)	/* SIGBUS when using memset() ?? */
+#if defined(__powerpc__) || defined(__ia64__)	/* SIGBUS when using SDL_memset() ?? */
 			Uint8 *rowp = (Uint8 *)this->screen->pixels;
 			int left = this->screen->pitch*this->screen->h;
 			while ( left-- ) { *rowp++ = 0; }
 #else
-			memset(this->screen->pixels,0,this->screen->h*this->screen->pitch);
+			SDL_memset(this->screen->pixels,0,this->screen->h*this->screen->pitch);
 #endif
 		}
 		/* This test fails when using the VGA16 shadow memory */
@@ -1611,9 +1611,9 @@
 	for ( i=0; i<NUM_MODELISTS; ++i ) {
 		if ( SDL_modelist[i] != NULL ) {
 			for ( j=0; SDL_modelist[i][j]; ++j ) {
-				free(SDL_modelist[i][j]);
+				SDL_free(SDL_modelist[i][j]);
 			}
-			free(SDL_modelist[i]);
+			SDL_free(SDL_modelist[i]);
 			SDL_modelist[i] = NULL;
 		}
 	}
--- a/src/video/gapi/SDL_gapivideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/gapi/SDL_gapivideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -177,7 +177,7 @@
 	}
 
 	/* Set up the new video mode rectangle */
-	mode = (SDL_Rect *)malloc(sizeof *mode);
+	mode = (SDL_Rect *)SDL_malloc(sizeof *mode);
 	if ( mode == NULL ) {
 		SDL_OutOfMemory();
 		return(-1);
@@ -190,11 +190,11 @@
 	/* Allocate the new list of modes, and fill in the new mode */
 	next_mode = gapi->SDL_nummodes[index];
 	gapi->SDL_modelist[index] = (SDL_Rect **)
-	       realloc(gapi->SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
+	       SDL_realloc(gapi->SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
 	if ( gapi->SDL_modelist[index] == NULL ) {
 		SDL_OutOfMemory();
 		gapi->SDL_nummodes[index] = 0;
-		free(mode);
+		SDL_free(mode);
 		return(-1);
 	}
 	gapi->SDL_modelist[index][next_mode] = mode;
@@ -211,8 +211,8 @@
 		FreeLibrary(g_hGapiLib);
 		g_hGapiLib = 0;
 	}
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *GAPI_CreateDevice(int devindex)
@@ -229,20 +229,20 @@
 	}
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	device->VideoInit = GAPI_VideoInit;
@@ -661,10 +661,10 @@
 	/* Allocate bitmap */
 	if(gapiBuffer) 
 	{
-		free(gapiBuffer);
+		SDL_free(gapiBuffer);
 		gapiBuffer = NULL;
 	}
-	gapiBuffer = malloc(video->h * video->pitch);
+	gapiBuffer = SDL_malloc(video->h * video->pitch);
 	video->pixels = gapiBuffer; 
 
 	if ( ! this->hidden->buffer ) {
@@ -672,7 +672,7 @@
 		return(NULL);
 	}
 
-	memset(gapiBuffer, 255, video->h * video->pitch);
+	SDL_memset(gapiBuffer, 255, video->h * video->pitch);
 	MoveWindow(SDL_Window, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), FALSE);
 	ShowWindow(SDL_Window, SW_SHOW);
 	SetForegroundWindow(SDL_Window);
@@ -738,7 +738,7 @@
 {
 	if( gapi->dstPixelStep == 1) /* optimized blitting on most devices */
 	{
-		memcpy(destPointer, srcPointer, width);
+		SDL_memcpy(destPointer, srcPointer, width);
 		return 1;
 	} else
 	{
@@ -761,7 +761,7 @@
 
 	if( step == 1 ) /* optimized blitting on most devices */
 	{
-		memcpy(destPointer, srcPointer, width * sizeof(PIXEL));
+		SDL_memcpy(destPointer, srcPointer, width * sizeof(PIXEL));
 		return 1;
 	}
 	else
@@ -1062,7 +1062,7 @@
 
 		if (this->screen->pixels != NULL)
 		{
-			free(this->screen->pixels);
+			SDL_free(this->screen->pixels);
 			this->screen->pixels = NULL;
 		}
 		if ( screen_icn ) {
@@ -1089,8 +1089,8 @@
 	for ( i=0; i<NUM_MODELISTS; ++i ) {
 		if ( gapi->SDL_modelist[i] != NULL ) {
 			for ( j=0; gapi->SDL_modelist[i][j]; ++j )
-				free(gapi->SDL_modelist[i][j]);
-			free(gapi->SDL_modelist[i]);
+				SDL_free(gapi->SDL_modelist[i][j]);
+			SDL_free(gapi->SDL_modelist[i]);
 			gapi->SDL_modelist[i] = NULL;
 		}
 	}
--- a/src/video/gem/SDL_gemevents.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/gem/SDL_gemevents.c	Tue Feb 07 06:59:48 2006 +0000
@@ -89,9 +89,9 @@
 {
 	int i;
 
-	memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
-	memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
-	memset(gem_currentascii, 0, sizeof(gem_currentascii));
+	SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
+	SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
+	SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
 
 	/* Initialize keymap */
 	for ( i=0; i<sizeof(keymap); i++ )
@@ -134,7 +134,7 @@
 	int i;
 	SDL_keysym	keysym;
 
-	memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
+	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
 	prevkc = prevks = 0;
 	
 	for (;;)
@@ -215,7 +215,7 @@
 				TranslateKey(i, gem_currentascii[i], &keysym, SDL_FALSE));
 	}
 
-	memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
+	SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
 
 	/* Refresh window name ? */
 	if (GEM_refresh_name) {
--- a/src/video/gem/SDL_gemmouse.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/gem/SDL_gemmouse.c	Tue Feb 07 06:59:48 2006 +0000
@@ -57,9 +57,9 @@
 	graf_mouse(ARROW, NULL);
 
 	if (cursor->mform_p != NULL)
-		free(cursor->mform_p);
+		SDL_free(cursor->mform_p);
 
-	free(cursor);
+	SDL_free(cursor);
 }
 
 WMcursor *GEM_CreateWMCursor(_THIS,
@@ -77,16 +77,16 @@
 	}
 
 	/* Allocate the cursor memory */
-	cursor = (WMcursor *)malloc(sizeof(WMcursor));
+	cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
 	if ( cursor == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
 
 	/* Allocate mform */
-	new_mform = (MFORM *)malloc(sizeof(MFORM));		
+	new_mform = (MFORM *)SDL_malloc(sizeof(MFORM));		
 	if (new_mform == NULL) {
-		free(cursor);
+		SDL_free(cursor);
 		SDL_OutOfMemory();
 		return(NULL);
 	}
--- a/src/video/gem/SDL_gemvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/gem/SDL_gemvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -125,8 +125,8 @@
 
 static void GEM_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *GEM_CreateDevice(int devindex)
@@ -136,23 +136,23 @@
 	unsigned long dummy;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 		device->gl_data = (struct SDL_PrivateGLData *)
-				malloc((sizeof *device->gl_data));
+				SDL_malloc((sizeof *device->gl_data));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
-	memset(device->gl_data, 0, sizeof(*device->gl_data));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
 
 	/* Set the function pointers */
 	device->VideoInit = GEM_VideoInit;
@@ -400,7 +400,7 @@
 		VDI_oldpalette[i][2] = rgb[2];
 	}
 	VDI_setpalette = GEM_SetNewPalette;
-	memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette));
+	SDL_memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette));
 
 	/* Setup screen info */
 	GEM_title_name = empty_name;
@@ -453,7 +453,7 @@
 	GEM_menubar=Atari_SysMalloc(menubar_size,MX_PREFTTRAM);
 
 	/* Fill video modes list */
-	SDL_modelist[0] = malloc(sizeof(SDL_Rect));
+	SDL_modelist[0] = SDL_malloc(sizeof(SDL_Rect));
 	SDL_modelist[0]->x = 0;
 	SDL_modelist[0]->y = 0;
 	SDL_modelist[0]->w = VDI_w;
@@ -679,7 +679,7 @@
 			SDL_SetError("Can not allocate %d KB for frame buffer", screensize>>10);
 			return NULL;
 		}
-		memset(GEM_buffer1, 0, screensize);
+		SDL_memset(GEM_buffer1, 0, screensize);
 #ifdef DEBUG_VIDEO_GEM
 		printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
 #endif
@@ -691,7 +691,7 @@
 			SDL_SetError("Can not allocate %d KB for shadow buffer", screensize>>10);
 			return NULL;
 		}
-		memset(GEM_buffer2, 0, screensize);
+		SDL_memset(GEM_buffer2, 0, screensize);
 #ifdef DEBUG_VIDEO_GEM
 		printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
 #endif
@@ -1132,7 +1132,7 @@
 
 	/* Free mode list */
 	if (SDL_modelist[0]) {
-		free(SDL_modelist[0]);
+		SDL_free(SDL_modelist[0]);
 		SDL_modelist[0]=NULL;
 	}
 
--- a/src/video/ggi/SDL_ggivideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/ggi/SDL_ggivideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -83,8 +83,8 @@
 
 static void GGI_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *GGI_CreateDevice(int devindex)
@@ -92,20 +92,20 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	device->VideoInit = GGI_VideoInit;
@@ -162,7 +162,7 @@
 	int err, num_bufs;
 	ggi_pixel white, black;
 	
-	priv = malloc(sizeof(struct private_hwdata));
+	priv = SDL_malloc(sizeof(struct private_hwdata));
 	if (priv == NULL)
 	{
 		SDL_SetError("Unhandled GGI mode type!\n");
--- a/src/video/ipod/SDL_ipodvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/ipod/SDL_ipodvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -65,7 +65,7 @@
     
     if ((file = fopen("/proc/cpuinfo", "r")) != NULL) {
 	while (fgets(cpuinfo, sizeof(cpuinfo), file) != NULL)
-	    if (strncmp(cpuinfo, "Revision", 8) == 0)
+	    if (SDL_strncmp(cpuinfo, "Revision", 8) == 0)
 		break;
 	fclose(file);
     }
@@ -73,7 +73,7 @@
     for (; isspace(cpuinfo[i]); i++);
     ptr = cpuinfo + i + 2;
     
-    return strtol(ptr, NULL, 10);
+    return SDL_strtol(ptr, NULL, 10);
 }
 
 static int iPod_Available() 
--- a/src/video/maccommon/SDL_macmouse.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/maccommon/SDL_macmouse.c	Tue Feb 07 06:59:48 2006 +0000
@@ -48,7 +48,7 @@
 
 void Mac_FreeWMCursor(_THIS, WMcursor *cursor)
 {
-	free(cursor);
+	SDL_free(cursor);
 }
 
 WMcursor *Mac_CreateWMCursor(_THIS,
@@ -58,12 +58,12 @@
 	int row, bytes;
 		
 	/* Allocate the cursor memory */
-	cursor = (WMcursor *)malloc(sizeof(WMcursor));
+	cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
 	if ( cursor == NULL ) {
 		SDL_OutOfMemory();
 		return(NULL);
 	}
-	memset(cursor, 0, sizeof(*cursor));
+	SDL_memset(cursor, 0, sizeof(*cursor));
     
     if (w > 16)
         w = 16;
@@ -74,11 +74,11 @@
 	bytes = (w+7)/8;
 
 	for ( row=0; row<h; ++row ) {
-		memcpy(&cursor->curs.data[row], data, bytes);
+		SDL_memcpy(&cursor->curs.data[row], data, bytes);
 		data += bytes;
 	}
 	for ( row=0; row<h; ++row ) {
-		memcpy(&cursor->curs.mask[row], mask, bytes);
+		SDL_memcpy(&cursor->curs.mask[row], mask, bytes);
 		mask += bytes;
 	}
 	cursor->curs.hotSpot.h = hot_x;
--- a/src/video/maccommon/SDL_macwm.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/maccommon/SDL_macwm.c	Tue Feb 07 06:59:48 2006 +0000
@@ -39,7 +39,7 @@
 	/* Don't convert C to P string in place, because it may be read-only */
 	Str255		ptitle; /* MJS */
 	ptitle[0] = strlen (title);
-	memcpy(ptitle+1, title, ptitle[0]); /* MJS */
+	SDL_memcpy(ptitle+1, title, ptitle[0]); /* MJS */
 	if (SDL_Window)
 		SetWTitle(SDL_Window, ptitle); /* MJS */
 }
--- a/src/video/macdsp/SDL_dspvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/macdsp/SDL_dspvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -238,11 +238,11 @@
    	if (device->hidden) {
    	   
    	   if (device->hidden->dspinfo)
-	         free(device->hidden->dspinfo);
+	         SDL_free(device->hidden->dspinfo);
    	   
-   	   free(device->hidden);
+   	   SDL_free(device->hidden);
    	}
-	   free(device);	
+	   SDL_free(device);	
 	}
 }
 
@@ -251,13 +251,13 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, sizeof (*device));
+		SDL_memset(device, 0, sizeof (*device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	    if (device->hidden)
-	        memset(device->hidden, 0, sizeof ( *(device->hidden) ) );
+	        SDL_memset(device->hidden, 0, sizeof ( *(device->hidden) ) );
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
@@ -267,22 +267,22 @@
 			if (device->hidden)
 		        free (device->hidden);			
 			
-			free(device);
+			SDL_free(device);
 		}
 		
 		return(NULL);
 	}
 	
 	/* Allocate DrawSprocket information */
-	device->hidden->dspinfo = (struct DSpInfo *)malloc(
+	device->hidden->dspinfo = (struct DSpInfo *)SDL_malloc(
 					(sizeof *device->hidden->dspinfo));
 	if ( device->hidden->dspinfo == NULL ) {
 		SDL_OutOfMemory();
-		free(device->hidden);
-		free(device);
+		SDL_free(device->hidden);
+		SDL_free(device);
 		return(0);
 	}
-	memset(device->hidden->dspinfo, 0, (sizeof *device->hidden->dspinfo));
+	SDL_memset(device->hidden->dspinfo, 0, (sizeof *device->hidden->dspinfo));
 
 	/* Set the function pointers */
 	device->VideoInit       = DSp_VideoInit;
@@ -1384,9 +1384,9 @@
 	/* Free list of video modes */
 	if ( SDL_modelist != NULL ) {
 		for ( i=0; SDL_modelist[i]; i++ ) {
-			free(SDL_modelist[i]);
+			SDL_free(SDL_modelist[i]);
 		}
-		free(SDL_modelist);
+		SDL_free(SDL_modelist);
 		SDL_modelist = NULL;
 	}
 	
--- a/src/video/macrom/SDL_romvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/macrom/SDL_romvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -120,8 +120,8 @@
 
 static void ROM_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *ROM_CreateDevice(int devindex)
@@ -129,20 +129,20 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);
 		}
 		return(0);
 	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
 	/* Set the function pointers */
 	device->VideoInit = ROM_VideoInit;
@@ -231,9 +231,9 @@
 	SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit+pmTolerant, 0);
 
 	/* Get a list of available fullscreen modes */
-	SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *));
+	SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
 	if ( SDL_modelist ) {
-		SDL_modelist[0] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
+		SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
 		if ( SDL_modelist[0] ) {
 			SDL_modelist[0]->x = 0;
 			SDL_modelist[0]->y = 0;
@@ -723,9 +723,9 @@
 	/* Free list of video modes */
 	if ( SDL_modelist != NULL ) {
 		for ( i=0; SDL_modelist[i]; ++i ) {
-			free(SDL_modelist[i]);
+			SDL_free(SDL_modelist[i]);
 		}
-		free(SDL_modelist);
+		SDL_free(SDL_modelist);
 		SDL_modelist = NULL;
 	}
 }
--- a/src/video/os2fslib/SDL_os2fslib.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/os2fslib/SDL_os2fslib.c	Tue Feb 07 06:59:48 2006 +0000
@@ -1169,8 +1169,8 @@
   {
     GpiDeleteBitmap(cursor->hbm);
     WinDestroyPointer(cursor->hptr);
-    free(cursor->pchData);
-    free(cursor);
+    SDL_free(cursor->pchData);
+    SDL_free(cursor);
   }
 }
 
@@ -1208,17 +1208,17 @@
   if ((w>maxx) || (h>maxy))
     return (WMcursor *) NULL;
 
-  pResult = (WMcursor *) malloc(sizeof(WMcursor));
+  pResult = (WMcursor *) SDL_malloc(sizeof(WMcursor));
   if (!pResult) return (WMcursor *) NULL;
 
-  pchTemp = (char *) malloc((maxx + 7)/8 * maxy*2);
+  pchTemp = (char *) SDL_malloc((maxx + 7)/8 * maxy*2);
   if (!pchTemp)
   {
-    free(pResult);
+    SDL_free(pResult);
     return (WMcursor *) NULL;
   }
 
-  memset(pchTemp, 0, (maxx + 7)/8 * maxy*2);
+  SDL_memset(pchTemp, 0, (maxx + 7)/8 * maxy*2);
 
   hps = WinGetPS(_this->hidden->hwndClient);
 
@@ -1234,7 +1234,7 @@
   bmi.argbColor[1].bGreen = 0x00;
   bmi.argbColor[1].bRed = 0xff;
 
-  memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
+  SDL_memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
   bmih.cbFix = sizeof(BITMAPINFOHEADER);
   bmih.cx = maxx;
   bmih.cy = 2*maxy;
@@ -1254,9 +1254,9 @@
     memnot(aptr, mask, run);
     mask += run;
     aptr += run;
-    memset(xptr,  0, pad);
+    SDL_memset(xptr,  0, pad);
     xptr += pad;
-    memset(aptr, ~0, pad);
+    SDL_memset(aptr, ~0, pad);
     aptr += pad;
   }
   pad += run;
@@ -1265,9 +1265,9 @@
     xptr = pchTemp + (maxx+7)/8 * (maxy-1-i);
     aptr = pchTemp + (maxx+7)/8 * (maxy+maxy-1-i);
 
-    memset(xptr,  0, (maxx+7)/8);
+    SDL_memset(xptr,  0, (maxx+7)/8);
     xptr += (maxx+7)/8;
-    memset(aptr, ~0, (maxx+7)/8);
+    SDL_memset(aptr, ~0, (maxx+7)/8);
     aptr += (maxx+7)/8;
   }
 
@@ -1507,18 +1507,18 @@
   if ((w>maxx) || (h>maxy))
     return;
 
-  pchTemp = (char *) malloc(w * h*2 * 4);
+  pchTemp = (char *) SDL_malloc(w * h*2 * 4);
   if (!pchTemp)
     return;
 
-  memset(pchTemp, 0, w * h*2 * 4);
+  SDL_memset(pchTemp, 0, w * h*2 * 4);
 
   // Convert surface to RGB, if it's not RGB yet!
   icon_rgb = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
                                   32, 0, 0, 0, 0);
   if ( icon_rgb == NULL )
   {
-    free(pchTemp);
+    SDL_free(pchTemp);
     return;
   }
   bounds.x = 0;
@@ -1528,7 +1528,7 @@
   if ( SDL_LowerBlit(icon, &bounds, icon_rgb, &bounds) < 0 )
   {
     SDL_FreeSurface(icon_rgb);
-    free(pchTemp);
+    SDL_free(pchTemp);
     return;
   }
 
@@ -1596,7 +1596,7 @@
   bmi.cPlanes = 1;
   bmi.cBitCount = 32;
 
-  memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
+  SDL_memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
   bmih.cbFix = sizeof(BITMAPINFOHEADER);
   bmih.cx = w;
   bmih.cy = 2*h;
@@ -1609,7 +1609,7 @@
   WinReleasePS(hps);
 
   // Free pixel array
-  free(pchTemp);
+  SDL_free(pchTemp);
 
   // Change icon in frame window
   WinSendMsg(hwndFrame,
@@ -2116,7 +2116,7 @@
   // no FreeListModes() call in SDL!
   if (_this->hidden->pListModesResult)
   {
-    free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL;
+    SDL_free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL;
   }
 
   // Free list of available fullscreen modes
@@ -2254,7 +2254,7 @@
 
   // We'll possibly adjust the structure, so copy out the values
   // into TempModeInfo!
-  memcpy(&TempModeInfo, pModeInfoFound, sizeof(TempModeInfo));
+  SDL_memcpy(&TempModeInfo, pModeInfoFound, sizeof(TempModeInfo));
   pModeInfoFound = &TempModeInfo;
 
   if (flags & SDL_RESIZABLE)
@@ -2335,7 +2335,7 @@
     pModeInfoFound->uiScanLineSize = pResult->pitch;
 
     // Store new source buffer parameters!
-    memcpy(&(_this->hidden->SrcBufferDesc), pModeInfoFound, sizeof(*pModeInfoFound));
+    SDL_memcpy(&(_this->hidden->SrcBufferDesc), pModeInfoFound, sizeof(*pModeInfoFound));
     _this->hidden->pchSrcBuffer = pResult->pixels;
 
 #ifdef DEBUG_BUILD
@@ -2446,7 +2446,7 @@
   // Destroy result of previous call, if there is any
   if (_this->hidden->pListModesResult)
   {
-    free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL;
+    SDL_free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL;
   }
 
   // For resizable and windowed mode we support every resolution!
@@ -2469,7 +2469,7 @@
     {
       if (pFSMode->uiBPP == format->BitsPerPixel)
       {
-        SDL_Rect *pRect = (SDL_Rect *) malloc(sizeof(SDL_Rect));
+        SDL_Rect *pRect = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
         if (pRect)
         {
           // Fill description
@@ -2489,14 +2489,14 @@
 #endif
 
             // We're the first one to be inserted!
-            _this->hidden->pListModesResult = (SDL_Rect**) malloc(2*sizeof(SDL_Rect*));
+            _this->hidden->pListModesResult = (SDL_Rect**) SDL_malloc(2*sizeof(SDL_Rect*));
             if (_this->hidden->pListModesResult)
             {
               _this->hidden->pListModesResult[0] = pRect;
 	      _this->hidden->pListModesResult[1] = NULL;
             } else
             {
-              free(pRect);
+              SDL_free(pRect);
             }
           } else
           {
@@ -2528,7 +2528,7 @@
 //            printf("!!! From %d slots, it will be at %d\n", iNumOfSlots, iPlace);
 #endif
 
-            pNewList = (SDL_Rect**) realloc(_this->hidden->pListModesResult, (iNumOfSlots+1)*sizeof(SDL_Rect*));
+            pNewList = (SDL_Rect**) SDL_realloc(_this->hidden->pListModesResult, (iNumOfSlots+1)*sizeof(SDL_Rect*));
             if (pNewList)
             {
               for (i=iNumOfSlots;i>iPlace;i--)
@@ -2537,7 +2537,7 @@
               _this->hidden->pListModesResult = pNewList;
             } else
             {
-              free(pRect);
+              SDL_free(pRect);
             }
           }
         }
@@ -2611,9 +2611,9 @@
 
   // For this, we select the first available fullscreen mode as
   // current window size!
-  memcpy(&(_this->hidden->SrcBufferDesc), _this->hidden->pAvailableFSLibVideoModes, sizeof(_this->hidden->SrcBufferDesc));
+  SDL_memcpy(&(_this->hidden->SrcBufferDesc), _this->hidden->pAvailableFSLibVideoModes, sizeof(_this->hidden->SrcBufferDesc));
   // Allocate new video buffer!
-  _this->hidden->pchSrcBuffer = (char *) malloc(_this->hidden->pAvailableFSLibVideoModes->uiScanLineSize * _this->hidden->pAvailableFSLibVideoModes->uiYResolution);
+  _this->hidden->pchSrcBuffer = (char *) SDL_malloc(_this->hidden->pAvailableFSLibVideoModes->uiScanLineSize * _this->hidden->pAvailableFSLibVideoModes->uiYResolution);
   if (!_this->hidden->pchSrcBuffer)
   {
 #ifdef DEBUG_BUILD
@@ -2666,12 +2666,12 @@
   // Free used memory
   FSLib_FreeVideoModeList(_this->hidden->pAvailableFSLibVideoModes);
   if (_this->hidden->pListModesResult)
-    free(_this->hidden->pListModesResult);
+    SDL_free(_this->hidden->pListModesResult);
   if (_this->hidden->pchSrcBuffer)
-    free(_this->hidden->pchSrcBuffer);
+    SDL_free(_this->hidden->pchSrcBuffer);
   DosCloseMutexSem(_this->hidden->hmtxUseSrcBuffer);
-  free(_this->hidden);
-  free(_this);
+  SDL_free(_this->hidden);
+  SDL_free(_this);
   FSLib_Uninitialize();
 }
 
@@ -2703,21 +2703,21 @@
 #endif
 
   /* Initialize all variables that we clean on shutdown */
-  device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+  device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
   if ( device )
   {
-    memset(device, 0, (sizeof *device));
+    SDL_memset(device, 0, (sizeof *device));
     // Also allocate memory for private data
-    device->hidden = (struct SDL_PrivateVideoData *) malloc((sizeof(struct SDL_PrivateVideoData)));
+    device->hidden = (struct SDL_PrivateVideoData *) SDL_malloc((sizeof(struct SDL_PrivateVideoData)));
   }
   if ( (device == NULL) || (device->hidden == NULL) )
   {
     SDL_OutOfMemory();
     if ( device )
-      free(device);
+      SDL_free(device);
     return NULL;
   }
-  memset(device->hidden, 0, (sizeof *device->hidden));
+  SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
   /* Set the function pointers */
 #ifdef DEBUG_BUILD
@@ -2770,8 +2770,8 @@
     printf("[os2fslib_CreateDevice] : Could not initialize FSLib!\n");
 #endif
     SDL_SetError("Could not initialize FSLib!");
-    free(device->hidden);
-    free(device);
+    SDL_free(device->hidden);
+    SDL_free(device);
     return NULL;
   }
   device->hidden->pAvailableFSLibVideoModes =
--- a/src/video/photon/SDL_ph_gl.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/photon/SDL_ph_gl.c	Tue Feb 07 06:59:48 2006 +0000
@@ -123,7 +123,7 @@
     this->gl_config.dll_handle = handle;
     this->gl_config.driver_loaded = 1;
 
-    strncpy(this->gl_config.driver_path, path, sizeof(this->gl_config.driver_path)-1);
+    SDL_strncpy(this->gl_config.driver_path, path, sizeof(this->gl_config.driver_path)-1);
 
     return 0;
 }
--- a/src/video/photon/SDL_ph_image.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/photon/SDL_ph_image.c	Tue Feb 07 06:59:48 2006 +0000
@@ -77,7 +77,7 @@
     if ((bpp==8) && (desktoppal==SDLPH_PAL_EMULATE))
     {
         /* creating image palette */
-        palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
+        palette=SDL_malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
         if (palette==NULL)
         {
             SDL_SetError("ph_SetupImage(): can't allocate memory for palette !\n");
@@ -89,7 +89,7 @@
         if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
         {
             SDL_SetError("ph_SetupImage(): PhCreateImage() failed for bpp=8 !\n");
-            free(palette);
+            SDL_free(palette);
             return -1;
         }
     }
@@ -254,11 +254,11 @@
            
            for (i=0; i<40; i++)
            {
-              memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
+              SDL_memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
            }
            for (i=440; i<480; i++)
            {
-              memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
+              SDL_memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
            }
            screen->pixels+=screen->pitch*40;
         }
@@ -278,11 +278,11 @@
            
            for (i=0; i<40; i++)
            {
-              memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
+              SDL_memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
            }
            for (i=440; i<480; i++)
            {
-              memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
+              SDL_memset(screen->pixels+screen->pitch*i, 0x00, screen->pitch);
            }
            screen->pixels+=screen->pitch*40;
         }
@@ -391,10 +391,10 @@
         /* if palette allocated, free it */
         if (SDL_Image->palette)
         {
-            free(SDL_Image->palette);
+            SDL_free(SDL_Image->palette);
         }
         PgShmemDestroy(SDL_Image->image);
-        free(SDL_Image);
+        SDL_free(SDL_Image);
     }
 
     /* Must be zeroed everytime */
@@ -531,8 +531,8 @@
        SDL_SetError("ph_AllocHWSurface(): hwdata already exists!\n");
        return -1;
     }
-    surface->hwdata=malloc(sizeof(struct private_hwdata));
-    memset(surface->hwdata, 0x00, sizeof(struct private_hwdata));
+    surface->hwdata=SDL_malloc(sizeof(struct private_hwdata));
+    SDL_memset(surface->hwdata, 0x00, sizeof(struct private_hwdata));
     surface->hwdata->offscreenctx=PdCreateOffscreenContext(0, surface->w, surface->h, Pg_OSC_MEM_PAGE_ALIGN);
     if (surface->hwdata->offscreenctx == NULL)
     {
@@ -601,7 +601,7 @@
 
     PhDCRelease(surface->hwdata->offscreenctx);
     
-    free(surface->hwdata);
+    SDL_free(surface->hwdata);
     surface->hwdata=NULL;
 
     /* Update video ram amount */
--- a/src/video/photon/SDL_ph_modes.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/photon/SDL_ph_modes.c	Tue Feb 07 06:59:48 2006 +0000
@@ -292,10 +292,10 @@
         settings.refresh = 0;
         settings.flags = 0;
 
-        refreshrate=getenv("SDL_PHOTON_FULLSCREEN_REFRESH");
+        refreshrate=SDL_getenv("SDL_PHOTON_FULLSCREEN_REFRESH");
         if (refreshrate!=NULL)
         {
-           if (sscanf(refreshrate, "%d", &refreshratenum)==1)
+           if (SDL_sscanf(refreshrate, "%d", &refreshratenum)==1)
            {
                settings.refresh = refreshratenum;
            }
--- a/src/video/photon/SDL_ph_mouse.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/photon/SDL_ph_mouse.c	Tue Feb 07 06:59:48 2006 +0000
@@ -49,7 +49,7 @@
         SDL_Unlock_EventThread();
     }	
 
-    free(cursor);
+    SDL_free(cursor);
 }
 
 WMcursor *ph_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
@@ -59,14 +59,14 @@
     unsigned char bit, databit, maskbit;
 
     /* Allocate and initialize the cursor memory */
-    if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL)
+    if ((cursor = (WMcursor*)SDL_malloc(sizeof(WMcursor))) == NULL)
     {
         SDL_OutOfMemory();
         return(NULL);
     }
-    memset(cursor,0,sizeof(WMcursor));
+    SDL_memset(cursor,0,sizeof(WMcursor));
 
-    cursor->ph_cursor = (PhCursorDef_t *) malloc(sizeof(PhCursorDef_t) + 32*4*2);
+    cursor->ph_cursor = (PhCursorDef_t *) SDL_malloc(sizeof(PhCursorDef_t) + 32*4*2);
 
     if (cursor->ph_cursor == NULL)
     {
@@ -74,7 +74,7 @@
         return NULL;
     }
 
-    memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
+    SDL_memset(cursor->ph_cursor,0,(sizeof(PhCursorDef_t) + 32*4*2));
 
     cursor->ph_cursor->hdr.type =Ph_RDATA_CURSOR;   
     cursor->ph_cursor->size1.x = (short)w;
--- a/src/video/photon/SDL_ph_video.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/photon/SDL_ph_video.c	Tue Feb 07 06:59:48 2006 +0000
@@ -76,11 +76,11 @@
     SDL_VideoDevice* device;
 
     /* Initialize all variables that we clean on shutdown */
-    device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+    device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
     if (device)
     {
-        memset(device, 0, (sizeof *device));
-        device->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *device->hidden));
+        SDL_memset(device, 0, (sizeof *device));
+        device->hidden = (struct SDL_PrivateVideoData*)SDL_malloc((sizeof *device->hidden));
         device->gl_data = NULL;
     }
     if ((device == NULL) || (device->hidden == NULL))
@@ -89,7 +89,7 @@
         ph_DeleteDevice(device);
         return NULL;
     }
-    memset(device->hidden, 0, (sizeof *device->hidden));
+    SDL_memset(device->hidden, 0, (sizeof *device->hidden));
 
     /* Set the driver flags */
     device->handles_any_size = 1;
@@ -158,15 +158,15 @@
     {
         if (device->hidden)
         {
-            free(device->hidden);
+            SDL_free(device->hidden);
             device->hidden = NULL;
         }
         if (device->gl_data)
         {
-            free(device->gl_data);
+            SDL_free(device->gl_data);
             device->gl_data = NULL;
         }
-        free(device);
+        SDL_free(device);
         device = NULL;
     }
 }
@@ -257,10 +257,10 @@
         }
         if (!currently_maximized)
         {
-            windowpos = getenv("SDL_VIDEO_WINDOW_POS");
-            iscentered = getenv("SDL_VIDEO_CENTERED");
+            windowpos = SDL_getenv("SDL_VIDEO_WINDOW_POS");
+            iscentered = SDL_getenv("SDL_VIDEO_CENTERED");
 
-            if ((iscentered) || ((windowpos) && (strcmp(windowpos, "center")==0)))
+            if ((iscentered) || ((windowpos) && (SDL_strcmp(windowpos, "center")==0)))
             {
                 PhWindowQueryVisible(Ph_QUERY_CONSOLE, 0, 0, &desktopextent);
                 if (desktop_mode.width>w)
@@ -280,7 +280,7 @@
             {
                 if (windowpos)
                 {
-                    if (sscanf(windowpos, "%d,%d", &x, &y) == 2)
+                    if (SDL_sscanf(windowpos, "%d,%d", &x, &y) == 2)
                     {
                         if ((x<desktop_mode.width) && (y<desktop_mode.height))
                         {
@@ -372,12 +372,12 @@
     old_video_mode=-1;
     old_refresh_rate=-1;
 	
-    if (NULL == (event = malloc(EVENT_SIZE)))
+    if (NULL == (event = SDL_malloc(EVENT_SIZE)))
     {
         SDL_OutOfMemory();
         return -1;
     }
-    memset(event, 0x00, EVENT_SIZE);
+    SDL_memset(event, 0x00, EVENT_SIZE);
 
     window = ph_CreateWindow(this);
     if (window == NULL)
@@ -592,7 +592,7 @@
 
     if (event!=NULL)
     {
-        free(event);
+        SDL_free(event);
         event=NULL;
     }
 }
--- a/src/video/photon/SDL_ph_wm.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/photon/SDL_ph_wm.c	Tue Feb 07 06:59:48 2006 +0000
@@ -64,7 +64,7 @@
 
     SDL_Lock_EventThread();
 
-    memset( &windowevent, 0, sizeof (event) );
+    SDL_memset( &windowevent, 0, sizeof (event) );
     windowevent.event_f = Ph_WM_HIDE;
     windowevent.event_state = Ph_WM_EVSTATE_HIDE;
     windowevent.rid = PtWidgetRid(window);
--- a/src/video/photon/SDL_phyuv.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/photon/SDL_phyuv.c	Tue Feb 07 06:59:48 2006 +0000
@@ -141,7 +141,7 @@
     overlay->hwdata->ischromakey=0;
 
     do {
-        memset(&overlay->hwdata->caps, 0x00, sizeof(PgScalerCaps_t));
+        SDL_memset(&overlay->hwdata->caps, 0x00, sizeof(PgScalerCaps_t));
         overlay->hwdata->caps.size = sizeof(PgScalerCaps_t);
         rtncode = PgGetScalerCapabilities(overlay->hwdata->channel, i, &overlay->hwdata->caps);
         if (rtncode==0)
@@ -498,9 +498,9 @@
 
     overlay->hwdata->CurrentFrameData = NULL;  
 	
-    free(overlay->hwdata->FrameData0);
-    free(overlay->hwdata->FrameData1);
+    SDL_free(overlay->hwdata->FrameData0);
+    SDL_free(overlay->hwdata->FrameData1);
     overlay->hwdata->FrameData0 = NULL;
     overlay->hwdata->FrameData1 = NULL;
-    free(overlay->hwdata);
+    SDL_free(overlay->hwdata);
 }
--- a/src/video/picogui/SDL_pgevents.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/picogui/SDL_pgevents.c	Tue Feb 07 06:59:48 2006 +0000
@@ -44,7 +44,7 @@
 int PG_HandleKey(struct pgEvent *evt)
 {
         SDL_keysym sym;
-	memset(&sym,0,sizeof(sym));
+	SDL_memset(&sym,0,sizeof(sym));
 	sym.sym = evt->e.kbd.key;
 	sym.mod = evt->e.kbd.mods;
         SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
@@ -54,7 +54,7 @@
 int PG_HandleChar(struct pgEvent *evt)
 {
         SDL_keysym sym;
-	memset(&sym,0,sizeof(sym));
+	SDL_memset(&sym,0,sizeof(sym));
 	sym.unicode = evt->e.kbd.key;
 	sym.mod = evt->e.kbd.mods;
         SDL_PrivateKeyboard(evt->type == PG_WE_KBD_KEYDOWN, &sym);
--- a/src/video/picogui/SDL_pgvideo.c	Mon Feb 06 17:28:04 2006 +0000
+++ b/src/video/picogui/SDL_pgvideo.c	Tue Feb 07 06:59:48 2006 +0000
@@ -85,8 +85,8 @@
 
 static void PG_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	SDL_free(device->hidden);
+	SDL_free(device);
 }
 
 static SDL_VideoDevice *PG_CreateDevice(int devindex)
@@ -94,20 +94,20 @@
 	SDL_VideoDevice *device;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
 	if ( device ) {
-		memset(device, 0, (sizeof *device));
+		SDL_memset(device, 0, (sizeof *device));
 		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
+				SDL_malloc((sizeof *device->hidden));
 	}
 	if ( (device == NULL) || (device->hidden == NULL) ) {
 		SDL_OutOfMemory();
 		if ( device ) {
-			free(device);
+			SDL_free(device);</