Removed uses of stdlib.h and string.h
authorSam Lantinga <slouken@libsdl.org>
Tue, 07 Feb 2006 09:29:18 +0000
changeset 1338 604d73db6802
parent 1337 c687f06c7473
child 1339 62802d9d7c87
Removed uses of stdlib.h and string.h
src/SDL.c
src/SDL_error.c
src/audio/SDL_audiodev.c
src/audio/SDL_audiomem.c
src/audio/SDL_wave.c
src/audio/alsa/SDL_alsa_audio.c
src/audio/amigaos/SDL_ahiaudio.h
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_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/mme/SDL_mmeaudio.h
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/aix/SDL_syscdrom.c
src/cdrom/beos/SDL_syscdrom.cc
src/cdrom/bsdi/SDL_syscdrom.c
src/cdrom/dc/SDL_syscdrom.c
src/cdrom/freebsd/SDL_syscdrom.c
src/cdrom/linux/SDL_syscdrom.c
src/cdrom/macosx/AudioFileReaderThread.c
src/cdrom/macosx/SDLOSXCAGuard.c
src/cdrom/macosx/SDL_syscdrom.c
src/cdrom/mint/SDL_syscdrom.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/file/SDL_rwops.c
src/joystick/SDL_joystick.c
src/joystick/amigaos/SDL_sysjoystick.c
src/joystick/beos/SDL_bejoystick.cc
src/joystick/bsd/SDL_sysjoystick.c
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/dc/SDL_sysjoystick.c
src/joystick/linux/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/macosx/SDL_loadso.c
src/main/beos/SDL_BeApp.cc
src/main/macos/SDL_main.c
src/stdlib/SDL_malloc.c
src/stdlib/SDL_string.c
src/thread/SDL_thread.c
src/thread/amigaos/SDL_systhread.c
src/thread/amigaos/SDL_systhread_c.h
src/thread/amigaos/SDL_thread.c
src/thread/bsdi/SDL_syssem.c
src/thread/dc/SDL_syscond.c
src/thread/dc/SDL_sysmutex.c
src/thread/dc/SDL_syssem.c
src/thread/epoc/SDL_sysmutex.cpp
src/thread/epoc/SDL_syssem.cpp
src/thread/epoc/SDL_systhread.cpp
src/thread/generic/SDL_syscond.c
src/thread/generic/SDL_sysmutex.c
src/thread/generic/SDL_syssem.c
src/thread/irix/SDL_systhread.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/video/SDL_RLEaccel.c
src/video/SDL_blit_N.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_xbiosevents.c
src/video/bwindow/SDL_sysmouse.cc
src/video/bwindow/SDL_sysvideo.cc
src/video/bwindow/SDL_sysyuv.cc
src/video/cybergfx/SDL_cgximage.c
src/video/cybergfx/SDL_cgxmodes.c
src/video/cybergfx/SDL_cgxvideo.c
src/video/cybergfx/SDL_cgxvideo.h
src/video/cybergfx/SDL_cgxyuv.c
src/video/dc/SDL_dcvideo.c
src/video/dga/SDL_dgavideo.c
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_yuv.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_gemmouse.c
src/video/gem/SDL_gemvideo.c
src/video/ggi/SDL_ggievents.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/nanox/SDL_nximage.c
src/video/nanox/SDL_nxmodes.c
src/video/nanox/SDL_nxmouse.c
src/video/nanox/SDL_nxvideo.c
src/video/nanox/SDL_nxwm.c
src/video/os2fslib/SDL_os2fslib.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_pgvideo.c
src/video/ps2gs/SDL_gsevents.c
src/video/ps2gs/SDL_gsmouse.c
src/video/ps2gs/SDL_gsvideo.c
src/video/ps2gs/SDL_gsyuv.c
src/video/qtopia/SDL_sysmouse.cc
src/video/qtopia/SDL_sysvideo.cc
src/video/quartz/SDL_QuartzEvents.m
src/video/riscos/SDL_riscosFullScreenVideo.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_wimpvideo.c
src/video/svga/SDL_svgaevents.c
src/video/svga/SDL_svgavideo.c
src/video/vgl/SDL_vglvideo.c
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_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/src/SDL.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/SDL.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,9 +27,9 @@
 #endif
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
 #include "SDL_endian.h"
 #include "SDL_fatal.h"
-#include "SDL_stdlib.h"
 #ifndef DISABLE_VIDEO
 #include "SDL_leaks.h"
 #endif
--- a/src/SDL_error.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/SDL_error.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,9 @@
 
 /* Simple error handling in SDL */
 
-#include "SDL_types.h"
 #include "SDL_stdlib.h"
 #include "SDL_string.h"
+#include "SDL_types.h"
 #include "SDL_error.h"
 #include "SDL_error_c.h"
 #ifndef DISABLE_THREADS
--- a/src/audio/SDL_audiodev.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/SDL_audiodev.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,13 +24,12 @@
 
 #if defined(unix) || defined(__unix__) || defined(__riscos__)
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <string.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audiodev_c.h"
 
 #ifndef _PATH_DEV_DSP
@@ -80,7 +79,8 @@
 
 		instance = 1;
 		do { /* Don't use errno ENOENT - it may not be thread-safe */
-			sprintf(audiopath, "%s%d", audiodev, instance++);
+			SDL_snprintf(audiopath, SDL_arraysize(audiopath),
+			             "%s%d", audiodev, instance++);
 			exists = 0;
 			if ( stat(audiopath, &sb) == 0 ) {
 				exists = 1;
@@ -100,11 +100,11 @@
 
 /* Get the name of the audio device we use for output */
 
-#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <string.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audiodev_c.h"
 
 #ifndef _PATH_DEV_DSP
@@ -158,7 +158,7 @@
 
     cycle    = 0;
     while( devsettings[cycle][0] != '\0' ) {
-        sprintf( audiopath,
+        SDL_snprintf( audiopath, SDL_arraysize(audiopath),
                  _PATH_DEV_DSP,
                  devsettings[cycle][0],
                  devsettings[cycle][1],
--- a/src/audio/SDL_audiomem.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/SDL_audiomem.c	Tue Feb 07 09:29:18 2006 +0000
@@ -31,8 +31,8 @@
 #include <stddef.h>
 #endif
 
+#include "SDL_stdlib.h"
 #include "SDL_audiomem.h"
-#include "SDL_stdlib.h"
 
 /* Allocate memory that will be shared between threads (freed on exit) */
 void *SDL_AllocAudioMem(int size)
--- a/src/audio/SDL_wave.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/SDL_wave.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,10 +24,10 @@
 
 /* Microsoft WAVE file loading routines */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_audio.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_wave.h"
 #include "SDL_endian.h"
 
--- a/src/audio/alsa/SDL_alsa_audio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/alsa/SDL_alsa_audio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,16 +24,11 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <signal.h>
 #include <sys/types.h>
-#include <sys/time.h>
+#include <signal.h>	/* For kill() */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/amigaos/SDL_ahiaudio.h	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/amigaos/SDL_ahiaudio.h	Tue Feb 07 09:29:18 2006 +0000
@@ -30,8 +30,6 @@
 #else
 #include <inline/exec.h>
 #endif
-#include <stdlib.h>
-#include <string.h>
 
 #include <devices/ahi.h>
 #include "mydebug.h"
--- a/src/audio/arts/SDL_artsaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/arts/SDL_artsaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,14 +22,8 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <sys/types.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/baudio/SDL_beaudio.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/baudio/SDL_beaudio.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -22,15 +22,14 @@
 
 /* Allow access to the audio stream on BeOS */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <SoundPlayer.h>
 
 #include "SDL_BeApp.h"
 
 extern "C" {
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
 #include "SDL_sysaudio.h"
--- a/src/audio/dart/SDL_dart.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/dart/SDL_dart.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,10 +22,8 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_types.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
--- a/src/audio/dc/SDL_dcaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/dc/SDL_dcaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,10 +23,6 @@
 
 /* Output dreamcast aica */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -34,6 +30,8 @@
 #include <fcntl.h>
 
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/disk/SDL_diskaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/disk/SDL_diskaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,9 +25,7 @@
 
 /* Output raw audio data to a file. */
 
-#include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/stat.h>
@@ -36,6 +34,8 @@
 #include <fcntl.h>
 
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/dma/SDL_dmaaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/dma/SDL_dmaaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,7 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -46,6 +44,8 @@
 #define MAP_FAILED	((Uint8 *)-1)
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/dmedia/SDL_irixaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/dmedia/SDL_irixaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,8 +23,8 @@
 /* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */
 /* patch for IRIX 5 by Georg Schwarz 18/07/2004 */
 
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_timer.h"
 #include "SDL_audio.h"
--- a/src/audio/dsp/SDL_dspaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/dsp/SDL_dspaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,9 +25,7 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
+#include <stdio.h>	/* For perror() ... should we really do this? */
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -43,6 +41,8 @@
 #include <sys/soundcard.h>
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
@@ -303,7 +303,6 @@
 #endif
 	if ( ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &frag_spec) < 0 ) {
 		perror("SNDCTL_DSP_SETFRAGMENT");
-		fprintf(stderr, "Warning: Couldn't set audio fragment size\n");
 	}
 #ifdef DEBUG_AUDIO
 	{ audio_buf_info info;
--- a/src/audio/esd/SDL_esdaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/esd/SDL_esdaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,15 +24,12 @@
 
 #ifdef ESD_SUPPORT
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
-#include <signal.h>
-#include <unistd.h>
 
 #include <esd.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
@@ -257,7 +254,7 @@
 	FILE *fp;
 	static char temp[BUFSIZ];
 
-	sprintf(temp, "/proc/%d/cmdline", getpid());
+	SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid());
 	fp = fopen(temp, "r");
 	if ( fp != NULL ) {
 		if ( fgets(temp, sizeof(temp)-1, fp) ) {
--- a/src/audio/macosx/SDL_coreaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/macosx/SDL_coreaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,11 +22,8 @@
 
 #include <AudioUnit/AudioUnit.h>
 
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
@@ -113,8 +110,10 @@
     /* No SDL conversion should be needed here, ever, since we accept
        any input format in OpenAudio, and leave the conversion to CoreAudio.
      */
+    /*
     assert(!this->convert.needed);
     assert(this->spec.channels == ioData->mNumberChannels);
+     */
     
     remaining = ioData->mDataByteSize;
     ptr = ioData->mData;
@@ -270,8 +269,7 @@
     /* Allocate a sample buffer */
     bufferOffset = bufferSize = this->spec.size;
     buffer = SDL_malloc(bufferSize);
-    assert(buffer);
-    
+
     /* Finally, start processing of the audio unit */
     result = AudioOutputUnitStart (outputAudioUnit);
     CHECK_RESULT("AudioOutputUnitStart")    
--- a/src/audio/macrom/SDL_romaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/macrom/SDL_romaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -30,9 +30,6 @@
 #  include <DriverServices.h>
 #endif
 
-#include <stdlib.h>
-#include <stdio.h>
-
 #if !defined(NewSndCallBackUPP) && (UNIVERSAL_INTERFACES_VERSION < 0x0335)
 #if !defined(NewSndCallBackProc) /* avoid circular redefinition... */
 #define NewSndCallBackUPP NewSndCallBackProc
@@ -42,6 +39,8 @@
 #endif
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
@@ -455,7 +454,7 @@
 
     /* allocate the 2 double-back buffers */
     for ( i=0; i<2; ++i ) {
-        audio_buf[i] = calloc(1, sizeof(SndDoubleBuffer)+spec->size);
+        audio_buf[i] = SDL_calloc(1, sizeof(SndDoubleBuffer)+spec->size);
         if ( audio_buf[i] == NULL ) {
             SDL_OutOfMemory();
             return(-1);
--- a/src/audio/mint/SDL_mintaudio_dma8.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_dma8.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,15 +27,13 @@
 	Patrice Mandin
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
 /* Mint includes */
 #include <mint/osbind.h>
 #include <mint/falcon.h>
 #include <mint/cookie.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
--- a/src/audio/mint/SDL_mintaudio_gsxb.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,15 +27,13 @@
 	Patrice Mandin
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
 /* Mint includes */
 #include <mint/osbind.h>
 #include <mint/falcon.h>
 #include <mint/cookie.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
--- a/src/audio/mint/SDL_mintaudio_mcsn.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,9 +27,6 @@
 	Patrice Mandin
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <support.h>
 
 /* Mint includes */
@@ -37,6 +34,8 @@
 #include <mint/falcon.h>
 #include <mint/cookie.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
--- a/src/audio/mint/SDL_mintaudio_stfa.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_stfa.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,15 +27,13 @@
 	Patrice Mandin
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
 /* Mint includes */
 #include <mint/osbind.h>
 #include <mint/falcon.h>
 #include <mint/cookie.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
--- a/src/audio/mint/SDL_mintaudio_xbios.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_xbios.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,9 +27,6 @@
 	Patrice Mandin, Didier Méquignon
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <unistd.h>
 #include <support.h>
 
@@ -38,6 +35,8 @@
 #include <mint/falcon.h>
 #include <mint/cookie.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_audio.h"
 #include "SDL_audio_c.h"
--- a/src/audio/mme/SDL_mmeaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/mme/SDL_mmeaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -91,7 +91,7 @@
     int len;
     char errbuf[MAXERRORLENGTH];
 
-    sprintf(errbuf, "%s: ", function);
+    SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
     len = SDL_strlen(errbuf);
     waveOutGetErrorText(code, errbuf+len, MAXERRORLENGTH-len);
     SDL_SetError("%s",errbuf);
--- a/src/audio/mme/SDL_mmeaudio.h	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/mme/SDL_mmeaudio.h	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,6 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <mme_api.h>
 
 #include "SDL_audio.h"
--- a/src/audio/nas/SDL_nasaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/nas/SDL_nasaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,13 +26,11 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
 #include <signal.h>
 #include <unistd.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/nto/SDL_nto_audio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/nto/SDL_nto_audio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,9 +20,6 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -34,6 +31,8 @@
 #include <sys/neutrino.h>
 #include <sys/asoundlib.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/openbsd/SDL_openbsdaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/openbsd/SDL_openbsdaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,19 +25,17 @@
  * vedge@vedge.com.ar.
  */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <signal.h>
 #include <sys/time.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/audioio.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/paudio/SDL_paudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/paudio/SDL_paudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,9 +24,6 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -34,6 +31,8 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audiomem.h"
--- a/src/audio/sun/SDL_sunaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/sun/SDL_sunaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,11 +22,8 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <string.h>
 #ifdef __NetBSD__
 #include <sys/ioctl.h>
 #include <sys/audioio.h>
@@ -39,6 +36,8 @@
 #endif
 #include <unistd.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_endian.h"
 #include "SDL_audio.h"
 #include "SDL_audiomem.h"
--- a/src/audio/ums/SDL_umsaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/ums/SDL_umsaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,9 +24,6 @@
 
 /* Allow access to a raw mixing buffer */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -36,6 +33,8 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_error.h"
 #include "SDL_audio_c.h"
--- a/src/audio/windib/SDL_dibaudio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/windib/SDL_dibaudio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,11 +25,11 @@
 #include "SDL_windows.h"
 #include <mmsystem.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_audio.h"
 #include "SDL_mutex.h"
 #include "SDL_timer.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_audio_c.h"
 #include "SDL_dibaudio.h"
 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
--- a/src/audio/windx5/SDL_dx5audio.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/audio/windx5/SDL_dx5audio.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,12 +22,12 @@
 
 /* Allow access to a raw mixing buffer */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_types.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_audio.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_audio_c.h"
 #include "SDL_dx5audio.h"
 
--- a/src/cdrom/SDL_cdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/SDL_cdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,10 +22,10 @@
 
 /* This is the CD-audio control API for Simple DirectMedia Layer */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_syscdrom.h"
 
 #if !defined(macintosh)
--- a/src/cdrom/aix/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/aix/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,11 +27,8 @@
 #define DEBUG_CDROM 1
 
 #include <sys/types.h>
-#include <stdlib.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 
@@ -43,6 +40,8 @@
 #include <fstab.h>
 #include <sys/scdisk.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 #include "SDL_syscdrom.h"
--- a/src/cdrom/beos/SDL_syscdrom.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/beos/SDL_syscdrom.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -25,10 +25,7 @@
  */
 
 #include <sys/types.h>
-#include <stdlib.h>
 #include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
 #include <unistd.h>
 
 #include <scsi.h>
@@ -36,6 +33,8 @@
 #include <Entry.h>
 #include <Path.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 extern "C" {
--- a/src/cdrom/bsdi/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/bsdi/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -29,18 +29,16 @@
 */
 
 #include <sys/types.h>
-#include <stdlib.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
 #include <err.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include </sys/dev/scsi/scsi.h>
 #include </sys/dev/scsi/scsi_ioctl.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 #include "SDL_syscdrom.h"
@@ -303,7 +301,7 @@
 			char *insert;
 			exists = 1;
 			for ( j=checklist[i][1]; exists; ++j ) {
-				sprintf(drive, "/dev/%sc", &checklist[i][3]);
+				SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc", &checklist[i][3]);
 				insert = SDL_strchr(drive, '?');
 				if ( insert != NULL ) {
 					*insert = j;
@@ -323,7 +321,7 @@
 				}
 			}
 		} else {
-			sprintf(drive, "/dev/%s", checklist[i]);
+			SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]);
 			if ( CheckDrive(drive, &stbuf) > 0 ) {
 				AddDrive(drive, &stbuf);
 			}
--- a/src/cdrom/dc/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/dc/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,8 +22,6 @@
 
 /* Functions for system-level CD-ROM audio control */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <dc/cdrom.h>
 #include <dc/spu.h>
 
--- a/src/cdrom/freebsd/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/freebsd/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,15 +23,14 @@
 /* Functions for system-level CD-ROM audio control */
 
 #include <sys/types.h>
-#include <stdlib.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/cdio.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 #include "SDL_syscdrom.h"
@@ -189,7 +188,7 @@
 			char *insert;
 			exists = 1;
 			for ( j=checklist[i][1]; exists; ++j ) {
-				sprintf(drive, "/dev/%sc", &checklist[i][3]);
+				SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc", &checklist[i][3]);
 				insert = SDL_strchr(drive, '?');
 				if ( insert != NULL ) {
 					*insert = j;
@@ -209,7 +208,7 @@
 				}
 			}
 		} else {
-			sprintf(drive, "/dev/%s", checklist[i]);
+			SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]);
 			if ( CheckDrive(drive, &stbuf) > 0 ) {
 				AddDrive(drive, &stbuf);
 			}
--- a/src/cdrom/linux/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/linux/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,12 +23,9 @@
 /* Functions for system-level CD-ROM audio control */
 
 #include <sys/types.h>
-#include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #ifdef __linux__
@@ -83,6 +80,8 @@
 #endif
 #endif /* USE_MNTENT */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 #include "SDL_syscdrom.h"
@@ -336,7 +335,7 @@
 			char *insert;
 			exists = 1;
 			for ( j=checklist[i][1]; exists; ++j ) {
-				sprintf(drive, "/dev/%s", &checklist[i][3]);
+				SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]);
 				insert = SDL_strchr(drive, '?');
 				if ( insert != NULL ) {
 					*insert = j;
@@ -359,7 +358,7 @@
 				}
 			}
 		} else {
-			sprintf(drive, "/dev/%s", checklist[i]);
+			SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]);
 #ifdef DEBUG_CDROM
   fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive);
 #endif
--- a/src/cdrom/macosx/AudioFileReaderThread.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/macosx/AudioFileReaderThread.c	Tue Feb 07 09:29:18 2006 +0000
@@ -546,7 +546,7 @@
 {
     if (afm != NULL) {
         if (afm->mFileBuffer) {
-            free (afm->mFileBuffer);
+            free(afm->mFileBuffer);
         }
 
         SDL_free(afm);
@@ -594,7 +594,7 @@
     afm->mBufferOffset = inChunkSize;
     afm->mChunkSize = inChunkSize;
     afm->mFileLength = inFileLength;
-    afm->mFileBuffer = (char*) malloc (afm->mChunkSize * 2);
+    afm->mFileBuffer = (char*) SDL_malloc(afm->mChunkSize * 2);
     FSGetForkPosition(afm->mForkRefNum, &afm->mAudioDataOffset);
     assert (afm->mFileBuffer != NULL);
     return afm;
--- a/src/cdrom/macosx/SDLOSXCAGuard.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/macosx/SDLOSXCAGuard.c	Tue Feb 07 09:29:18 2006 +0000
@@ -68,12 +68,19 @@
 //  Includes
 //=============================================================================
 
+/*
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+*/
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 
 //#define NDEBUG 1
+/*
 #include <assert.h>
+*/
+#define assert(X)
 
 
 #include "SDLOSXCAGuard.h"
--- a/src/cdrom/macosx/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/macosx/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -58,7 +58,7 @@
         return 0;
         
     /* Allocate memory for tracks */
-    tracks[cdrom->id] = (FSRef*) calloc (1, sizeof(**tracks) * cdrom->numtracks);
+    tracks[cdrom->id] = (FSRef*) SDL_calloc (1, sizeof(**tracks) * cdrom->numtracks);
     if (tracks[cdrom->id] == NULL) {
         SDL_OutOfMemory ();
         return -1;
@@ -203,14 +203,14 @@
     }
     
     /* Allocate space for volumes */
-    volumes = (FSVolumeRefNum*) calloc (1, sizeof(*volumes) * SDL_numcds);
+    volumes = (FSVolumeRefNum*) SDL_calloc (1, sizeof(*volumes) * SDL_numcds);
     if (volumes == NULL) {
         SDL_OutOfMemory ();
         return -1;
     }
     
     /* Allocate space for tracks */
-    tracks = (FSRef**) calloc (1, sizeof(*tracks) * (SDL_numcds + 1));
+    tracks = (FSRef**) SDL_calloc (1, sizeof(*tracks) * (SDL_numcds + 1));
     if (tracks == NULL) {
         SDL_OutOfMemory ();
         return -1;
--- a/src/cdrom/mint/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/mint/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,9 +27,6 @@
 */
 
 #include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 
 #include <cdromio.h>
 #include <metados.h>
--- a/src/cdrom/openbsd/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/openbsd/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,16 +24,15 @@
 
 #include <sys/types.h>
 #include <sys/ioctl.h>
-#include <stdlib.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/cdio.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 #include "SDL_syscdrom.h"
@@ -198,7 +197,7 @@
 			char *insert;
 			exists = 1;
 			for ( j=checklist[i][1]; exists; ++j ) {
-				sprintf(drive, "/dev/%s", &checklist[i][3]);
+				SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]);
 				insert = SDL_strchr(drive, '?');
 				if ( insert != NULL ) {
 					*insert = j;
@@ -218,7 +217,7 @@
 				}
 			}
 		} else {
-			sprintf(drive, "/dev/%s", checklist[i]);
+			SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]);
 			if ( CheckDrive(drive, &stbuf) > 0 ) {
 				AddDrive(drive, &stbuf);
 			}
--- a/src/cdrom/os2/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/os2/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,10 +25,9 @@
 #define INCL_MCIOS2
 #include <os2.h>
 #include <os2me.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 #include "SDL_syscdrom.h"
--- a/src/cdrom/osf/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/osf/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -31,12 +31,9 @@
 #include <io/cam/cdrom.h>
 #include <io/cam/rzdisk.h>
 #include <io/common/devgetinfo.h>
-#include <alloca.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 #include "SDL_syscdrom.h"
@@ -218,7 +215,7 @@
 	    while (devent = readdir(devdir))
 		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);
+			SDL_snprintf(drive, SDL_arraysize(drive), "%s/%s", checklist[i].dir, devent->d_name);
 #ifdef DEBUG_CDROM
 			fprintf(stderr, "Try to add drive: %s\n", drive);
 #endif
--- a/src/cdrom/qnx/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/qnx/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,17 +23,16 @@
 /* Functions for system-level CD-ROM audio control */
 
 #include <sys/types.h>
-#include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
-#include <stdio.h>
 #include <errno.h>
-#include <string.h>
 #include <unistd.h>
 #include <sys/cdrom.h>
 #include <sys/dcmd_cam.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
 #include "SDL_timer.h"
@@ -218,7 +217,7 @@
 
             for ( j=checklist[i][1]; exists; ++j )
             {
-                sprintf(drive, "/dev/%s", &checklist[i][3]);
+                SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", &checklist[i][3]);
                 insert = SDL_strchr(drive, '?');
                 if (insert != NULL)
                 {
@@ -242,7 +241,7 @@
         }
         else
         {
-            sprintf(drive, "/dev/%s", checklist[i]);
+            SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]);
             if (CheckDrive(drive, &stbuf) > 0)
             {
                 AddDrive(drive, &stbuf);
--- a/src/cdrom/win32/SDL_syscdrom.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/cdrom/win32/SDL_syscdrom.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,10 +25,10 @@
 #include "SDL_windows.h"
 #include <mmsystem.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_cdrom.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_syscdrom.h"
 
 /* This really broken?? */
--- a/src/file/SDL_rwops.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/file/SDL_rwops.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,10 +24,10 @@
    data sources.  It can easily be extended to files, memory, etc.
 */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_rwops.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 
 #ifdef HAVE_STDIO_H
 
--- a/src/joystick/SDL_joystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/SDL_joystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,10 +22,10 @@
 
 /* This is the joystick API for Simple DirectMedia Layer */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_events.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #ifndef DISABLE_EVENTS
 #include "SDL_events_c.h"
 #endif
--- a/src/joystick/amigaos/SDL_sysjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/amigaos/SDL_sysjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,8 +23,6 @@
 
 /* This is the system specific header for the SDL joystick API */
 
-#include <stdio.h>		/* For the definition of NULL */
-
 #include <libraries/lowlevel.h>
 #if defined(__SASC) || defined(STORMC4_WOS)
 #include <proto/exec.h>
@@ -39,8 +37,8 @@
 
 extern struct ExecBase *SysBase;
 extern struct GfxBase *GfxBase;
-#include <stdlib.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_joystick.h"
 #include "SDL_sysjoystick.h"
--- a/src/joystick/beos/SDL_bejoystick.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/beos/SDL_bejoystick.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -22,15 +22,13 @@
 
 /* This is the system specific header for the SDL joystick API */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include <be/support/String.h>
 #include <be/device/Joystick.h>
 
 extern "C" {
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_joystick.h"
 #include "SDL_sysjoystick.h"
--- a/src/joystick/bsd/SDL_sysjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/bsd/SDL_sysjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -29,11 +29,8 @@
 
 #include <sys/param.h>
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <string.h>
 #include <errno.h>
 
 #if defined(HAVE_USB_H)
@@ -59,6 +56,8 @@
 #include <machine/joystick.h>
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_joystick.h"
 #include "SDL_sysjoystick.h"
@@ -145,7 +144,7 @@
 	for (i = 0; i < MAX_UHID_JOYS; i++) {
 		SDL_Joystick nj;
 
-		sprintf(s, "/dev/uhid%d", i);
+		SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
 
 		nj.index = SDL_numjoysticks;
 		joynames[nj.index] = strdup(s);
@@ -159,7 +158,7 @@
 		}
 	}
 	for (i = 0; i < MAX_JOY_JOYS; i++) {
-		sprintf(s, "/dev/joy%d", i);
+		SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
 		fd = open(s, O_RDONLY);
 		if (fd != -1) {
 			joynames[SDL_numjoysticks++] = strdup(s);
@@ -312,7 +311,7 @@
 				case HUG_GAME_PAD:
 					s = hid_usage_in_page(hitem.usage);
 					sp = SDL_malloc(SDL_strlen(s) + 5);
-					sprintf(sp, "%s (%d)", s,
+					SDL_snprintf(sp, SDL_strlen(s) + 5, "%s (%d)", s,
 					    joy->index);
 					joydevnames[joy->index] = sp;
 				}
--- a/src/joystick/darwin/SDL_sysjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,11 +23,8 @@
 /* SDL joystick driver for Darwin / MacOS X, based on the IOKit HID API */
 /* Written 2001 by Max Horn */
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>
 #include <ctype.h>
-#include <sys/errno.h>
 #include <sysexits.h>
 #include <mach/mach.h>
 #include <mach/mach_error.h>
--- a/src/joystick/dc/SDL_sysjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/dc/SDL_sysjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,8 @@
 
 /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
 
-#include <stdlib.h>
-#include <stdio.h>		/* For the definition of NULL */
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_joystick.h"
 #include "SDL_sysjoystick.h"
--- a/src/joystick/linux/SDL_sysjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,6 @@
 
 /* This is the system specific header for the SDL joystick API */
 
-#include <stdio.h>		/* For the definition of NULL */
-#include <stdlib.h>		/* For SDL_getenv() prototype */
-#include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -38,6 +35,8 @@
 #include <linux/input.h>
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_joystick.h"
 #include "SDL_sysjoystick.h"
@@ -325,7 +324,7 @@
 
 	for ( i=0; i<SDL_TABLESIZE(joydev_pattern); ++i ) {
 		for ( j=0; j < MAX_JOYSTICKS; ++j ) {
-			sprintf(path, joydev_pattern[i], j);
+			SDL_snprintf(path, SDL_arraysize(path), joydev_pattern[i], j);
 
 			/* rcg06302000 replaced access(F_OK) call with stat().
 			 * stat() will fail if the file doesn't exist, so it's
--- a/src/joystick/mint/SDL_sysjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/mint/SDL_sysjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,13 +26,11 @@
  *	Patrice Mandin
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include <mint/cookie.h>
 #include <mint/osbind.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_types.h"
 #include "SDL_error.h"
 #include "SDL_joystick.h"
--- a/src/joystick/os2/SDL_sysjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/os2/SDL_sysjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,8 +22,6 @@
 
 /* OS/2 Joystick driver, contributed by Daniel Caetano */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <mem.h>
 
 #define INCL_DOSDEVICES
@@ -32,6 +30,8 @@
 #include <os2.h>
 #include "joyos2.h"
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_joystick.h"
 #include "SDL_sysjoystick.h"
@@ -217,7 +217,7 @@
 		if (joycfg.buttons>=7) SYS_JoyData[0].buttoncalc[2]=((axis[2]->upper+axis[3]->centre)>>1);
 		if (joycfg.buttons>=8) SYS_JoyData[0].buttoncalc[3]=((axis[3]->upper+axis[3]->centre)>>1);
 		/* Intialize Joystick Name */
-		strcpy (SYS_JoyData[0].szDeviceName,joycfg.name);
+		SDL_strcpy (SYS_JoyData[0].szDeviceName,joycfg.name);
 		}
 	/* Default Init ... autoconfig */
 	else
@@ -294,7 +294,8 @@
 			}
 		/* Hack to define Joystick Port Names */
 		if ( numdevs > maxdevs ) numdevs = maxdevs;
-		for (i=0; i<numdevs; i++) sprintf (SYS_JoyData[i].szDeviceName,"Default Joystick %c",'A'+SYS_JoyData[i].id);
+		for (i=0; i<numdevs; i++) {
+			SDL_sprintf (SYS_JoyData[i].szDeviceName, SDL_arraysize(szDeviceName), "Default Joystick %c", 'A'+SYS_JoyData[i].id);
 		}
 	}
 /* Return the number of devices found */
--- a/src/joystick/riscos/SDL_sysjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/riscos/SDL_sysjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -29,9 +29,8 @@
 
 /* This is the system specific header for the SDL joystick API */
 
-#include <stdio.h>		/* For the definition of NULL */
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_joystick.h"
 #include "SDL_sysjoystick.h"
--- a/src/joystick/win32/SDL_mmjoystick.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/joystick/win32/SDL_mmjoystick.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,11 +22,11 @@
 
 /* Win32 MultiMedia Joystick driver, contributed by Andrei de A. Formiga */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_events.h"
 #include "SDL_joystick.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysjoystick.h"
 #include "SDL_joystick_c.h"
 
--- a/src/loadso/macosx/SDL_loadso.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/loadso/macosx/SDL_loadso.c	Tue Feb 07 09:29:18 2006 +0000
@@ -62,9 +62,6 @@
 */
 
 #include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdarg.h>
@@ -73,6 +70,9 @@
 #include <mach-o/nlist.h>
 #include <mach-o/getsect.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
+
 /* Just playing to see if it would compile with the freebsd headers, it does,
  * but because of the different values for RTLD_LOCAL etc, it would break binary
  * compat... oh well
@@ -390,14 +390,14 @@
 	}
 	if (!path)
 	{
-		path = (char **)calloc(MAX_SEARCH_PATHS, sizeof(char **));
+		path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **));
 	}
 	if (!list && !end)
 		list = searchList();
 	if (i >= (numsize))
 	{
 		debug("Increasing size for long PATH");
-		tmp = (char **)calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
+		tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
 		if (tmp)
 		{
 			SDL_memcpy(tmp, path, sizeof(char **) * numsize);
@@ -515,7 +515,7 @@
 		dls = dls->next;
 	if (!dls)
 #endif
-		dls = calloc(sizeof(*dls),1);
+		dls = SDL_calloc(sizeof(*dls),1);
 	return dls;
 }
 
@@ -1017,7 +1017,7 @@
 	malloc_sym = SDL_malloc(sym_len + 2);
 	if (malloc_sym)
 	{
-		sprintf(malloc_sym, "_%s", symbol);
+		SDL_sprintf(malloc_sym, sym_len+2, "_%s", symbol);
 		value = dlsymIntern(handle, malloc_sym, 1);
 		SDL_free(malloc_sym);
 	}
@@ -1062,7 +1062,7 @@
 	malloc_sym = SDL_malloc(sym_len + 2);
 	if (malloc_sym)
 	{
-		sprintf(malloc_sym, "_%s", symbol);
+		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
 		value = dlsymIntern(handle, malloc_sym, 1);
 		SDL_free(malloc_sym);
 	}
@@ -1347,7 +1347,7 @@
 	malloc_sym = SDL_malloc(sym_len + 2);
 	if (malloc_sym)
 	{
-		sprintf(malloc_sym, "_%s", symbol);
+		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
 		rv.d = dlsymIntern(handle, malloc_sym, 1);
 		SDL_free(malloc_sym);
 	}
--- a/src/main/beos/SDL_BeApp.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/main/beos/SDL_BeApp.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -25,8 +25,6 @@
 #include <AppKit.h>
 #include <storage/Path.h>
 #include <storage/Entry.h>
-#include <stdlib.h>
-#include <string.h>
 #include <unistd.h>
 
 #include "SDL_BeApp.h"
--- a/src/main/macos/SDL_main.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/main/macos/SDL_main.c	Tue Feb 07 09:29:18 2006 +0000
@@ -589,7 +589,7 @@
 
     /* Parse C-string into argv and argc */
     nargs = ParseCommandLine (commandLine, NULL);
-    args = (char **)SDL_malloc((nargs+1)*(sizeof *args));
+    args = (char **)malloc((nargs+1)*(sizeof *args));
     if ( args == NULL ) {
 		exit(-1);
 	}
--- a/src/stdlib/SDL_malloc.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/stdlib/SDL_malloc.c	Tue Feb 07 09:29:18 2006 +0000
@@ -29,19 +29,14 @@
 #ifndef HAVE_MALLOC
 
 #define LACKS_STDIO_H
-#define LACKS_UNISTD_H
-#define LACKS_FCNTL_H
-#define LACKS_SYS_PARAM_H
-#define LACKS_SYS_MMAN_H
 #define LACKS_STRINGS_H
 #define LACKS_STRING_H
-#define LACKS_SYS_TYPES_H
-#define LACKS_ERRNO_H
 #define LACKS_STDLIB_H
 #define ABORT
 #define memset	SDL_memset
 #define memcpy	SDL_memcpy
 #define malloc	SDL_malloc
+#define calloc	SDL_calloc
 #define realloc	SDL_realloc
 #define free	SDL_free
 
--- a/src/stdlib/SDL_string.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/stdlib/SDL_string.c	Tue Feb 07 09:29:18 2006 +0000
@@ -343,7 +343,8 @@
 {
     char *bufp = string;
     while ( *bufp ) {
-        *bufp++ = toupper(*bufp);
+        *bufp = toupper(*bufp);
+	++bufp;
     }
     return string;
 }
@@ -354,7 +355,8 @@
 {
     char *bufp = string;
     while ( *bufp ) {
-        *bufp++ = tolower(*bufp);
+        *bufp = tolower(*bufp);
+	++bufp;
     }
     return string;
 }
@@ -367,6 +369,7 @@
         if ( *string == c ) {
             return (char *)string;
         }
+	++string;
     }
     return NULL;
 }
@@ -380,6 +383,7 @@
         if ( *bufp == c ) {
             return (char *)bufp;
         }
+	--bufp;
     }
     return NULL;
 }
@@ -393,6 +397,7 @@
         if ( SDL_strncmp(haystack, needle, length) == 0 ) {
             return (char *)haystack;
         }
+	++haystack;
     }
     return NULL;
 }
--- a/src/thread/SDL_thread.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/SDL_thread.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,11 +22,11 @@
 
 /* System independent thread management routines for SDL */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_mutex.h"
 #include "SDL_thread.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_thread_c.h"
 #include "SDL_systhread.h"
 
--- a/src/thread/amigaos/SDL_systhread.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/amigaos/SDL_systhread.c	Tue Feb 07 09:29:18 2006 +0000
@@ -102,7 +102,7 @@
 	D(bug("Sending %lx to the new thread...\n",args));
 
 	if(args)
-		sprintf(buffer,"%ld",args);
+		SDL_snprintf(buffer, SDL_arraysize(buffer),"%ld",args);
 
 	#ifdef STORMC4_WOS
 	thread->handle=CreateTaskPPCTags(TASKATTR_CODE,	RunThread,
--- a/src/thread/amigaos/SDL_systhread_c.h	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/amigaos/SDL_systhread_c.h	Tue Feb 07 09:29:18 2006 +0000
@@ -31,9 +31,6 @@
 #include <inline/exec.h>
 #endif
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include "mydebug.h"
 
 extern struct ExecBase *SysBase;
--- a/src/thread/amigaos/SDL_thread.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/amigaos/SDL_thread.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,10 +22,8 @@
 
 /* System independent thread management routines for SDL */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_mutex.h"
 #include "SDL_thread.h"
--- a/src/thread/bsdi/SDL_syssem.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/bsdi/SDL_syssem.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,15 +20,13 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_timer.h"
 
 #ifdef SDL_USE_PTHREADS
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>			/* For getpid() */
 #include <pthread.h>
 
--- a/src/thread/dc/SDL_syscond.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/dc/SDL_syscond.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,9 +26,7 @@
    implementation, written by Christopher Tate and Owen Smith.  Thanks!
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 
--- a/src/thread/dc/SDL_sysmutex.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/dc/SDL_sysmutex.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,7 @@
 
 /* An implementation of mutexes using semaphores */
 
-#include <stdio.h>
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_systhread_c.h"
--- a/src/thread/dc/SDL_syssem.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/dc/SDL_syssem.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,8 +22,6 @@
 
 /* An implementation of semaphores using mutexes and condition variables */
 
-#include <stdlib.h>
-
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_thread.h"
--- a/src/thread/epoc/SDL_sysmutex.cpp	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/epoc/SDL_sysmutex.cpp	Tue Feb 07 09:29:18 2006 +0000
@@ -29,9 +29,6 @@
 
 /* Mutex functions using the Win32 API */
 
-//#include <stdio.h>
-//#include <stdlib.h>
-
 #include<e32std.h>
 
 #include "SDL_error.h"
--- a/src/thread/epoc/SDL_syssem.cpp	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/epoc/SDL_syssem.cpp	Tue Feb 07 09:29:18 2006 +0000
@@ -28,8 +28,6 @@
 
 /* Semaphore functions using the Win32 API */
 
-//#include <stdio.h>
-//#include <stdlib.h>
 #include <e32std.h>
 
 #include "SDL_error.h"
--- a/src/thread/epoc/SDL_systhread.cpp	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/epoc/SDL_systhread.cpp	Tue Feb 07 09:29:18 2006 +0000
@@ -28,10 +28,6 @@
 */
 
 
-//#include <stdlib.h>
-//#include <stdio.h>
-
-
 extern "C" {
 #undef NULL
 #include "SDL_error.h"
--- a/src/thread/generic/SDL_syscond.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/generic/SDL_syscond.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,9 +26,9 @@
    implementation, written by Christopher Tate and Owen Smith.  Thanks!
  */
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
-#include "SDL_stdlib.h"
 
 struct SDL_cond
 {
--- a/src/thread/generic/SDL_sysmutex.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/generic/SDL_sysmutex.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,9 @@
 
 /* An implementation of mutexes using semaphores */
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
-#include "SDL_stdlib.h"
 #include "SDL_systhread_c.h"
 
 
--- a/src/thread/generic/SDL_syssem.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/generic/SDL_syssem.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,10 +22,10 @@
 
 /* An implementation of semaphores using mutexes and condition variables */
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_thread.h"
-#include "SDL_stdlib.h"
 #include "SDL_systhread_c.h"
 
 
--- a/src/thread/irix/SDL_systhread.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/irix/SDL_systhread.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,7 +22,6 @@
 
 /* IRIX thread management routines for SDL */
 
-#include <stdlib.h>
 #include <errno.h>
 #include <signal.h>
 #include <sys/types.h>
--- a/src/thread/linux/SDL_syscond.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/linux/SDL_syscond.c	Tue Feb 07 09:29:18 2006 +0000
@@ -40,9 +40,9 @@
 #include <sys/time.h>
 #include <unistd.h>
 #include <errno.h>
-#include <stdlib.h>
 #include <pthread.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_sysmutex_c.h"
--- a/src/thread/linux/SDL_sysmutex.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/linux/SDL_sysmutex.c	Tue Feb 07 09:29:18 2006 +0000
@@ -37,10 +37,9 @@
 
 #ifdef SDL_USE_PTHREADS
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <pthread.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 
@@ -59,7 +58,7 @@
 	pthread_mutexattr_t attr;
 
 	/* Allocate the structure */
-	mutex = (SDL_mutex *)calloc(1, sizeof(*mutex));
+	mutex = (SDL_mutex *)SDL_calloc(1, sizeof(*mutex));
 	if ( mutex ) {
 		pthread_mutexattr_init(&attr);
 #if defined(PTHREAD_RECURSIVE_MUTEX)
--- a/src/thread/linux/SDL_syssem.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/linux/SDL_syssem.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,7 +20,7 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_timer.h"
@@ -46,9 +46,6 @@
 #include "generic/SDL_syssem.c"
 #else
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>			/* For getpid() */
 #include <pthread.h>
 #include <semaphore.h>
 
@@ -74,7 +71,7 @@
 		static int semnum = 0;
 		char name[32];
 
-		sprintf(name, "/SDL_sem-%d-%4.4d", getpid(), semnum++);
+		SDL_snprintf(name, SDL_arraysize(name), "/SDL_sem-%d-%4.4d", getpid(), semnum++);
 		sem->sem = sem_open(name, O_CREAT, 0600, initial_value);
 		if ( sem->sem == (sem_t *)SEM_FAILED ) {
 			SDL_SetError("sem_open(%s) failed", name);
--- a/src/thread/linux/SDL_systhread.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/linux/SDL_systhread.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,6 +22,7 @@
 
 /* Linux thread management routines for SDL */
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_systhread.h"
@@ -138,7 +139,6 @@
 
 #else /* Linux-specific clone() based implementation */
 
-#include <stdlib.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/wait.h>
@@ -227,7 +227,7 @@
 	*/
 	char command[1024];
 
-	sprintf(command,
+	SDL_snprintf(command, SDL_arraysize(command),
 		"ps ax|fgrep -v fgrep|fgrep -v '<zombie>'|fgrep %d >/dev/null",
 								thread->handle);
 	while ( system(command) == 0 )
--- a/src/thread/os2/SDL_syscond.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/os2/SDL_syscond.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,9 +26,7 @@
    implementation, written by Christopher Tate and Owen Smith.  Thanks!
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 
--- a/src/thread/os2/SDL_sysmutex.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/os2/SDL_sysmutex.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,12 +22,11 @@
 
 /* Mutex functions using the OS/2 API */
 
-#include <stdio.h>
-#include <stdlib.h>
 #define INCL_DOSERRORS
 #define INCL_DOSSEMAPHORES
 #include <os2.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_mutex.h"
 
--- a/src/thread/os2/SDL_syssem.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/os2/SDL_syssem.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,13 +22,12 @@
 
 /* Semaphore functions using the OS/2 API */
 
-#include <stdio.h>
-#include <stdlib.h>
 #define INCL_DOS
 #define INCL_DOSERRORS
 #define INCL_DOSSEMAPHORES
 #include <os2.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_timer.h"
--- a/src/thread/os2/SDL_systhread.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/os2/SDL_systhread.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,13 +22,12 @@
 
 /* OS/2 thread management routines for SDL */
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <process.h>
 #define INCL_DOSERRORS
 #define INCL_DOSPROCESS
 #include <os2.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_systhread.h"
--- a/src/thread/pth/SDL_syscond.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/pth/SDL_syscond.c	Tue Feb 07 09:29:18 2006 +0000
@@ -4,10 +4,9 @@
  *	Patrice Mandin
  */
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <pth.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_syscond_c.h"
--- a/src/thread/pth/SDL_sysmutex.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/pth/SDL_sysmutex.c	Tue Feb 07 09:29:18 2006 +0000
@@ -4,10 +4,9 @@
  *	Patrice Mandin
  */
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <pth.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_mutex.h"
 #include "SDL_sysmutex_c.h"
--- a/src/thread/riscos/SDL_syscond.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/riscos/SDL_syscond.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,10 +27,9 @@
 #else
 #include <sys/time.h>
 #include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
 #include <pthread.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 #include "SDL_sysmutex_c.h"
--- a/src/thread/riscos/SDL_sysmutex.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/riscos/SDL_sysmutex.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,10 +26,9 @@
 #include "../generic/SDL_sysmutex.c"
 #else
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <pthread.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
 
@@ -47,7 +46,7 @@
 	pthread_mutexattr_t attr;
 
 	/* Allocate the structure */
-	mutex = (SDL_mutex *)calloc(1, sizeof(*mutex));
+	mutex = (SDL_mutex *)SDL_calloc(1, sizeof(*mutex));
 	if ( mutex ) {
 		pthread_mutexattr_init(&attr);
 #ifdef PTHREAD_NO_RECURSIVE_MUTEX
--- a/src/thread/riscos/SDL_syssem.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/riscos/SDL_syssem.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,12 +23,10 @@
 /* RISC OS semiphores based on linux code */
 
 
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_thread.h"
-
 #include "SDL_systhread_c.h"
 
 #ifdef DISABLE_THREADS
@@ -76,8 +74,6 @@
 #else
 
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>			/* For getpid() */
 #include <pthread.h>
 #include <semaphore.h>
--- a/src/thread/win32/SDL_sysmutex.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/win32/SDL_sysmutex.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,9 +24,9 @@
 
 #include "SDL_windows.h"
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_mutex.h"
-#include "SDL_stdlib.h"
 
 
 struct SDL_mutex {
--- a/src/thread/win32/SDL_syssem.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/win32/SDL_syssem.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,9 +24,9 @@
 
 #include "SDL_windows.h"
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
-#include "SDL_stdlib.h"
 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
 #include "win_ce_semaphore.h"
 #endif
--- a/src/thread/win32/SDL_systhread.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/thread/win32/SDL_systhread.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,9 +24,9 @@
 
 #include "SDL_windows.h"
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_thread.h"
-#include "SDL_stdlib.h"
 #include "SDL_systhread.h"
 
 typedef struct ThreadStartParms
--- a/src/timer/SDL_timer.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/timer/SDL_timer.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,9 +20,9 @@
     slouken@libsdl.org
 */
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
-#include "SDL_stdlib.h"
 #include "SDL_timer_c.h"
 #include "SDL_mutex.h"
 #include "SDL_systimer.h"
--- a/src/video/SDL_RLEaccel.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_RLEaccel.c	Tue Feb 07 09:29:18 2006 +0000
@@ -86,10 +86,10 @@
  */
 
 #include "SDL_types.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_video.h"
 #include "SDL_error.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysvideo.h"
 #include "SDL_blit.h"
 #include "SDL_RLEaccel_c.h"
--- a/src/video/SDL_blit_N.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_blit_N.c	Tue Feb 07 09:29:18 2006 +0000
@@ -32,8 +32,7 @@
 #ifdef HAVE_ALTIVEC_H
 #include <altivec.h>
 #endif
-#include <assert.h>
-#include <stdlib.h>
+#define assert(X)
 #ifdef MACOSX
 #include <sys/sysctl.h>
 static size_t GetL3CacheSize( void )
@@ -235,7 +234,6 @@
 
         assert(width == 0);
 
-
         /* do scalar until we can align... */
         ONE_PIXEL_BLEND((extrawidth), extrawidth);
 #undef ONE_PIXEL_BLEND
--- a/src/video/SDL_cursor.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_cursor.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,12 +22,12 @@
 
 /* General cursor handling code for SDL */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_mutex.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_blit.h"
 #include "SDL_events_c.h"
 #include "SDL_sysvideo.h"
--- a/src/video/SDL_gamma.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_gamma.c	Tue Feb 07 09:29:18 2006 +0000
@@ -36,9 +36,9 @@
 #define log(x)		__ieee754_log(x)
 #endif
 
-#include "SDL_error.h"
 #include "SDL_stdlib.h"
 #include "SDL_string.h"
+#include "SDL_error.h"
 #include "SDL_sysvideo.h"
 
 
--- a/src/video/SDL_pixels.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_pixels.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,11 +22,11 @@
 
 /* General (mostly internal) pixel/color manipulation routines for SDL */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_endian.h"
 #include "SDL_video.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysvideo.h"
 #include "SDL_blit.h"
 #include "SDL_pixels_c.h"
--- a/src/video/SDL_surface.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_surface.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,10 +20,10 @@
     slouken@libsdl.org
 */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysvideo.h"
 #include "SDL_cursor_c.h"
 #include "SDL_blit.h"
--- a/src/video/SDL_video.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_video.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,12 +23,12 @@
 /* The high-level video driver subsystem */
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_events.h"
 #include "SDL_mutex.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysvideo.h"
 #include "SDL_sysevents.h"
 #include "SDL_blit.h"
--- a/src/video/SDL_yuv.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_yuv.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,9 @@
 
 /* This is the implementation of the YUV video surface support */
 
+#include "SDL_stdlib.h"
 #include "SDL_video.h"
 #include "SDL_error.h"
-#include "SDL_stdlib.h"
 #include "SDL_sysvideo.h"
 #include "SDL_yuvfuncs.h"
 #include "SDL_yuv_sw_c.h"
--- a/src/video/SDL_yuv_sw.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/SDL_yuv_sw.c	Tue Feb 07 09:29:18 2006 +0000
@@ -82,11 +82,11 @@
  * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_cpuinfo.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_stretch_c.h"
 #include "SDL_yuvfuncs.h"
 #include "SDL_yuv_sw_c.h"
--- a/src/video/Xext/Xv/Xv.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/Xext/Xv/Xv.c	Tue Feb 07 09:29:18 2006 +0000
@@ -234,7 +234,7 @@
           SyncHandle();
 	  return(XvBadAlloc);
 	}
-      (void)SDL_strncpy(name, u.string, size);
+      (void)strncpy(name, u.string, size);
       name[size] = '\0';
       pa->name = name;
 
@@ -386,7 +386,7 @@
           SyncHandle();
 	  return(XvBadAlloc);
       }
-      SDL_strncpy(name, u.string, size);
+      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;	      
-	      SDL_memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16);
+	      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;
-	      SDL_memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32);
+	      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	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/Xext/Xxf86dga/XF86DGA.c	Tue Feb 07 09:29:18 2006 +0000
@@ -407,12 +407,12 @@
     MapPtr *old;
 
     old = mapList;
-    mapList = SDL_realloc(mapList, sizeof(MapPtr) * (numMaps + 1));
+    mapList = realloc(mapList, sizeof(MapPtr) * (numMaps + 1));
     if (!mapList) {
 	mapList = old;
 	return NULL;
     }
-    mapList[numMaps] = SDL_malloc(sizeof(MapRec));
+    mapList[numMaps] = malloc(sizeof(MapRec));
     if (!mapList[numMaps])
 	return NULL;
     return mapList[numMaps++];
@@ -424,12 +424,12 @@
     ScrPtr *old;
 
     old = scrList;
-    scrList = SDL_realloc(scrList, sizeof(ScrPtr) * (numScrs + 1));
+    scrList = realloc(scrList, sizeof(ScrPtr) * (numScrs + 1));
     if (!scrList) {
 	scrList = old;
 	return NULL;
     }
-    scrList[numScrs] = SDL_malloc(sizeof(ScrRec));
+    scrList[numScrs] = malloc(sizeof(ScrRec));
     if (!scrList[numScrs])
 	return NULL;
     return scrList[numScrs++];
--- a/src/video/aalib/SDL_aavideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/aalib/SDL_aavideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,14 +23,13 @@
 /* AAlib based SDL video driver implementation.
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <unistd.h>
 #include <sys/stat.h>
 
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/ataricommon/SDL_atarievents.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ataricommon/SDL_atarievents.c	Tue Feb 07 09:29:18 2006 +0000
@@ -28,12 +28,11 @@
  *	This routines choose what the final event manager will be
  */
 
-#include <stdlib.h>
-#include <string.h>
-
 #include <mint/cookie.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_sysevents.h"
 #include "SDL_events_c.h"
 
--- a/src/video/ataricommon/SDL_atarigl.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ataricommon/SDL_atarigl.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,15 +24,14 @@
 
 /*--- Includes ---*/
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #ifdef HAVE_OPENGL
 #include <GL/osmesa.h>
 #endif
 
 #include <mint/osbind.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_video.h"
 #include "SDL_error.h"
 #include "SDL_endian.h"
--- a/src/video/ataricommon/SDL_xbiosevents.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ataricommon/SDL_xbiosevents.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,10 +26,6 @@
  *	Patrice Mandin
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include <mint/osbind.h>
 
 #include "SDL_events_c.h"
--- a/src/video/bwindow/SDL_sysmouse.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/bwindow/SDL_sysmouse.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -20,12 +20,11 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <string.h>
-
 #include <AppKit.h>
 #include <GameKit.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_BWin.h"
 
--- a/src/video/bwindow/SDL_sysvideo.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/bwindow/SDL_sysvideo.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -22,13 +22,11 @@
 
 /* BWindow based framebuffer implementation */
 
-#include <stdlib.h>
-#include <string.h>
-
-#include <stdio.h>
 #include <unistd.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_BeApp.h"
 #include "SDL_BWin.h"
 #include "SDL_timer.h"
@@ -291,7 +289,7 @@
 
 	/* Get the video modes we can switch to in fullscreen mode */
 	bscreen.GetModeList(&modes, &nmodes);
-	qsort(modes, nmodes, sizeof *modes, CompareModes);
+	SDL_qsort(modes, nmodes, sizeof *modes, CompareModes);
 	for ( i=0; i<nmodes; ++i ) {
 		bpp = ColorSpaceToBitsPerPixel(modes[i].space);
 		//if ( bpp != 0 ) { // There are bugs in changing colorspace
--- a/src/video/bwindow/SDL_sysyuv.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/bwindow/SDL_sysyuv.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -22,10 +22,7 @@
 
 /* This is the BeOS version of SDL YUV video overlays */
 
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_sysyuv.h"
@@ -158,7 +155,7 @@
 	}
 
     /* Create the overlay structure */
-    overlay = (SDL_Overlay*)calloc(1, sizeof(SDL_Overlay));
+    overlay = (SDL_Overlay*)SDL_calloc(1, sizeof(SDL_Overlay));
 
     if (overlay == NULL)
     {
@@ -176,7 +173,7 @@
     overlay->hwfuncs = &be_yuvfuncs;
 
     /* Create the pixel data and lookup tables */
-    hwdata = (struct private_yuvhwdata*)calloc(1, sizeof(struct private_yuvhwdata));
+    hwdata = (struct private_yuvhwdata*)SDL_calloc(1, sizeof(struct private_yuvhwdata));
 
     if (hwdata == NULL)
     {
@@ -215,8 +212,8 @@
 	overlay->hwdata->bbitmap = bbitmap;
 	
 	overlay->planes = planes;
-	overlay->pitches = (Uint16*)calloc(overlay->planes, sizeof(Uint16));
-	overlay->pixels  = (Uint8**)calloc(overlay->planes, sizeof(Uint8*));
+	overlay->pitches = (Uint16*)SDL_calloc(overlay->planes, sizeof(Uint16));
+	overlay->pixels  = (Uint8**)SDL_calloc(overlay->planes, sizeof(Uint8*));
 	if (!overlay->pitches || !overlay->pixels)
 	{
         SDL_OutOfMemory();
--- a/src/video/cybergfx/SDL_cgximage.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/cybergfx/SDL_cgximage.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,8 +20,8 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_endian.h"
 #include "SDL_cgximage_c.h"
--- a/src/video/cybergfx/SDL_cgxmodes.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxmodes.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,11 +22,6 @@
 
 /* Utilities for getting and setting the X display mode */
 
-/*
-#include <stdlib.h>
-#include <string.h>
-*/
-
 #include "SDL_timer.h"
 #include "SDL_error.h"
 #include "SDL_events.h"
--- a/src/video/cybergfx/SDL_cgxvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,18 +25,6 @@
  * gabriele.greco@aruba.it
  */
 
-/*
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#ifdef MTRR_SUPPORT
-#include <asm/mtrr.h>
-#include <sys/fcntl.h>
-#endif
-*/
-
 #include "SDL.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
--- a/src/video/cybergfx/SDL_cgxvideo.h	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxvideo.h	Tue Feb 07 09:29:18 2006 +0000
@@ -24,10 +24,6 @@
 #define _SDL_cgxvideo_h
 
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include <exec/exec.h>
 #include <cybergraphx/cybergraphics.h>
 #include <graphics/scale.h>
@@ -47,9 +43,11 @@
 #include <inline/console.h>
 #endif
 
-#include "mydebug.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_mouse.h"
 #include "SDL_sysvideo.h"
+#include "mydebug.h"
 
 #define USE_CGX_WRITELUTPIXEL
 
--- a/src/video/cybergfx/SDL_cgxyuv.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/cybergfx/SDL_cgxyuv.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,14 +24,14 @@
 
 #ifdef XFREE86_XV
 
-#include <stdlib.h>
-#include <string.h>
 #include <X11/Xlib.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include <X11/extensions/XShm.h>
 #include <X11/extensions/Xvlib.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_x11yuv_c.h"
--- a/src/video/dc/SDL_dcvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/dc/SDL_dcvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,11 +20,9 @@
     slouken@libsdl.org
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/dga/SDL_dgavideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/dga/SDL_dgavideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,16 +23,14 @@
 /* DGA 2.0 based SDL video driver implementation.
 */
 
-#include <stdlib.h>
-#include <string.h>
+#include <stdio.h>
+
 #include <X11/Xlib.h>
 #include <Xext/extensions/xf86dga.h>
 
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
@@ -390,7 +388,7 @@
 
 	/* Query for the list of available video modes */
 	modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
-	qsort(modes, num_modes, sizeof *modes, cmpmodes);
+	SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
 	for ( i=0; i<num_modes; ++i ) {
 #ifdef DGA_DEBUG
 		PrintMode(&modes[i]);
@@ -449,7 +447,7 @@
 
 	/* Search for a matching video mode */
 	modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
-	qsort(modes, num_modes, sizeof *modes, cmpmodes);
+	SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
 	for ( i=0; i<num_modes; ++i ) {
 		int depth;
 
@@ -968,7 +966,7 @@
 	if ( ! DGA_colormap ) {
 		return(0);
 	}
-	xcmap = (XColor *)alloca(ncolors*sizeof(*xcmap));
+	xcmap = SDL_stack_alloc(XColor, ncolors);
 	for ( i=0; i<ncolors; ++i ) {
 		xcmap[i].pixel = firstcolor + i;
 		xcmap[i].red   = (colors[i].r<<8)|colors[i].r;
@@ -980,6 +978,7 @@
 	pXStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
 	pXSync(DGA_Display, False);
 	UNLOCK_DISPLAY();
+	SDL_stack_free(xcmap);
 
 	/* That was easy. :) */
 	return(1);
--- a/src/video/directfb/SDL_DirectFB_events.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_events.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,8 +24,6 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <termios.h>
--- a/src/video/directfb/SDL_DirectFB_video.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_video.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,9 +27,6 @@
 /* DirectFB video driver implementation.
 */
 
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
@@ -38,6 +35,8 @@
 #include <directfb_version.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
@@ -110,7 +109,7 @@
   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));
     }
   if (device == NULL  ||  device->hidden == NULL)
@@ -122,7 +121,7 @@
         }
       return(0);
     }
-  memset (device->hidden, 0, sizeof (*device->hidden));
+  SDL_memset (device->hidden, 0, sizeof (*device->hidden));
 
   /* Set the function pointers */
   device->VideoInit = DirectFB_VideoInit;
@@ -195,7 +194,7 @@
 
   HIDDEN->nummodes++;
 
-  enumrect = calloc(1, sizeof(struct DirectFBEnumRect));
+  enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect));
   if (!enumrect)
     {
       SDL_OutOfMemory();
@@ -294,14 +293,14 @@
   SDL_Palette *palette;
   SDL_Color   *colors;
 
-  palette = calloc (1, sizeof(SDL_Palette));
+  palette = SDL_calloc (1, sizeof(SDL_Palette));
   if (!palette)
     {
       SDL_OutOfMemory();
       return NULL;
     }
 
-  colors = calloc (size, sizeof(SDL_Color));
+  colors = SDL_calloc (size, sizeof(SDL_Color));
   if (!colors)
     {
       SDL_OutOfMemory();
@@ -432,7 +431,7 @@
       goto error;
     }
 
-  HIDDEN->modelist = calloc (HIDDEN->nummodes + 1, sizeof(SDL_Rect *));
+  HIDDEN->modelist = SDL_calloc (HIDDEN->nummodes + 1, sizeof(SDL_Rect *));
   if (!HIDDEN->modelist)
     {
       SDL_OutOfMemory();
@@ -614,7 +613,7 @@
   else if (!current->hwdata)
     {
       /* Allocate the hardware acceleration data */
-      current->hwdata = (struct private_hwdata *) calloc (1, sizeof(*current->hwdata));
+      current->hwdata = (struct private_hwdata *) SDL_calloc (1, sizeof(*current->hwdata));
       if (!current->hwdata)
         {
           SDL_OutOfMemory();
@@ -821,7 +820,7 @@
     return -1;
 
   /* Allocate the hardware acceleration data */
-  surface->hwdata = (struct private_hwdata *) calloc (1, sizeof(*surface->hwdata));
+  surface->hwdata = (struct private_hwdata *) SDL_calloc (1, sizeof(*surface->hwdata));
   if (surface->hwdata == NULL)
     {
       SDL_OutOfMemory();
--- a/src/video/directfb/SDL_DirectFB_yuv.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/directfb/SDL_DirectFB_yuv.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,7 @@
 
 /* This is the DirectFB implementation of YUV video overlays */
 
-#include <stdlib.h>
-#include <string.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_DirectFB_yuv.h"
@@ -148,7 +146,7 @@
   struct private_yuvhwdata *hwdata;
 
   /* Create the overlay structure */
-  overlay = calloc (1, sizeof(SDL_Overlay));
+  overlay = SDL_calloc (1, sizeof(SDL_Overlay));
   if (!overlay)
     {
       SDL_OutOfMemory();
@@ -164,7 +162,7 @@
   overlay->hwfuncs = &directfb_yuvfuncs;
 
   /* Create the pixel data and lookup tables */
-  hwdata = calloc(1, sizeof(struct private_yuvhwdata));
+  hwdata = SDL_calloc(1, sizeof(struct private_yuvhwdata));
   overlay->hwdata = hwdata;
   if (!hwdata)
     {
--- a/src/video/dummy/SDL_nullvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/dummy/SDL_nullvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -35,11 +35,9 @@
  *  SDL video driver.  Renamed to "DUMMY" by Sam Lantinga.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
@@ -145,7 +143,9 @@
 
 int DUMMY_VideoInit(_THIS, SDL_PixelFormat *vformat)
 {
+	/*
 	fprintf(stderr, "WARNING: You are using the SDL dummy video driver!\n");
+	*/
 
 	/* Determine the screen depth (use default 8-bit depth) */
 	/* we change this during the SDL_SetVideoMode implementation... */
--- a/src/video/epoc/SDL_epocvideo.cpp	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/epoc/SDL_epocvideo.cpp	Tue Feb 07 09:29:18 2006 +0000
@@ -29,11 +29,9 @@
 
 
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
 extern "C" {
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_video.h"
--- a/src/video/fbcon/SDL_fbelo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/fbcon/SDL_fbelo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,12 +20,12 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
 #include <unistd.h>
 #include <sys/time.h>
 #include <ctype.h>
-#include <string.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_fbvideo.h"
 #include "SDL_fbelo.h"
 
--- a/src/video/fbcon/SDL_fbevents.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/fbcon/SDL_fbevents.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,14 +22,12 @@
 
 /* Handle the event stream, converting console events into SDL events */
 
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/ioctl.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <string.h>
 #include <errno.h>
 #include <limits.h>
 
@@ -42,6 +40,8 @@
 #include <linux/keyboard.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_mutex.h"
 #include "SDL_sysevents.h"
 #include "SDL_sysvideo.h"
@@ -260,7 +260,7 @@
 			for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) {
 				char vtpath[12];
 
-				sprintf(vtpath, vcs[i], current_vt);
+				SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], current_vt);
 				keyboard_fd = open(vtpath, O_RDWR, 0);
 #ifdef DEBUG_KEYBOARD
 				fprintf(stderr, "vtpath = %s, fd = %d\n",
@@ -345,7 +345,7 @@
 			char path[PATH_MAX];
 			char name[PATH_MAX];
 
-			sprintf(path, "/proc/%s/status", entry->d_name);
+			SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name);
 			status=fopen(path, "r");
 			if ( status ) {
 				name[0] = '\0';
@@ -379,7 +379,7 @@
 	proc = opendir("/proc");
 	if ( proc ) {
 		while ( (pid=find_pid(proc, "gpm")) > 0 ) {
-			sprintf(path, "/proc/%d/cmdline", pid);
+			SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
 			cmdline = open(path, O_RDONLY, 0);
 			if ( cmdline >= 0 ) {
 				len = read(cmdline, args, sizeof(args));
--- a/src/video/fbcon/SDL_fbvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/fbcon/SDL_fbvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,16 +23,17 @@
 /* Framebuffer console based SDL video driver implementation.
 */
 
-#include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <asm/page.h>		/* For definition of PAGE_SIZE */
+#include <sys/io.h>		/* For ioperm() */
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
@@ -53,10 +54,12 @@
 #ifndef FB_AUX_VGA_PLANES_VGA4
 #define FB_AUX_VGA_PLANES_VGA4	0
 #endif
+/*
 static inline void outb (unsigned char value, unsigned short port)
 {
   __asm__ __volatile__ ("outb %b0,%w1"::"a" (value), "Nd" (port));
 } 
+*/
 #endif /* FB_TYPE_VGA_PLANES */
 
 /* A list of video resolutions that we query for (sorted largest to smallest) */
@@ -438,7 +441,7 @@
 	int i;
 	for ( i=0; i<NUM_MODELISTS; ++i ) {
 		if ( SDL_nummodes[i] > 0 ) {
-			qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
+			SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
 		}
 	}
 }
--- a/src/video/gapi/SDL_gapivideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/gapi/SDL_gapivideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -32,11 +32,8 @@
 // TODO: windib on SH3 PPC2000 landscape test
 // TODO: optimize 8bpp landscape mode
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
@@ -479,7 +476,7 @@
 	/* Sort the mode lists */
 	for ( i=0; i<NUM_MODELISTS; ++i ) {
 		if ( gapi->SDL_nummodes[i] > 0 ) {
-			qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i], sizeof *gapi->SDL_modelist[i], cmpmodes);
+			SDL_qsort(gapi->SDL_modelist[i], gapi->SDL_nummodes[i], sizeof *gapi->SDL_modelist[i], cmpmodes);
 		}
 	}
 
--- a/src/video/gem/SDL_gemmouse.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/gem/SDL_gemmouse.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,10 +26,9 @@
  *	Patrice Mandin
  */
 
-#include <stdlib.h>
-
 #include <gem.h>
 
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_mouse.h"
 #include "SDL_events_c.h"
--- a/src/video/gem/SDL_gemvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/gem/SDL_gemvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -28,10 +28,6 @@
 	Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 /* Mint includes */
 #include <gem.h>
 #include <gemx.h>
@@ -39,6 +35,8 @@
 #include <mint/cookie.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/ggi/SDL_ggievents.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ggi/SDL_ggievents.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,8 +24,6 @@
 
 #include <sys/types.h>
 #include <sys/time.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <termios.h>
--- a/src/video/ggi/SDL_ggivideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ggi/SDL_ggivideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,8 +23,6 @@
 /* GGI-based SDL video driver implementation.
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
@@ -33,6 +31,8 @@
 #include <ggi/gii.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/ipod/SDL_ipodvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ipod/SDL_ipodvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -1,8 +1,6 @@
 #include <sys/types.h>
 #include <sys/ioctl.h>
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
@@ -15,6 +13,8 @@
 #include <linux/fb.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
@@ -93,15 +93,15 @@
 {
     SDL_VideoDevice *this;
     
-    this = (SDL_VideoDevice *)malloc (sizeof(SDL_VideoDevice));
+    this = (SDL_VideoDevice *)SDL_malloc (sizeof(SDL_VideoDevice));
     if (this) {
 	memset (this, 0, sizeof *this);
-	this->hidden = (struct SDL_PrivateVideoData *) malloc (sizeof(struct SDL_PrivateVideoData));
+	this->hidden = (struct SDL_PrivateVideoData *) SDL_malloc (sizeof(struct SDL_PrivateVideoData));
     }
     if (!this || !this->hidden) {
 	SDL_OutOfMemory();
 	if (this)
-	    free (this);
+	    SDL_free (this);
 	return 0;
     }
     memset (this->hidden, 0, sizeof(struct SDL_PrivateVideoData));
@@ -178,7 +178,7 @@
 	    for ( i=0; vcs[i] && (kbfd < 0); ++i ) {
 		char vtpath[12];
 		
-		sprintf(vtpath, vcs[i], curvt);
+		SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], curvt);
 		kbfd = open(vtpath, O_RDWR);
 	    }
 	}
@@ -320,8 +320,8 @@
 	Rmask = Gmask = Bmask = 0;
     }
 
-    if (this->hidden->buffer) free (this->hidden->buffer);
-    this->hidden->buffer = malloc (width * height * (bpp / 8));
+    if (this->hidden->buffer) SDL_free (this->hidden->buffer);
+    this->hidden->buffer = SDL_malloc (width * height * (bpp / 8));
     if (!this->hidden->buffer) {
 	SDL_SetError ("Couldn't allocate buffer for requested mode");
 	return 0;
@@ -331,7 +331,7 @@
 
     if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, 0)) {
 	SDL_SetError ("Couldn't allocate new pixel format");
-	free (this->hidden->buffer);
+	SDL_free (this->hidden->buffer);
 	this->hidden->buffer = 0;
 	return 0;
     }
--- a/src/video/maccommon/SDL_macmouse.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/maccommon/SDL_macmouse.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,8 +20,6 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #if defined(__APPLE__) && defined(__MACH__)
 #include <Carbon/Carbon.h>
 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
@@ -35,6 +33,8 @@
 #include <CursorDevices.h>
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_mouse.h"
 #include "SDL_macmouse_c.h"
--- a/src/video/maccommon/SDL_macwm.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/maccommon/SDL_macwm.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,9 +20,6 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <string.h>
-
 #if defined(__APPLE__) && defined(__MACH__)
 #include <Carbon/Carbon.h>
 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
@@ -32,6 +29,7 @@
 #include <Strings.h>
 #endif
 
+#include "SDL_string.h"
 #include "SDL_macwm_c.h"
 
 void Mac_SetCaption(_THIS, const char *title, const char *icon)
--- a/src/video/macdsp/SDL_dspvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/macdsp/SDL_dspvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -122,9 +122,6 @@
 #define DSP_NO_SYNC_OPENGL
 
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #if defined(__APPLE__) && defined(__MACH__)
 #include <Carbon/Carbon.h>
 #include <DrawSprocket/DrawSprocket.h>
@@ -140,6 +137,8 @@
 #include <DrawSprocket.h>
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_video.h"
 #include "SDL_blit.h"
 #include "SDL_error.h"
@@ -265,7 +264,7 @@
 		if ( device ) {
 			
 			if (device->hidden)
-		        free (device->hidden);			
+				SDL_free(device->hidden);			
 			
 			SDL_free(device);
 		}
@@ -390,14 +389,14 @@
 done:
 	i++;          /* i was not incremented before kicking out of the loop */
 	
-	mode_list = (SDL_Rect**) malloc (sizeof (SDL_Rect*) * (i+1));
+	mode_list = (SDL_Rect**) SDL_malloc (sizeof (SDL_Rect*) * (i+1));
 	if (mode_list) {
 	
 	   /* -dw- new stuff: build in reverse order so largest sizes list first */
 		for (j = i-1; j >= 0; j--) {
-			mode_list [j] = (SDL_Rect*) malloc (sizeof (SDL_Rect));	
+			mode_list [j] = (SDL_Rect*) SDL_malloc (sizeof (SDL_Rect));	
 			if (mode_list [j])
-				memcpy (mode_list [j], &(temp_list [j]), sizeof (SDL_Rect));
+				SDL_memcpy (mode_list [j], &(temp_list [j]), sizeof (SDL_Rect));
 			else {
 				SDL_OutOfMemory ();
 				return NULL;
@@ -475,7 +474,7 @@
 	  return 0;
 	}
 		
-	memset (&attrib, 0, sizeof (DSpContextAttributes));
+	SDL_memset (&attrib, 0, sizeof (DSpContextAttributes));
 
 	/* These attributes are hopefully supported on all devices...*/
 	attrib.displayWidth         = 640;
@@ -657,7 +656,7 @@
 		fmt = "Hardware surface could not be allocated in %s - unknown error";
 		break;
 	}
-	sprintf(message, fmt, mem);
+	SDL_snprintf(message, SDL_arraysize(message), fmt, mem);
 	SDL_SetError(message);
 }
 #endif // TARGET_API_MAC_OSX
@@ -735,7 +734,7 @@
 		   DisposeGWorld (dsp_back_buffer);
 		
 		if (current->hwdata)
-		   free (current->hwdata);
+		   SDL_free(current->hwdata);
 		   
 		DSpContext_SetState (dsp_context, kDSpContextState_Inactive );
 		DSpContext_Release  (dsp_context);
@@ -788,7 +787,7 @@
 		page_count = 1;
 	}
 
-	memset (&attrib, 0, sizeof (DSpContextAttributes));
+	SDL_memset (&attrib, 0, sizeof (DSpContextAttributes));
 	attrib.displayWidth         = width;
 	attrib.displayHeight        = height;
 	attrib.displayBestDepth     = bpp;
@@ -867,7 +866,7 @@
 		/* single-buffer context */
 		DSpContext_GetFrontBuffer (dsp_context, &dsp_back_buffer);
 			
-		current->hwdata   = (private_hwdata*) malloc (sizeof (private_hwdata));
+		current->hwdata   = (private_hwdata*) SDL_malloc (sizeof (private_hwdata));
 		if (current ->hwdata == NULL) {
 			SDL_OutOfMemory ();
 	  		return NULL;		  
@@ -885,13 +884,13 @@
 	} 
 	else if ( DSp_NewHWSurface(this, &dsp_back_buffer, bpp, width-1, height-1) == 0 ) {
       
-      current->hwdata = (private_hwdata*) malloc (sizeof (private_hwdata));
+      current->hwdata = (private_hwdata*) SDL_malloc (sizeof (private_hwdata));
       if (current ->hwdata == NULL) {
       	SDL_OutOfMemory ();
       	return NULL;		  
       }
       
-      memset (current->hwdata, 0, sizeof (private_hwdata));
+      SDL_memset (current->hwdata, 0, sizeof (private_hwdata));
       current->hwdata->offscreen = dsp_back_buffer;
       current->flags |= SDL_DOUBLEBUF | SDL_HWSURFACE; 
       this->UpdateRects = DSp_DirectUpdate; /* hardware doesn't do update rects, must be page-flipped */	   
@@ -1084,13 +1083,13 @@
 	if ( DSp_NewHWSurface (this, &temp, surface->format->BitsPerPixel, surface->w, surface->h) < 0 )
 	   return (-1);
 			
-	surface->hwdata = (private_hwdata*) malloc (sizeof (private_hwdata));
+	surface->hwdata = (private_hwdata*) SDL_malloc (sizeof (private_hwdata));
 	if (surface->hwdata == NULL) {
 		SDL_OutOfMemory ();
 		return -1;
 	}
 	
-	memset (surface->hwdata, 0, sizeof(private_hwdata));
+	SDL_memset (surface->hwdata, 0, sizeof(private_hwdata));
 	surface->hwdata->offscreen = temp;
 	surface->pitch	 = GetPixRowBytes (GetPortPixMap (temp)) & 0x3FFF;
 	surface->pixels  = GetPixBaseAddr (GetPortPixMap (temp));
@@ -1105,7 +1104,7 @@
 {	
 	if (surface->hwdata->offscreen != NULL)
 		DisposeGWorld (surface->hwdata->offscreen);
-	free (surface->hwdata);
+	SDL_free(surface->hwdata);
 
     surface->pixels = NULL;
 }
--- a/src/video/macrom/SDL_romvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/macrom/SDL_romvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,9 +20,6 @@
     slouken@libsdl.org
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #if defined(__APPLE__) && defined(__MACH__)
 #include <Carbon/Carbon.h>
 #if USE_QUICKTIME
@@ -44,6 +41,8 @@
 #include <QDOffscreen.h>
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_video.h"
 #include "SDL_error.h"
 #include "SDL_syswm.h"
--- a/src/video/nanox/SDL_nximage.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/nanox/SDL_nximage.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,9 +25,8 @@
     clare@setabox.com
 */
 
-#include <stdlib.h>
-#include <string.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 
 #include "SDL_nximage_c.h"
@@ -106,7 +105,7 @@
         else
         {
             for (j = h; j > 0; -- j, src += yinc, dest += destinc)
-                memcpy (dest, src, rowinc) ;
+                SDL_memcpy (dest, src, rowinc) ;
         }
         if (!Clientfb) {
             if (currently_fullscreen) {
@@ -128,13 +127,13 @@
     
     Dprintf ("enter NX_SetupImage\n") ;
 
-    screen -> pixels = (void *) malloc (size) ;
+    screen -> pixels = (void *) SDL_malloc (size) ;
 
     if (!Clientfb) {
-        Image_buff = (unsigned char *) malloc (size) ;
+        Image_buff = (unsigned char *) SDL_malloc (size) ;
         if (screen -> pixels == NULL || Image_buff == NULL) {
-            free (screen -> pixels) ;
-            free (Image_buff) ;
+            SDL_free (screen -> pixels) ;
+            SDL_free (Image_buff) ;
             SDL_OutOfMemory () ;
             return -1 ;
         }
@@ -152,8 +151,8 @@
 {
     Dprintf ("enter NX_DestroyImage\n") ;
     
-    if (SDL_Image) free (SDL_Image) ;
-    if (Image_buff) free (Image_buff) ;
+    if (SDL_Image) SDL_free (SDL_Image) ;
+    if (Image_buff) SDL_free (Image_buff) ;
     if (screen) screen -> pixels = NULL ;
     
     Dprintf ("leave NX_DestroyImage\n") ;
@@ -215,7 +214,7 @@
         rowinc = xinc * this -> screen -> w;
 
         for (j = this -> screen -> h; j > 0; -- j, src += yinc, dest += fbinfo.pitch)
-            memcpy (dest, src, rowinc) ;
+            SDL_memcpy (dest, src, rowinc) ;
     }
     else
 #endif
--- a/src/video/nanox/SDL_nxmodes.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/nanox/SDL_nxmodes.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,8 +24,8 @@
     clare@setabox.com
 */
 
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_nxmodes_c.h"
 
 SDL_Rect ** NX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
@@ -46,9 +46,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/nanox/SDL_nxmouse.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/nanox/SDL_nxmouse.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,8 +24,7 @@
     clare@setabox.com
 */
 
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_events_c.h"
 
@@ -43,7 +42,7 @@
 
     Dprintf ("enter NX_CreateWMCursor\n") ;
 
-    cursor = (WMcursor *) malloc (sizeof (WMcursor)) ;
+    cursor = (WMcursor *) SDL_malloc (sizeof (WMcursor)) ;
     if (cursor == NULL) {
         SDL_OutOfMemory () ;
         return NULL ;
@@ -56,7 +55,7 @@
 void NX_FreeWMCursor (_THIS, WMcursor * cursor)
 {
     Dprintf ("NX_FreeWMCursor\n") ;
-    free (cursor) ;
+    SDL_free (cursor) ;
     return ;
 }
 
--- a/src/video/nanox/SDL_nxvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/nanox/SDL_nxvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,9 +25,8 @@
     clare@setabox.com
 */
 
-#include <stdlib.h>
-#include <string.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_video.h"
 #include "SDL_pixels_c.h"
 #include "SDL_events_c.h"
@@ -84,11 +83,11 @@
     Dprintf ("enter NX_CreateDevice\n") ;
 
     // 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 = NULL ;
     }
     if ((device == NULL) || (device -> hidden == NULL)) {
@@ -96,7 +95,7 @@
         NX_DeleteDevice (device) ;
         return 0 ;
     }
-    memset (device -> hidden, 0, (sizeof * device -> hidden)) ;
+    SDL_memset (device -> hidden, 0, (sizeof * device -> hidden)) ;
 
     // Set the function pointers
     device -> VideoInit = NX_VideoInit ;
@@ -212,9 +211,9 @@
     SDL_Visual.bpp = si.bpp ;
 
     // GetVideoMode
-    SDL_modelist = (SDL_Rect **) malloc (sizeof (SDL_Rect *) * 2) ;
+    SDL_modelist = (SDL_Rect **) SDL_malloc (sizeof (SDL_Rect *) * 2) ;
     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 ;
@@ -486,9 +485,9 @@
     
     if (SDL_Visual.bpp != 32 && SDL_Visual.bpp != 24) return -1 ;
 
-    if (! GammaRamp_R) GammaRamp_R = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
-    if (! GammaRamp_G) GammaRamp_G = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
-    if (! GammaRamp_B) GammaRamp_B = (Uint16 *) malloc (sizeof (Uint16) * CI_SIZE) ;
+    if (! GammaRamp_R) GammaRamp_R = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ;
+    if (! GammaRamp_G) GammaRamp_G = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ;
+    if (! GammaRamp_B) GammaRamp_B = (Uint16 *) SDL_malloc (sizeof (Uint16) * CI_SIZE) ;
     if ((! GammaRamp_R) || (! GammaRamp_G) || (! GammaRamp_B)) {
         SDL_OutOfMemory () ;
         return -1 ;
--- a/src/video/nanox/SDL_nxwm.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/nanox/SDL_nxwm.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,8 +24,6 @@
     clare@setabox.com
 */
 
-#include <stdlib.h>
-
 #include "SDL_syswm.h"
 #include "SDL_error.h"
 #include "SDL_events_c.h"
--- a/src/video/os2fslib/SDL_os2fslib.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/os2fslib/SDL_os2fslib.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,13 +20,12 @@
     slouken@libsdl.org
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <process.h>
 #include <time.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/photon/SDL_ph_image.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/photon/SDL_ph_image.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,12 +20,12 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-
 #include <Ph.h>
 #include <photon/Pg.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_endian.h"
 #include "SDL_video.h"
--- a/src/video/photon/SDL_ph_modes.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/photon/SDL_ph_modes.c	Tue Feb 07 09:29:18 2006 +0000
@@ -173,7 +173,7 @@
         return -1;
     }
 
-    qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
+    SDL_qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
 
     for(i=0;i<mode_list.num_modes;i++)
     {
--- a/src/video/photon/SDL_ph_mouse.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/photon/SDL_ph_mouse.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,10 +20,8 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_mouse.h"
 #include "SDL_events_c.h"
--- a/src/video/photon/SDL_ph_video.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/photon/SDL_ph_video.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,13 +20,12 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
-#include <string.h>
 #include <sys/ioctl.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_thread.h"
--- a/src/video/photon/SDL_ph_wm.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/photon/SDL_ph_wm.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,13 +22,13 @@
 
 #define DISABLE_X11
 
-#include <stdlib.h>
-#include <string.h>
 #include <Ph.h>
 #include <photon/PpProto.h>
 #include <photon/PhWm.h>
 #include <photon/wmapi.h>
+
 #include "SDL_version.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_video.h"
--- a/src/video/photon/SDL_phyuv.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/photon/SDL_phyuv.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,13 +22,13 @@
 
 /* This is the QNX Realtime Platform version of SDL YUV video overlays */
 
-#include <stdlib.h>
-#include <string.h>
 #include <errno.h>
 
 #include <Ph.h>
 #include <Pt.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_phyuv_c.h"
@@ -81,7 +81,7 @@
     PhPoint_t pos;
 
     /* Create the overlay structure */
-    overlay = calloc(1, sizeof(SDL_Overlay));
+    overlay = SDL_calloc(1, sizeof(SDL_Overlay));
 
     if (overlay == NULL)
     {
@@ -99,7 +99,7 @@
     overlay->hwfuncs = &ph_yuvfuncs;
 
     /* Create the pixel data and lookup tables */
-    hwdata = calloc(1, sizeof(struct private_yuvhwdata));
+    hwdata = SDL_calloc(1, sizeof(struct private_yuvhwdata));
 
     if (hwdata == NULL)
     {
@@ -132,8 +132,8 @@
     overlay->hwdata->CurrentViewPort.size.w = width;
     overlay->hwdata->CurrentViewPort.size.h = height;
     overlay->hwdata->State = OVERLAY_STATE_UNINIT;
-    overlay->hwdata->FrameData0 = (FRAMEDATA *) calloc(1, sizeof(FRAMEDATA));
-    overlay->hwdata->FrameData1 = (FRAMEDATA *) calloc(1, sizeof(FRAMEDATA));
+    overlay->hwdata->FrameData0 = (FRAMEDATA *) SDL_calloc(1, sizeof(FRAMEDATA));
+    overlay->hwdata->FrameData1 = (FRAMEDATA *) SDL_calloc(1, sizeof(FRAMEDATA));
 
     vidport = -1;
     i=0;
@@ -246,8 +246,8 @@
 
     /* Find the pitch and offset values for the overlay */
     overlay->planes = planes;
-    overlay->pitches = calloc(overlay->planes, sizeof(Uint16));
-    overlay->pixels  = calloc(overlay->planes, sizeof(Uint8*));
+    overlay->pitches = SDL_calloc(overlay->planes, sizeof(Uint16));
+    overlay->pixels  = SDL_calloc(overlay->planes, sizeof(Uint8*));
     if (!overlay->pitches || !overlay->pixels)
     {
         SDL_OutOfMemory();
--- a/src/video/picogui/SDL_pgvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/picogui/SDL_pgvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,11 +23,9 @@
     micahjd@users.sourceforge.net
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/ps2gs/SDL_gsevents.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ps2gs/SDL_gsevents.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,11 +25,8 @@
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/ioctl.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <string.h>
 #include <errno.h>
 #include <limits.h>
 
@@ -42,6 +39,7 @@
 #include <linux/keyboard.h>
 
 #include "SDL.h"
+#include "SDL_string.h"
 #include "SDL_mutex.h"
 #include "SDL_sysevents.h"
 #include "SDL_sysvideo.h"
@@ -257,7 +255,7 @@
 			for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) {
 				char vtpath[12];
 
-				sprintf(vtpath, vcs[i], current_vt);
+				SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], current_vt);
 				keyboard_fd = open(vtpath, O_RDWR, 0);
 #ifdef DEBUG_KEYBOARD
 				fprintf(stderr, "vtpath = %s, fd = %d\n",
@@ -333,7 +331,7 @@
 			char path[PATH_MAX];
 			char name[PATH_MAX];
 
-			sprintf(path, "/proc/%s/status", entry->d_name);
+			SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name);
 			status=fopen(path, "r");
 			if ( status ) {
 				name[0] = '\0';
@@ -367,7 +365,7 @@
 	proc = opendir("/proc");
 	if ( proc ) {
 		while ( (pid=find_pid(proc, "gpm")) > 0 ) {
-			sprintf(path, "/proc/%d/cmdline", pid);
+			SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
 			cmdline = open(path, O_RDONLY, 0);
 			if ( cmdline >= 0 ) {
 				len = read(cmdline, args, sizeof(args));
--- a/src/video/ps2gs/SDL_gsmouse.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ps2gs/SDL_gsmouse.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,8 +20,6 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <sys/ioctl.h>
 
 #include "SDL_error.h"
--- a/src/video/ps2gs/SDL_gsvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ps2gs/SDL_gsvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,14 +23,14 @@
 /* Framebuffer console based SDL video driver implementation.
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/ps2gs/SDL_gsyuv.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/ps2gs/SDL_gsyuv.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,14 +22,14 @@
 
 /* This is the Playstation 2 implementation of YUV video overlays */
 
-#include <stdlib.h>
-#include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <asm/page.h>		/* For definition of PAGE_SIZE */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_gsyuv_c.h"
--- a/src/video/qtopia/SDL_sysmouse.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/qtopia/SDL_sysmouse.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -20,11 +20,6 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <string.h>
-
-
-#include "SDL_error.h"
 #include "SDL_QWin.h"
 
 extern "C" {
--- a/src/video/qtopia/SDL_sysvideo.cc	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/qtopia/SDL_sysvideo.cc	Tue Feb 07 09:29:18 2006 +0000
@@ -22,16 +22,14 @@
 
 /* Qtopia based framebuffer implementation */
 
-#include <stdlib.h>
-#include <string.h>
-
-#include <stdio.h>
 #include <unistd.h>
 
 #include <qapplication.h>
 #include <qpe/qpeapplication.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_timer.h"
 
 #include "SDL_QWin.h"
--- a/src/video/quartz/SDL_QuartzEvents.m	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/quartz/SDL_QuartzEvents.m	Tue Feb 07 09:29:18 2006 +0000
@@ -20,9 +20,9 @@
     slouken@libsdl.org
 */
 
+#include "SDL_stdlib.h"
 #include "SDL_QuartzVideo.h"
 
-#include <stdlib.h> // For getenv()
 #include <IOKit/IOMessage.h> // For wake from sleep detection
 #include <IOKit/pwr_mgt/IOPMLib.h> // For wake from sleep detection
 #include "SDL_QuartzKeys.h"
@@ -295,7 +295,7 @@
         }
     }
     
-    if (getenv ("SDL_ENABLEAPPEVENTS"))
+    if (SDL_getenv ("SDL_ENABLEAPPEVENTS"))
         [ NSApp sendEvent:event ];
 }
 
@@ -773,7 +773,7 @@
 
             switch (type) {
                 case NSLeftMouseDown:
-                    if ( getenv("SDL_HAS3BUTTONMOUSE") ) {
+                    if ( SDL_getenv("SDL_HAS3BUTTONMOUSE") ) {
                         DO_MOUSE_DOWN (SDL_BUTTON_LEFT);
                     } else {
                         if ( NSCommandKeyMask & current_mods ) {
--- a/src/video/riscos/SDL_riscosFullScreenVideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/riscos/SDL_riscosFullScreenVideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,11 +27,9 @@
      Implements RISC OS full screen display.
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
@@ -357,7 +355,7 @@
 	/* Sort the mode lists */
 	for ( j=0; j<NUM_MODELISTS; ++j ) {
 		if ( SDL_nummodes[j] > 0 ) {
-			qsort(SDL_modelist[j], SDL_nummodes[j], sizeof *SDL_modelist[j], cmpmodes);
+			SDL_qsort(SDL_modelist[j], SDL_nummodes[j], sizeof *SDL_modelist[j], cmpmodes);
 		}
 	}
 }
--- a/src/video/riscos/SDL_riscosmouse.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/riscos/SDL_riscosmouse.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,9 +27,7 @@
      Implements mouse cursor shape definitions and positioning
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_error.h"
 #include "SDL_mouse.h"
 #include "SDL_events_c.h"
--- a/src/video/riscos/SDL_riscossprite.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/riscos/SDL_riscossprite.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,9 +27,10 @@
      Implements Sprite plotting code for wimp display.window
 */
 
-#include <stdlib.h>
 #include "kernel.h"
 #include "swis.h"
+
+#include "SDL_stdlib.h"
 #include "SDL_riscosvideo.h"
 
 extern void WIMP_ReadModeInfo(_THIS);
--- a/src/video/riscos/SDL_riscostask.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/riscos/SDL_riscostask.c	Tue Feb 07 09:29:18 2006 +0000
@@ -31,12 +31,11 @@
 	  Restoring desktop after switching to full screen
 */
 
-#include <stdlib.h>
-#include <string.h>
-
 #include "kernel.h"
 #include "swis.h"
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_riscostask.h"
 
 #ifndef DISABLE_THREADS
--- a/src/video/riscos/SDL_riscosvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/riscos/SDL_riscosvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -29,11 +29,9 @@
 	 into other source files.
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_syswm.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
--- a/src/video/riscos/SDL_wimpvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/riscos/SDL_wimpvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,11 +27,9 @@
      Implements RISC OS Wimp display.
 */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/svga/SDL_svgaevents.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/svga/SDL_svgaevents.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,6 @@
 
 /* Handle the event stream, converting X11 events into SDL events */
 
-#include <stdio.h>
-#include <stdlib.h>
-
 #include <vga.h>
 #include <vgamouse.h>
 #include <vgakeyboard.h>
@@ -38,6 +35,8 @@
 #endif
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_sysevents.h"
 #include "SDL_events_c.h"
 #include "SDL_svgavideo.h"
--- a/src/video/svga/SDL_svgavideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/svga/SDL_svgavideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,8 +23,6 @@
 /* SVGAlib based SDL video driver implementation.
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -43,6 +41,8 @@
 #include <vgakeyboard.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/vgl/SDL_vglvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/vgl/SDL_vglvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,8 +25,6 @@
 
 #include <err.h>
 #include <osreldate.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
 #include <sys/stat.h>
 
@@ -36,6 +34,8 @@
 #include <vgl.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/wincommon/SDL_sysevents.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/wincommon/SDL_sysevents.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,12 +22,12 @@
 
 #include "SDL_windows.h"
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_events.h"
 #include "SDL_video.h"
 #include "SDL_error.h"
 #include "SDL_syswm.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_getenv.h"
 #include "SDL_sysevents.h"
 #include "SDL_events_c.h"
--- a/src/video/wincommon/SDL_sysmouse.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/wincommon/SDL_sysmouse.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,10 +22,10 @@
 
 #include "SDL_windows.h"
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_mouse.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysmouse_c.h"
 #include "SDL_events_c.h"
 #include "SDL_cursor_c.h"
--- a/src/video/wincommon/SDL_syswm.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/wincommon/SDL_syswm.c	Tue Feb 07 09:29:18 2006 +0000
@@ -23,11 +23,11 @@
 #include "SDL_windows.h"
 
 #include "SDL_version.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_syswm.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_syswm_c.h"
 #include "SDL_wingl_c.h"
 #include "SDL_pixels_c.h"
--- a/src/video/wincommon/SDL_wingl.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/wincommon/SDL_wingl.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,12 +22,12 @@
 
 /* WGL implementation of SDL OpenGL support */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #ifdef HAVE_OPENGL
 #include "SDL_opengl.h"
 #endif
 #include "SDL_error.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_lowvideo.h"
 #include "SDL_wingl_c.h"
 
--- a/src/video/windib/SDL_dibevents.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/windib/SDL_dibevents.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,11 +22,11 @@
 
 #include "SDL_windows.h"
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_events.h"
 #include "SDL_error.h"
 #include "SDL_syswm.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysevents.h"
 #include "SDL_events_c.h"
 #include "SDL_lowvideo.h"
--- a/src/video/windib/SDL_dibvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/windib/SDL_dibvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -35,10 +35,10 @@
 #endif
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_mutex.h"
 #include "SDL_syswm.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysvideo.h"
 #include "SDL_sysevents.h"
 #include "SDL_events_c.h"
--- a/src/video/windx5/SDL_dx5events.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/windx5/SDL_dx5events.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,12 +24,12 @@
 
 #include "directx.h"
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_events.h"
 #include "SDL_video.h"
 #include "SDL_error.h"
 #include "SDL_syswm.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysevents.h"
 #include "SDL_events_c.h"
 #include "SDL_lowvideo.h"
--- a/src/video/windx5/SDL_dx5video.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/windx5/SDL_dx5video.c	Tue Feb 07 09:29:18 2006 +0000
@@ -28,12 +28,12 @@
 #define CDS_FULLSCREEN	4
 #endif
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_events.h"
 #include "SDL_syswm.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_sysvideo.h"
 #include "SDL_blit.h"
 #include "SDL_pixels_c.h"
--- a/src/video/windx5/SDL_dx5yuv.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/windx5/SDL_dx5yuv.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,10 +22,10 @@
 
 /* This is the DirectDraw implementation of YUV video overlays */
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
-#include "SDL_stdlib.h"
-#include "SDL_string.h"
 #include "SDL_dx5yuv_c.h"
 #include "SDL_yuvfuncs.h"
 
--- a/src/video/wscons/SDL_wsconsvideo.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/wscons/SDL_wsconsvideo.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,13 +26,11 @@
 #include <dev/wscons/wsdisplay_usl_io.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/x11/SDL_x11dga.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11dga.c	Tue Feb 07 09:29:18 2006 +0000
@@ -25,7 +25,8 @@
    There will be a completely separate DGA driver that is fullscreen-only.
 */
 
-#include <stdlib.h>		/* For SDL_getenv() */
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_video.h"
 #include "SDL_cursor_c.h"
 #include "SDL_x11dga_c.h"
--- a/src/video/x11/SDL_x11events.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11events.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,6 @@
 
 /* Handle the event stream, converting X11 events into SDL events */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <setjmp.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -37,6 +34,7 @@
 #include <unistd.h>
 
 #include "SDL.h"
+#include "SDL_string.h"
 #include "SDL_syswm.h"
 #include "SDL_sysevents.h"
 #include "SDL_sysvideo.h"
--- a/src/video/x11/SDL_x11gl.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11gl.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,12 +20,11 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>	/* For SDL_getenv() prototype */
-#include <string.h>
-
-#include "SDL_events_c.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_x11video.h"
+#include "SDL_events_c.h"
 #include "SDL_x11dga_c.h"
 #include "SDL_x11gl_c.h"
 
--- a/src/video/x11/SDL_x11image.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11image.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,9 +20,11 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_endian.h"
 #include "SDL_events_c.h"
--- a/src/video/x11/SDL_x11modes.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11modes.c	Tue Feb 07 09:29:18 2006 +0000
@@ -22,9 +22,10 @@
 
 /* Utilities for getting and setting the X display mode */
 
-#include <stdlib.h>
-#include <string.h>
+#include <stdio.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_timer.h"
 #include "SDL_error.h"
 #include "SDL_events.h"
@@ -359,7 +360,7 @@
         }
 #endif
 
-        qsort(modes, nmodes, sizeof *modes, cmpmodes);
+        SDL_qsort(modes, nmodes, sizeof *modes, cmpmodes);
         SDL_modelist = (SDL_Rect **)SDL_malloc((nmodes+2)*sizeof(SDL_Rect *));
         if ( SDL_modelist ) {
             n = 0;
--- a/src/video/x11/SDL_x11mouse.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11mouse.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,13 +20,11 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_mouse.h"
 #include "SDL_events_c.h"
--- a/src/video/x11/SDL_x11video.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11video.c	Tue Feb 07 09:29:18 2006 +0000
@@ -27,29 +27,16 @@
           if full locking is neccessary, take a look at XInitThreads().
 */
 
-#include <stdlib.h>
-#include <stdio.h>
 #include <unistd.h>
-#include <string.h>
 #include <sys/ioctl.h>
 #ifdef MTRR_SUPPORT
 #include <asm/mtrr.h>
 #include <sys/fcntl.h>
 #endif
 
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
-
-#ifdef HAVE_ALLOCA
-#define ALLOCA(n) ((void*)alloca(n))
-#define FREEA(p)
-#else
-#define ALLOCA(n) SDL_malloc(n)
-#define FREEA(p) SDL_free(p)
-#endif
-
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_thread.h"
@@ -299,9 +286,9 @@
 	/* Next look at the application's executable name */
 #if defined(linux) || defined(__FreeBSD__)
 #if defined(linux)
-	sprintf(procfile, "/proc/%d/exe", getpid());
+	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
 #elif defined(__FreeBSD__)
-	sprintf(procfile, "/proc/%d/file", getpid());
+	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
 #else
 #error Where can we find the executable name?
 #endif
@@ -1215,7 +1202,7 @@
 	        /* private writable colormap: just set the colours we need */
 	        XColor  *xcmap;
 		int i;
-	        xcmap = ALLOCA(ncolors*sizeof(*xcmap));
+	        xcmap = SDL_stack_alloc(XColor, ncolors);
 		if(xcmap == NULL)
 		        return 0;
 		for ( i=0; i<ncolors; ++i ) {
@@ -1227,7 +1214,7 @@
 		}
 		pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
 		pXSync(GFX_Display, False);
-		FREEA(xcmap);
+		SDL_stack_free(xcmap);
 	} else {
 	        /*
 		 * Shared colormap: We only allocate read-only cells, which
@@ -1245,7 +1232,7 @@
 		int nfree = 0;
 		int nc = this->screen->format->palette->ncolors;
 	        colors = this->screen->format->palette->colors;
-		freelist = ALLOCA(nc * sizeof(*freelist));
+		freelist = SDL_stack_alloc(unsigned long, nc);
 		/* make sure multiple allocations of the same cell are freed */
 	        for(i = 0; i < ncolors; i++) {
 		        int pixel = firstcolor + i;
@@ -1255,10 +1242,10 @@
 			}
 		}
 		pXFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0);
-		FREEA(freelist);
+		SDL_stack_free(freelist);
 
-		want = ALLOCA(ncolors * sizeof(SDL_Color));
-		reject = ALLOCA(ncolors * sizeof(SDL_Color));
+		want = SDL_stack_alloc(SDL_Color, ncolors);
+		reject = SDL_stack_alloc(SDL_Color, ncolors);
 		SDL_memcpy(want, colors + firstcolor, ncolors * sizeof(SDL_Color));
 		/* make sure the user isn't fooled by her own wishes
 		   (black is safe, always available in the default colormap) */
@@ -1288,8 +1275,8 @@
 		}
 		if(nrej)
 			allocate_nearest(this, colors, reject, nrej);
-		FREEA(reject);
-		FREEA(want);
+		SDL_stack_free(reject);
+		SDL_stack_free(want);
 	}
 	return nrej == 0;
 }
--- a/src/video/x11/SDL_x11wm.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11wm.c	Tue Feb 07 09:29:18 2006 +0000
@@ -20,12 +20,12 @@
     slouken@libsdl.org
 */
 
-#include <stdlib.h>
-#include <string.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
 #include "SDL_version.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_timer.h"
 #include "SDL_video.h"
--- a/src/video/x11/SDL_x11yuv.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/x11/SDL_x11yuv.c	Tue Feb 07 09:29:18 2006 +0000
@@ -24,8 +24,6 @@
 
 #ifdef XFREE86_XV
 
-#include <stdlib.h>
-#include <string.h>
 #include <X11/Xlib.h>
 #ifndef NO_SHARED_MEMORY
 #include <sys/ipc.h>
@@ -34,6 +32,8 @@
 #endif
 #include <Xext/extensions/Xvlib.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_x11yuv_c.h"
--- a/src/video/xbios/SDL_xbios.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/xbios/SDL_xbios.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,9 +26,6 @@
  * Patrice Mandin
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
@@ -38,6 +35,8 @@
 #include <mint/falcon.h>
 
 #include "SDL.h"
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_error.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
--- a/src/video/xbios/SDL_xbios_centscreen.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/xbios/SDL_xbios_centscreen.c	Tue Feb 07 09:29:18 2006 +0000
@@ -26,11 +26,10 @@
 	Patrice Mandin
 */
 
-#include <stdlib.h>
-#include <string.h>
-
 #include <mint/falcon.h>
 
+#include "SDL_stdlib.h"
+#include "SDL_string.h"
 #include "SDL_xbios.h"
 #include "SDL_xbios_centscreen.h"
 
--- a/src/video/xbios/SDL_xbios_sb3.c	Tue Feb 07 07:03:29 2006 +0000
+++ b/src/video/xbios/SDL_xbios_sb3.c	Tue Feb 07 09:29:18 2006 +0000
@@ -28,8 +28,7 @@
 
 /*--- Includes ---*/
 
-#include <stdlib.h>
-
+#include "SDL_stdlib.h"
 #include "SDL_xbios.h"
 #include "SDL_xbios_sb3.h"