Commit d31251b0142ae6b275c75a13ce79288b9eb4864d

Sylvain 2021-11-21T22:30:48

use SDL's functions version inplace of libc version

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
diff --git a/Xcode-iOS/Demos/src/accelerometer.c b/Xcode-iOS/Demos/src/accelerometer.c
index 2cc0123..925aee4 100644
--- a/Xcode-iOS/Demos/src/accelerometer.c
+++ b/Xcode-iOS/Demos/src/accelerometer.c
@@ -58,7 +58,7 @@ render(SDL_Renderer *renderer, int w, int h, double deltaTime)
         ay * SDL_IPHONE_MAX_GFORCE / SINT16_MAX * GRAVITY_CONSTANT *
         deltaMilliseconds;
 
-    speed = sqrt(shipData.vx * shipData.vx + shipData.vy * shipData.vy);
+    speed = SDL_sqrt(shipData.vx * shipData.vx + shipData.vy * shipData.vy);
 
     if (speed > 0) {
         /* compensate for friction */
diff --git a/Xcode-iOS/Demos/src/fireworks.c b/Xcode-iOS/Demos/src/fireworks.c
index 2c4f621..600d20b 100644
--- a/Xcode-iOS/Demos/src/fireworks.c
+++ b/Xcode-iOS/Demos/src/fireworks.c
@@ -109,7 +109,7 @@ stepParticles(double deltaTime)
                 }
             } else {
                 float speed =
-                    sqrt(curr->xvel * curr->xvel + curr->yvel * curr->yvel);
+                    SDL_sqrt(curr->xvel * curr->xvel + curr->yvel * curr->yvel);
                 /*      if wind resistance is not powerful enough to stop us completely,
                    then apply winde resistance, otherwise just stop us completely */
                 if (WIND_RESISTANCE * deltaMilliseconds < speed) {
@@ -194,15 +194,15 @@ explodeEmitter(struct particle *emitter)
         /* come up with a random angle and speed for new particle */
         float theta = randomFloat(0, 2.0f * 3.141592);
         float exponent = 3.0f;
-        float speed = randomFloat(0.00, powf(0.17, exponent));
-        speed = powf(speed, 1.0f / exponent);
+        float speed = randomFloat(0.00, SDL_powf(0.17, exponent));
+        speed = SDL_powf(speed, 1.0f / exponent);
 
         /* select the particle at the end of our array */
         struct particle *p = &particles[num_active_particles];
 
         /* set the particles properties */
-        p->xvel = speed * cos(theta);
-        p->yvel = speed * sin(theta);
+        p->xvel = speed * SDL_cos(theta);
+        p->yvel = speed * SDL_sin(theta);
         p->x = emitter->x + emitter->xvel;
         p->y = emitter->y + emitter->yvel;
         p->isActive = 1;
@@ -297,7 +297,7 @@ spawnEmitterParticle(GLfloat x, GLfloat y)
     p->y = screen_h;
     /* set velocity so that terminal point is (x,y) */
     p->xvel = 0;
-    p->yvel = -sqrt(2 * ACCEL * (screen_h - y));
+    p->yvel = -SDL_sqrt(2 * ACCEL * (screen_h - y));
     /* set other attributes */
     p->size = 10 * pointSizeScale;
     p->type = emitter;
diff --git a/Xcode-iOS/Demos/src/touch.c b/Xcode-iOS/Demos/src/touch.c
index 6f727e4..918240b 100644
--- a/Xcode-iOS/Demos/src/touch.c
+++ b/Xcode-iOS/Demos/src/touch.c
@@ -21,7 +21,7 @@ void
 drawLine(SDL_Renderer *renderer, float startx, float starty, float dx, float dy)
 {
 
-    float distance = sqrt(dx * dx + dy * dy);   /* length of line segment (pythagoras) */
+    float distance = SDL_sqrt(dx * dx + dy * dy);   /* length of line segment (pythagoras) */
     int iterations = distance / PIXELS_PER_ITERATION + 1;       /* number of brush sprites to draw for the line */
     float dx_prime = dx / iterations;   /* x-shift per iteration */
     float dy_prime = dy / iterations;   /* y-shift per iteration */
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index fd8e6da..318644e 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -1753,7 +1753,7 @@ SDL_SilenceValueForFormat(const SDL_AudioFormat format)
 {
     switch (format) {
         /* !!! FIXME: 0x80 isn't perfect for U16, but we can't fit 0x8000 in a
-           !!! FIXME:  byte for memset() use. This is actually 0.1953 percent
+           !!! FIXME:  byte for SDL_memset() use. This is actually 0.1953 percent
            !!! FIXME:  off from silence. Maybe just don't use U16. */
         case AUDIO_U16LSB:
         case AUDIO_U16MSB:
diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c
index 79c879f..2c69743 100644
--- a/src/audio/alsa/SDL_alsa_audio.c
+++ b/src/audio/alsa/SDL_alsa_audio.c
@@ -779,7 +779,7 @@ add_device(const int iscapture, const char *name, void *hint, ALSA_Device **pSee
     /* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
        just chop the extra lines off, this seems to get a reasonable device
        name without extra details. */
-    if ((ptr = strchr(desc, '\n')) != NULL) {
+    if ((ptr = SDL_strchr(desc, '\n')) != NULL) {
         *ptr = '\0';
     }
 
diff --git a/src/audio/psp/SDL_pspaudio.c b/src/audio/psp/SDL_pspaudio.c
index 5eeb0da..e98604c 100644
--- a/src/audio/psp/SDL_pspaudio.c
+++ b/src/audio/psp/SDL_pspaudio.c
@@ -90,7 +90,7 @@ PSPAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
         return SDL_SetError("Couldn't reserve hardware channel");
     }
 
-    memset(this->hidden->rawbuf, 0, mixlen);
+    SDL_memset(this->hidden->rawbuf, 0, mixlen);
     for (i = 0; i < NUM_BUFFERS; i++) {
         this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
     }
diff --git a/src/audio/vita/SDL_vitaaudio.c b/src/audio/vita/SDL_vitaaudio.c
index b69aed8..72929eb 100644
--- a/src/audio/vita/SDL_vitaaudio.c
+++ b/src/audio/vita/SDL_vitaaudio.c
@@ -100,7 +100,7 @@ VITAAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
 
     sceAudioOutSetVolume(this->hidden->channel, SCE_AUDIO_VOLUME_FLAG_L_CH|SCE_AUDIO_VOLUME_FLAG_R_CH, vols);
 
-    memset(this->hidden->rawbuf, 0, mixlen);
+    SDL_memset(this->hidden->rawbuf, 0, mixlen);
     for (i = 0; i < NUM_BUFFERS; i++) {
         this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
     }
diff --git a/src/core/freebsd/SDL_evdev_kbd_freebsd.c b/src/core/freebsd/SDL_evdev_kbd_freebsd.c
index 06642b5..c74b1b8 100644
--- a/src/core/freebsd/SDL_evdev_kbd_freebsd.c
+++ b/src/core/freebsd/SDL_evdev_kbd_freebsd.c
@@ -268,7 +268,7 @@ SDL_EVDEV_kbd_init(void)
             kbd->key_map = &keymap_default_us_acc;
         }
         /* Allow inhibiting keyboard mute with env. variable for debugging etc. */
-        if (getenv("SDL_INPUT_FREEBSD_KEEP_KBD") == NULL) {
+        if (SDL_getenv("SDL_INPUT_FREEBSD_KEEP_KBD") == NULL) {
             /* Take keyboard from console and open the actual keyboard device.
              * Ensures that the keystrokes do not leak through to the console.
              */
diff --git a/src/core/openbsd/SDL_wscons_kbd.c b/src/core/openbsd/SDL_wscons_kbd.c
index a507b6f..b59df0f 100644
--- a/src/core/openbsd/SDL_wscons_kbd.c
+++ b/src/core/openbsd/SDL_wscons_kbd.c
@@ -509,7 +509,7 @@ static void put_utf8(SDL_WSCONS_input_data* input, uint c)
 static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym)
 {
     if (KS_GROUP(ksym) == KS_GROUP_Keypad) {
-        if (isprint(ksym & 0xFF)) ksym &= 0xFF;
+        if (SDL_isprint(ksym & 0xFF)) ksym &= 0xFF;
     }
     switch(ksym) {
     case KS_Escape:
@@ -526,7 +526,7 @@ static void Translate_to_text(SDL_WSCONS_input_data* input, keysym_t ksym)
     if (input->text_len > 0) {
         input->text[input->text_len] = '\0';
         SDL_SendKeyboardText(input->text);
-        /*memset(input->text, 0, sizeof(input->text));*/
+        /*SDL_memset(input->text, 0, sizeof(input->text));*/
         input->text_len = 0;
         input->text[0] = 0;
     }
diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c
index 7749556..a26b892 100644
--- a/src/cpuinfo/SDL_cpuinfo.c
+++ b/src/cpuinfo/SDL_cpuinfo.c
@@ -377,8 +377,8 @@ CPU_haveARMSIMD(void)
             {
                 const char *plat = (const char *) aux.a_un.a_val;
                 if (plat) {
-                    arm_simd = strncmp(plat, "v6l", 3) == 0 ||
-                               strncmp(plat, "v7l", 3) == 0;
+                    arm_simd = SDL_strncmp(plat, "v6l", 3) == 0 ||
+                               SDL_strncmp(plat, "v7l", 3) == 0;
                 }
             }
         }
diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c
index c39c07a..83321b8 100644
--- a/src/filesystem/unix/SDL_sysfilesystem.c
+++ b/src/filesystem/unix/SDL_sysfilesystem.c
@@ -82,7 +82,7 @@ readSymLink(const char *path)
 #if defined(__OPENBSD__)
 static char *search_path_for_binary(const char *bin)
 {
-    char *envr = getenv("PATH");
+    char *envr = SDL_getenv("PATH");
     size_t alloc_size;
     char *exe = NULL;
     char *start = envr;
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index 555fd83..744a54e 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -35,7 +35,6 @@
 #include <fcntl.h>              /* O_RDWR */
 #include <limits.h>             /* INT_MAX */
 #include <errno.h>              /* errno, strerror */
-#include <math.h>               /* atan2 */
 #include <sys/stat.h>           /* stat */
 
 /* Just in case. */
@@ -713,10 +712,10 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
         else {
             float f = SDL_atan2(src->dir[1], src->dir[0]);    /* Ideally we'd use fixed point math instead of floats... */
                     /*
-                      atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
+                      SDL_atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
                        - Y-axis-value is the second coordinate (from center to SOUTH)
                        - X-axis-value is the first coordinate (from center to EAST)
-                        We add 36000, because atan2 also returns negative values. Then we practically
+                        We add 36000, because SDL_atan2 also returns negative values. Then we practically
                         have the first spherical value. Therefore we proceed as in case
                         SDL_HAPTIC_SPHERICAL and add another 9000 to get the polar value.
                       --> add 45000 in total
diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp
index bac7bc4..0984f47 100644
--- a/src/hidapi/android/hid.cpp
+++ b/src/hidapi/android/hid.cpp
@@ -53,7 +53,6 @@
 #include <pthread.h>
 #include <errno.h>	// For ETIMEDOUT and ECONNRESET
 #include <stdlib.h> // For malloc() and free()
-#include <string.h>	// For memcpy()
 
 #define TAG "hidapi"
 
@@ -196,7 +195,7 @@ public:
 		}
 
 		m_nSize = nSize;
-		memcpy( m_pData, pData, nSize );
+		SDL_memcpy( m_pData, pData, nSize );
 	}
 
 	void clear()
@@ -313,7 +312,7 @@ static jbyteArray NewByteArray( JNIEnv* env, const uint8_t *pData, size_t nDataL
 {
 	jbyteArray array = env->NewByteArray( (jsize)nDataLen );
 	jbyte *pBuf = env->GetByteArrayElements( array, NULL );
-	memcpy( pBuf, pData, nDataLen );
+	SDL_memcpy( pBuf, pData, nDataLen );
 	env->ReleaseByteArrayElements( array, pBuf, 0 );
 
 	return array;
@@ -324,7 +323,7 @@ static char *CreateStringFromJString( JNIEnv *env, const jstring &sString )
 	size_t nLength = env->GetStringUTFLength( sString );
 	const char *pjChars = env->GetStringUTFChars( sString, NULL );
 	char *psString = (char*)malloc( nLength + 1 );
-	memcpy( psString, pjChars, nLength );
+	SDL_memcpy( psString, pjChars, nLength );
 	psString[ nLength ] = '\0';
 	env->ReleaseStringUTFChars( sString, pjChars );
 	return psString;
@@ -347,9 +346,9 @@ static wchar_t *CreateWStringFromJString( JNIEnv *env, const jstring &sString )
 
 static wchar_t *CreateWStringFromWString( const wchar_t *pwSrc )
 {
-	size_t nLength = wcslen( pwSrc );
+	size_t nLength = SDL_wcslen( pwSrc );
 	wchar_t *pwString = (wchar_t*)malloc( ( nLength + 1 ) * sizeof( wchar_t ) );
-	memcpy( pwString, pwSrc, nLength * sizeof( wchar_t ) );
+	SDL_memcpy( pwString, pwSrc, nLength * sizeof( wchar_t ) );
 	pwString[ nLength ] = '\0';
 	return pwString;
 }
@@ -358,7 +357,7 @@ static hid_device_info *CopyHIDDeviceInfo( const hid_device_info *pInfo )
 {
 	hid_device_info *pCopy = new hid_device_info;
 	*pCopy = *pInfo;
-	pCopy->path = strdup( pInfo->path );
+	pCopy->path = SDL_strdup( pInfo->path );
 	pCopy->product_string = CreateWStringFromWString( pInfo->product_string );
 	pCopy->manufacturer_string = CreateWStringFromWString( pInfo->manufacturer_string );
 	pCopy->serial_number = CreateWStringFromWString( pInfo->serial_number );
@@ -579,12 +578,12 @@ public:
 		if ( m_bIsBLESteamController )
 		{
 			data[0] = 0x03;
-			memcpy( data + 1, buffer.data(), nDataLen );
+			SDL_memcpy( data + 1, buffer.data(), nDataLen );
 			++nDataLen;
 		}
 		else
 		{
-			memcpy( data, buffer.data(), nDataLen );
+			SDL_memcpy( data, buffer.data(), nDataLen );
 		}
 		m_vecData.pop_front();
 
@@ -721,7 +720,7 @@ public:
 			}
 
 			size_t uBytesToCopy = m_featureReport.size() > nDataLen ? nDataLen : m_featureReport.size();
-			memcpy( pData, m_featureReport.data(), uBytesToCopy );
+			SDL_memcpy( pData, m_featureReport.data(), uBytesToCopy );
 			m_featureReport.clear();
 			LOGV( "=== Got %u bytes", uBytesToCopy );
 
@@ -921,7 +920,7 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNI
 	LOGV( "HIDDeviceConnected() id=%d VID/PID = %.4x/%.4x, interface %d\n", nDeviceID, nVendorId, nProductId, nInterface );
 
 	hid_device_info *pInfo = new hid_device_info;
-	memset( pInfo, 0, sizeof( *pInfo ) );
+	SDL_memset( pInfo, 0, sizeof( *pInfo ) );
 	pInfo->path = CreateStringFromJString( env, sIdentifier );
 	pInfo->vendor_id = nVendorId;
 	pInfo->product_id = nProductId;
@@ -1120,7 +1119,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx
 		hid_mutex_guard l( &g_DevicesMutex );
 		for ( hid_device_ref<CHIDDevice> pCurr = g_Devices; pCurr; pCurr = pCurr->next )
 		{
-			if ( strcmp( pCurr->GetDeviceInfo()->path, path ) == 0 ) 
+			if ( SDL_strcmp( pCurr->GetDeviceInfo()->path, path ) == 0 ) 
 			{
 				hid_device *pValue = pCurr->GetDevice();
 				if ( pValue )
diff --git a/src/joystick/hidapi/SDL_hidapi_steam.c b/src/joystick/hidapi/SDL_hidapi_steam.c
index d89bd08..5cbf339 100644
--- a/src/joystick/hidapi/SDL_hidapi_steam.c
+++ b/src/joystick/hidapi/SDL_hidapi_steam.c
@@ -220,7 +220,7 @@ static void hexdump( const uint8_t *ptr, int len )
 
 static void ResetSteamControllerPacketAssembler( SteamControllerPacketAssembler *pAssembler )
 {
-    memset( pAssembler->uBuffer, 0, sizeof( pAssembler->uBuffer ) );
+    SDL_memset( pAssembler->uBuffer, 0, sizeof( pAssembler->uBuffer ) );
     pAssembler->nExpectedSegmentNumber = 0;
 }
 
@@ -279,7 +279,7 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs
             }
         }
         
-        memcpy( pAssembler->uBuffer + nSegmentNumber * MAX_REPORT_SEGMENT_PAYLOAD_SIZE,
+        SDL_memcpy( pAssembler->uBuffer + nSegmentNumber * MAX_REPORT_SEGMENT_PAYLOAD_SIZE,
                pSegment + 2, // ignore header and report number
                MAX_REPORT_SEGMENT_PAYLOAD_SIZE );
         
@@ -294,7 +294,7 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs
     else
     {
         // Just pass through
-        memcpy( pAssembler->uBuffer,
+        SDL_memcpy( pAssembler->uBuffer,
                pSegment,
                nSegmentLength );
         return nSegmentLength;
@@ -331,10 +331,10 @@ static int SetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65], int
             nActualDataLen -= nBytesInPacket;
 
             // Construct packet
-            memset( uPacketBuffer, 0, sizeof( uPacketBuffer ) );
+            SDL_memset( uPacketBuffer, 0, sizeof( uPacketBuffer ) );
             uPacketBuffer[ 0 ] = BLE_REPORT_NUMBER;
             uPacketBuffer[ 1 ] = GetSegmentHeader( nSegmentNumber, nActualDataLen == 0 );
-            memcpy( &uPacketBuffer[ 2 ], pBufferPtr, nBytesInPacket );
+            SDL_memcpy( &uPacketBuffer[ 2 ], pBufferPtr, nBytesInPacket );
             
             pBufferPtr += nBytesInPacket;
             nSegmentNumber++;
@@ -364,7 +364,7 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
         
         while( nRetries < BLE_MAX_READ_RETRIES )
         {
-            memset( uSegmentBuffer, 0, sizeof( uSegmentBuffer ) );
+            SDL_memset( uSegmentBuffer, 0, sizeof( uSegmentBuffer ) );
             uSegmentBuffer[ 0 ] = BLE_REPORT_NUMBER;
             nRet = SDL_hid_get_feature_report( dev, uSegmentBuffer, sizeof( uSegmentBuffer ) );
             DPRINTF( "GetFeatureReport ble ret=%d\n", nRet );
@@ -386,7 +386,7 @@ static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
                 {
                     // Leave space for "report number"
                     uBuffer[ 0 ] = 0;
-                    memcpy( uBuffer + 1, assembler.uBuffer, nPacketLength );
+                    SDL_memcpy( uBuffer + 1, assembler.uBuffer, nPacketLength );
                     return nPacketLength;
                 }
             }
@@ -500,7 +500,7 @@ static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew, 
     }
     
     // Reset the default settings
-    memset( buf, 0, 65 );
+    SDL_memset( buf, 0, 65 );
     buf[1] = ID_LOAD_DEFAULT_SETTINGS;
     buf[2] = 0;
     res = SetFeatureReport( dev, buf, 3 );
@@ -518,7 +518,7 @@ buf[3+nSettings*3+1] = ((uint16_t)VALUE)&0xFF; \
 buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
 ++nSettings;
     
-    memset( buf, 0, 65 );
+    SDL_memset( buf, 0, 65 );
     buf[1] = ID_SET_SETTINGS_VALUES;
     ADD_SETTING( SETTING_WIRELESS_PACKET_VERSION, 2 );
     ADD_SETTING( SETTING_LEFT_TRACKPAD_MODE, TRACKPAD_NONE );
@@ -547,7 +547,7 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
     int iRetry;
     for ( iRetry = 0; iRetry < 2; ++iRetry )
     {
-        memset( buf, 0, 65 );
+        SDL_memset( buf, 0, 65 );
         buf[1] = ID_GET_DIGITAL_MAPPINGS;
         buf[2] = 1; // one byte - requesting from index 0
         buf[3] = 0;
@@ -580,7 +580,7 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
     }
     
     // Set our new mappings
-    memset( buf, 0, 65 );
+    SDL_memset( buf, 0, 65 );
     buf[1] = ID_SET_DIGITAL_MAPPINGS;
     buf[2] = 6; // 2 settings x 3 bytes
     buf[3] = IO_DIGITAL_BUTTON_RIGHT_TRIGGER;
@@ -608,7 +608,7 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
 //---------------------------------------------------------------------------
 static int ReadSteamController( SDL_hid_device *dev, uint8_t *pData, int nDataSize )
 {
-    memset( pData, 0, nDataSize );
+    SDL_memset( pData, 0, nDataSize );
     pData[ 0 ] = BLE_REPORT_NUMBER; // hid_read will also overwrite this with the same value, 0x03
     return SDL_hid_read( dev, pData, nDataSize );
 }
@@ -624,18 +624,18 @@ static void CloseSteamController( SDL_hid_device *dev )
     int nSettings = 0;
     
     // Reset digital button mappings
-    memset( buf, 0, 65 );
+    SDL_memset( buf, 0, 65 );
     buf[1] = ID_SET_DEFAULT_DIGITAL_MAPPINGS;
     SetFeatureReport( dev, buf, 2 );
 
     // Reset the default settings
-    memset( buf, 0, 65 );
+    SDL_memset( buf, 0, 65 );
     buf[1] = ID_LOAD_DEFAULT_SETTINGS;
     buf[2] = 0;
     SetFeatureReport( dev, buf, 3 );
 
     // Reset mouse mode for lizard mode
-    memset( buf, 0, 65 );
+    SDL_memset( buf, 0, 65 );
     buf[1] = ID_SET_SETTINGS_VALUES;
     ADD_SETTING( SETTING_RIGHT_TRACKPAD_MODE, TRACKPAD_ABSOLUTE_MOUSE );
     buf[2] = nSettings*3;
@@ -695,14 +695,14 @@ static void FormatStatePacketUntilGyro( SteamControllerStateInternal_t *pState, 
     // 15 degrees in rad
     const float flRotationAngle = 0.261799f;
 
-    memset(pState, 0, offsetof(SteamControllerStateInternal_t, sBatteryLevel));
+    SDL_memset(pState, 0, offsetof(SteamControllerStateInternal_t, sBatteryLevel));
 
     //pState->eControllerType = m_eControllerType;
     pState->eControllerType = 2; // k_eControllerType_SteamController;
     pState->unPacketNum = pStatePacket->unPacketNum;
 
     // We have a chunk of trigger data in the packet format here, so zero it out afterwards
-    memcpy(&pState->ulButtons, &pStatePacket->ButtonTriggerData.ulButtons, 8);
+    SDL_memcpy(&pState->ulButtons, &pStatePacket->ButtonTriggerData.ulButtons, 8);
     pState->ulButtons &= ~0xFFFF000000LL;
 
     // The firmware uses this bit to tell us what kind of data is packed into the left two axises
@@ -822,7 +822,7 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize, 
     ucOptionDataMask |= (uint32_t)(*pData++) << 8;
     if ( ucOptionDataMask & k_EBLEButtonChunk1 )
     {
-        memcpy( &pState->ulButtons, pData, 3 );
+        SDL_memcpy( &pState->ulButtons, pData, 3 );
         pData += 3;
     }
     if ( ucOptionDataMask & k_EBLEButtonChunk2 )
@@ -844,14 +844,14 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize, 
         // This doesn't handle any of the special headcrab stuff for raw joystick which is OK for now since that FW doesn't support
         // this protocol yet either
         int nLength = sizeof( pState->sLeftStickX ) + sizeof( pState->sLeftStickY );
-        memcpy( &pState->sLeftStickX, pData, nLength );
+        SDL_memcpy( &pState->sLeftStickX, pData, nLength );
         pData += nLength;
     }
     if ( ucOptionDataMask & k_EBLELeftTrackpadChunk )
     {
         int nLength = sizeof( pState->sLeftPadX ) + sizeof( pState->sLeftPadY );
         int nPadOffset;
-        memcpy( &pState->sLeftPadX, pData, nLength );
+        SDL_memcpy( &pState->sLeftPadX, pData, nLength );
         if ( pState->ulButtons & STEAM_LEFTPAD_FINGERDOWN_MASK )
             nPadOffset = 1000;
         else
@@ -867,7 +867,7 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize, 
         int nLength = sizeof( pState->sRightPadX ) + sizeof( pState->sRightPadY );
         int nPadOffset = 0;
 
-        memcpy( &pState->sRightPadX, pData, nLength );
+        SDL_memcpy( &pState->sRightPadX, pData, nLength );
 
         if ( pState->ulButtons & STEAM_RIGHTPAD_FINGERDOWN_MASK )
             nPadOffset = 1000;
@@ -882,19 +882,19 @@ static bool UpdateBLESteamControllerState( const uint8_t *pData, int nDataSize, 
     if ( ucOptionDataMask & k_EBLEIMUAccelChunk )
     {
         int nLength = sizeof( pState->sAccelX ) + sizeof( pState->sAccelY ) + sizeof( pState->sAccelZ );
-        memcpy( &pState->sAccelX, pData, nLength );
+        SDL_memcpy( &pState->sAccelX, pData, nLength );
         pData += nLength;
     }
     if ( ucOptionDataMask & k_EBLEIMUGyroChunk )
     {
         int nLength = sizeof( pState->sAccelX ) + sizeof( pState->sAccelY ) + sizeof( pState->sAccelZ );
-        memcpy( &pState->sGyroX, pData, nLength );
+        SDL_memcpy( &pState->sGyroX, pData, nLength );
         pData += nLength;
     }
     if ( ucOptionDataMask & k_EBLEIMUQuatChunk )
     {
         int nLength = sizeof( pState->sGyroQuatW ) + sizeof( pState->sGyroQuatX ) + sizeof( pState->sGyroQuatY ) + sizeof( pState->sGyroQuatZ );
-        memcpy( &pState->sGyroQuatW, pData, nLength );
+        SDL_memcpy( &pState->sGyroQuatW, pData, nLength );
         pData += nLength;
     }
     return true;
@@ -1122,7 +1122,7 @@ HIDAPI_DriverSteam_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *jo
     unsigned char buf[65];
     int nSettings = 0;
 
-    memset( buf, 0, 65 );
+    SDL_memset( buf, 0, 65 );
     buf[1] = ID_SET_SETTINGS_VALUES;
     if (enabled) {
         ADD_SETTING( SETTING_GYRO_MODE, 0x18 /* SETTING_GYRO_SEND_RAW_ACCEL | SETTING_GYRO_MODE_SEND_RAW_GYRO */ );
diff --git a/src/locale/SDL_locale.c b/src/locale/SDL_locale.c
index 59f3e7f..e475b07 100644
--- a/src/locale/SDL_locale.c
+++ b/src/locale/SDL_locale.c
@@ -45,7 +45,7 @@ build_locales_from_csv_string(char *csv)
 
     num_locales++;  /* one more for terminator */
 
-    slen = ((size_t) (ptr - csv)) + 1;  /* strlen(csv) + 1 */
+    slen = ((size_t) (ptr - csv)) + 1;  /* SDL_strlen(csv) + 1 */
     alloclen = slen + (num_locales * sizeof (SDL_Locale));
 
     loc = retval = (SDL_Locale *) SDL_calloc(1, alloclen);
diff --git a/src/misc/vita/SDL_sysurl.c b/src/misc/vita/SDL_sysurl.c
index 42f6c45..68f3997 100644
--- a/src/misc/vita/SDL_sysurl.c
+++ b/src/misc/vita/SDL_sysurl.c
@@ -35,7 +35,7 @@ SDL_SYS_OpenURL(const char *url)
     sceAppUtilInit(&init_param, &boot_param);
     SDL_zero(browser_param);
     browser_param.str = url;
-    browser_param.strlen = strlen(url);
+    browser_param.strlen = SDL_strlen(url);
     sceAppUtilLaunchWebBrowser(&browser_param);
     return 0;
 }
diff --git a/src/power/haiku/SDL_syspower.c b/src/power/haiku/SDL_syspower.c
index 87167b9..4ae9657 100644
--- a/src/power/haiku/SDL_syspower.c
+++ b/src/power/haiku/SDL_syspower.c
@@ -59,7 +59,7 @@ SDL_GetPowerInfo_Haiku(SDL_PowerState * state, int *seconds, int *percent)
         return SDL_FALSE;       /* maybe some other method will work? */
     }
 
-    memset(regs, '\0', sizeof(regs));
+    SDL_memset(regs, '\0', sizeof(regs));
     regs[0] = APM_FUNC_OFFSET + APM_FUNC_GET_POWER_STATUS;
     regs[1] = APM_DEVICE_ALL;
     rc = ioctl(fd, APM_BIOS_CALL, regs);
diff --git a/src/power/linux/SDL_syspower.c b/src/power/linux/SDL_syspower.c
index f911005..c02ef0d 100644
--- a/src/power/linux/SDL_syspower.c
+++ b/src/power/linux/SDL_syspower.c
@@ -51,7 +51,7 @@ open_power_file(const char *base, const char *node, const char *key)
         return -1;  /* oh well. */
     }
 
-    snprintf(path, pathlen, "%s/%s/%s", base, node, key);
+    SDL_snprintf(path, pathlen, "%s/%s/%s", base, node, key);
     fd = open(path, O_RDONLY | O_CLOEXEC);
     SDL_stack_free(path);
     return fd;
diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c
index a903d1d..b5ac715 100644
--- a/src/render/software/SDL_rotate.c
+++ b/src/render/software/SDL_rotate.c
@@ -184,7 +184,7 @@ computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int 
     if (signy < 0) sp += (src->h-1)*src->pitch;                                                             \
                                                                                                             \
     for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) {                                             \
-        if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */               \
+        if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use SDL_memcpy */           \
             SDL_memcpy(dp, sp, dst->w*sizeof(pixelType));                                                   \
             sp += dst->w*sizeof(pixelType);                                                                 \
             dp += dst->w*sizeof(pixelType);                                                                 \
@@ -439,7 +439,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, 
     if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))
         return NULL;
 
-    /* Calculate target factors from sin/cos and zoom */
+    /* Calculate target factors from sine/cosine and zoom */
     sangleinv = sangle*65536.0;
     cangleinv = cangle*65536.0;
 
diff --git a/src/render/vitagxm/SDL_render_vita_gxm_tools.c b/src/render/vitagxm/SDL_render_vita_gxm_tools.c
index 08c3611..6d0a4b9 100644
--- a/src/render/vitagxm/SDL_render_vita_gxm_tools.c
+++ b/src/render/vitagxm/SDL_render_vita_gxm_tools.c
@@ -475,7 +475,7 @@ gxm_init(SDL_Renderer *renderer)
             SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE,
             &data->displayBufferUid[i]);
 
-        // memset the buffer to black
+        // SDL_memset the buffer to black
         for (y = 0; y < VITA_GXM_SCREEN_HEIGHT; y++) {
             unsigned int *row = (unsigned int *)data->displayBufferData[i] + y * VITA_GXM_SCREEN_STRIDE;
             for (x = 0; x < VITA_GXM_SCREEN_WIDTH; x++) {
@@ -1104,7 +1104,7 @@ create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, Sc
 
             // set up parameters
             SceGxmRenderTargetParams renderTargetParams;
-            memset(&renderTargetParams, 0, sizeof(SceGxmRenderTargetParams));
+            SDL_memset(&renderTargetParams, 0, sizeof(SceGxmRenderTargetParams));
             renderTargetParams.flags = 0;
             renderTargetParams.width = w;
             renderTargetParams.height = h;
diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c
index c8c3368..7e19bbe 100644
--- a/src/video/directfb/SDL_DirectFB_events.c
+++ b/src/video/directfb/SDL_DirectFB_events.c
@@ -683,7 +683,7 @@ EnumKeyboards(DFBInputDeviceID device_id,
 #endif
         devdata->keyboard[devdata->num_keyboard].id = device_id;
         devdata->keyboard[devdata->num_keyboard].is_generic = 0;
-        if (!strncmp("X11", desc.name, 3))
+        if (!SDL_strncmp("X11", desc.name, 3))
         {
             devdata->keyboard[devdata->num_keyboard].map = xfree86_scancode_table2;
             devdata->keyboard[devdata->num_keyboard].map_size = SDL_arraysize(xfree86_scancode_table2);
diff --git a/src/video/directfb/SDL_DirectFB_mouse.c b/src/video/directfb/SDL_DirectFB_mouse.c
index 9674625..597fc3a 100644
--- a/src/video/directfb/SDL_DirectFB_mouse.c
+++ b/src/video/directfb/SDL_DirectFB_mouse.c
@@ -164,7 +164,7 @@ DirectFB_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
 
     p = surface->pixels;
     for (i = 0; i < surface->h; i++)
-        memcpy((char *) dest + i * pitch,
+        SDL_memcpy((char *) dest + i * pitch,
                (char *) p + i * surface->pitch, 4 * surface->w);
 
     curdata->surf->Unlock(curdata->surf);
diff --git a/src/video/directfb/SDL_DirectFB_video.c b/src/video/directfb/SDL_DirectFB_video.c
index cca2fd7..2552971 100644
--- a/src/video/directfb/SDL_DirectFB_video.c
+++ b/src/video/directfb/SDL_DirectFB_video.c
@@ -201,7 +201,7 @@ static int readBoolEnv(const char *env_name, int def_val)
 
     stemp = SDL_getenv(env_name);
     if (stemp)
-        return atoi(stemp);
+        return SDL_atoi(stemp);
     else
         return def_val;
 }
diff --git a/src/video/directfb/SDL_DirectFB_window.c b/src/video/directfb/SDL_DirectFB_window.c
index b8c78fe..48e6875 100644
--- a/src/video/directfb/SDL_DirectFB_window.c
+++ b/src/video/directfb/SDL_DirectFB_window.c
@@ -227,7 +227,7 @@ DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
 
         p = surface->pixels;
         for (i = 0; i < surface->h; i++)
-            memcpy((char *) dest + i * pitch,
+            SDL_memcpy((char *) dest + i * pitch,
                    (char *) p + i * surface->pitch, 4 * surface->w);
 
         SDL_DFB_CHECK(windata->icon->Unlock(windata->icon));
diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c
index 95087da..db2f74a 100644
--- a/src/video/emscripten/SDL_emscriptenframebuffer.c
+++ b/src/video/emscripten/SDL_emscriptenframebuffer.c
@@ -119,7 +119,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rec
             //      }
             // the following code is faster though, because
             // .set() is almost free - easily 10x faster due to
-            // native memcpy efficiencies, and the remaining loop
+            // native SDL_memcpy efficiencies, and the remaining loop
             // just stores, not load + store, so it is faster
             data32.set(HEAP32.subarray(src, src + num));
             var data8 = SDL2.data8;
diff --git a/src/video/haiku/SDL_BWin.h b/src/video/haiku/SDL_BWin.h
index bfd2014..11061e5 100644
--- a/src/video/haiku/SDL_BWin.h
+++ b/src/video/haiku/SDL_BWin.h
@@ -193,7 +193,7 @@ class SDL_BWin:public BDirectWindow
             if (_clips == NULL)
                 _clips = (clipping_rect *)malloc(_num_clips*sizeof(clipping_rect));
             if(_clips) {
-                memcpy(_clips, info->clip_list,
+                SDL_memcpy(_clips, info->clip_list,
                     _num_clips*sizeof(clipping_rect));
 
                 _bits = (uint8*) info->bits;
diff --git a/src/video/vita/SDL_vitaframebuffer.c b/src/video/vita/SDL_vitaframebuffer.c
index a8b9014..af055b1 100644
--- a/src/video/vita/SDL_vitaframebuffer.c
+++ b/src/video/vita/SDL_vitaframebuffer.c
@@ -74,7 +74,7 @@ int VITA_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, vo
         &data->buffer_uid
     );
 
-    // memset the buffer to black
+    // SDL_memset the buffer to black
     SDL_memset(data->buffer, 0x0, SCREEN_W*SCREEN_H*4);
 
     SDL_memset(&framebuf, 0x00, sizeof(SceDisplayFrameBuf));
diff --git a/src/video/vita/SDL_vitatouch.c b/src/video/vita/SDL_vitatouch.c
index 51684f5..8e08784 100644
--- a/src/video/vita/SDL_vitatouch.c
+++ b/src/video/vita/SDL_vitatouch.c
@@ -90,7 +90,7 @@ VITA_PollTouch(void)
     if (Vita_Window == NULL)
         return;
 
-    memcpy(touch_old, touch, sizeof(touch_old));
+    SDL_memcpy(touch_old, touch, sizeof(touch_old));
 
     for(port = 0; port < SCE_TOUCH_PORT_MAX_NUM; port++) {
         /** Skip polling of Touch Device if environment variable is set **/
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
index c9d2812..1938cd6 100644
--- a/src/video/wayland/SDL_waylandvideo.c
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -601,7 +601,7 @@ display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
         d->idle_inhibit_manager = wl_registry_bind(d->registry, id, &zwp_idle_inhibit_manager_v1_interface, 1);
     } else if (SDL_strcmp(interface, "xdg_activation_v1") == 0) {
         d->activation_manager = wl_registry_bind(d->registry, id, &xdg_activation_v1_interface, 1);
-    } else if (strcmp(interface, "zwp_text_input_manager_v3") == 0) {
+    } else if (SDL_strcmp(interface, "zwp_text_input_manager_v3") == 0) {
         Wayland_add_text_input_manager(d, id, version);
     } else if (SDL_strcmp(interface, "wl_data_device_manager") == 0) {
         Wayland_add_data_device_manager(d, id, version);
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index 5d0517e..1d0bd79 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -270,19 +270,19 @@ static char* X11_URIToLocal(char* uri) {
     char *file = NULL;
     SDL_bool local;
 
-    if (memcmp(uri,"file:/",6) == 0) uri += 6;      /* local file? */
-    else if (strstr(uri,":/") != NULL) return file; /* wrong scheme */
+    if (SDL_memcmp(uri,"file:/",6) == 0) uri += 6;      /* local file? */
+    else if (SDL_strstr(uri,":/") != NULL) return file; /* wrong scheme */
 
     local = uri[0] != '/' || (uri[0] != '\0' && uri[1] == '/');
 
     /* got a hostname? */
     if (!local && uri[0] == '/' && uri[2] != '/') {
-      char* hostname_end = strchr(uri+1, '/');
+      char* hostname_end = SDL_strchr(uri+1, '/');
       if (hostname_end != NULL) {
           char hostname[ 257 ];
           if (gethostname(hostname, 255) == 0) {
             hostname[ 256 ] = '\0';
-            if (memcmp(uri+1, hostname, hostname_end - (uri+1)) == 0) {
+            if (SDL_memcmp(uri+1, hostname, hostname_end - (uri+1)) == 0) {
                 uri = hostname_end + 1;
                 local = SDL_TRUE;
             }
@@ -1186,7 +1186,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent)
 
 
                 /* reply with status */
-                memset(&m, 0, sizeof(XClientMessageEvent));
+                SDL_memset(&m, 0, sizeof(XClientMessageEvent));
                 m.type = ClientMessage;
                 m.display = xevent->xclient.display;
                 m.window = xevent->xclient.data.l[0];
@@ -1204,7 +1204,7 @@ X11_DispatchEvent(_THIS, XEvent *xevent)
             else if(xevent->xclient.message_type == videodata->XdndDrop) {
                 if (data->xdnd_req == None) {
                     /* say again - not interested! */
-                    memset(&m, 0, sizeof(XClientMessageEvent));
+                    SDL_memset(&m, 0, sizeof(XClientMessageEvent));
                     m.type = ClientMessage;
                     m.display = xevent->xclient.display;
                     m.window = xevent->xclient.data.l[0];
@@ -1583,7 +1583,7 @@ X11_SendWakeupEvent(_THIS, SDL_Window *window)
     Window xwindow = ((SDL_WindowData *) window->driverdata)->xwindow;
     XClientMessageEvent event;
 
-    memset(&event, 0, sizeof(XClientMessageEvent));
+    SDL_memset(&event, 0, sizeof(XClientMessageEvent));
     event.type = ClientMessage;
     event.display = req_display;
     event.send_event = True;
diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c
index c0a5b5f..cbc3242 100644
--- a/src/video/x11/SDL_x11modes.c
+++ b/src/video/x11/SDL_x11modes.c
@@ -358,7 +358,7 @@ GetXftDPI(Display* dpy)
     }
 
     /*
-     * It's possible for SDL_atoi to call strtol, if it fails due to a
+     * It's possible for SDL_atoi to call SDL_strtol, if it fails due to a
      * overflow or an underflow, it will return LONG_MAX or LONG_MIN and set
      * errno to ERANGE. So we need to check for this so we dont get crazy dpi
      * values
diff --git a/src/video/x11/SDL_x11shape.c b/src/video/x11/SDL_x11shape.c
index d3d45ec..372db60 100644
--- a/src/video/x11/SDL_x11shape.c
+++ b/src/video/x11/SDL_x11shape.c
@@ -71,7 +71,7 @@ X11_ResizeWindowShape(SDL_Window* window) {
             return SDL_SetError("Could not allocate memory for shaped-window bitmap.");
         }
     }
-    memset(data->bitmap,0,data->bitmapsize);
+    SDL_memset(data->bitmap,0,data->bitmapsize);
 
     window->shaper->userx = window->x;
     window->shaper->usery = window->y;
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index def7ae9..1b3e693 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -737,9 +737,9 @@ X11_SetWindowTitle(_THIS, SDL_Window * window)
     Atom _NET_WM_NAME = data->videodata->_NET_WM_NAME;
     Atom WM_NAME = data->videodata->WM_NAME;
 
-    X11_XChangeProperty(display, data->xwindow, WM_NAME, UTF8_STRING, 8, 0, (const unsigned char *) title, strlen(title));
+    X11_XChangeProperty(display, data->xwindow, WM_NAME, UTF8_STRING, 8, 0, (const unsigned char *) title, SDL_strlen(title));
 
-    status = X11_XChangeProperty(display, data->xwindow, _NET_WM_NAME, UTF8_STRING, 8, 0, (const unsigned char *) title, strlen(title));
+    status = X11_XChangeProperty(display, data->xwindow, _NET_WM_NAME, UTF8_STRING, 8, 0, (const unsigned char *) title, SDL_strlen(title));
 
     if (status != 1) {
         char *x11_error = NULL;
diff --git a/src/video/x11/edid-parse.c b/src/video/x11/edid-parse.c
index e22324f..f1ef089 100644
--- a/src/video/x11/edid-parse.c
+++ b/src/video/x11/edid-parse.c
@@ -50,7 +50,7 @@ get_bits (int in, int begin, int end)
 static int
 decode_header (const uchar *edid)
 {
-    if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0)
+    if (SDL_memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0)
 	return TRUE;
     return FALSE;
 }
diff --git a/test/checkkeysthreads.c b/test/checkkeysthreads.c
index e636b71..360e7f5 100644
--- a/test/checkkeysthreads.c
+++ b/test/checkkeysthreads.c
@@ -210,7 +210,7 @@ static int SDLCALL ping_thread(void *ptr)
 {
     int cnt;
     SDL_Event sdlevent;
-    memset(&sdlevent, 0 , sizeof(SDL_Event));
+    SDL_memset(&sdlevent, 0 , sizeof(SDL_Event));
     for (cnt = 0; cnt < 10; ++cnt) {
         fprintf(stderr, "sending event (%d/%d) from thread.\n", cnt + 1, 10); fflush(stderr);
         sdlevent.type = SDL_KEYDOWN;
diff --git a/test/testautomation_sdltest.c b/test/testautomation_sdltest.c
index 1790194..809664d 100644
--- a/test/testautomation_sdltest.c
+++ b/test/testautomation_sdltest.c
@@ -1131,7 +1131,7 @@ sdltest_randomAsciiString(void *arg)
      SDLTest_AssertCheck(len >= 1 && len <= 255, "Validate that result length; expected: len=[1,255], got: %d", (int) len);
      nonAsciiCharacters = 0;
      for (i=0; i<len; i++) {
-       if (iscntrl(result[i])) {
+       if (SDL_iscntrl(result[i])) {
          nonAsciiCharacters++;
        }
      }
@@ -1169,7 +1169,7 @@ sdltest_randomAsciiStringWithMaximumLength(void *arg)
      SDLTest_AssertCheck(len >= 1 && len <= targetLen, "Validate that result length; expected: len=[1,%d], got: %d", (int) targetLen, (int) len);
      nonAsciiCharacters = 0;
      for (i=0; i<len; i++) {
-       if (iscntrl(result[i])) {
+       if (SDL_iscntrl(result[i])) {
          nonAsciiCharacters++;
        }
      }
@@ -1223,7 +1223,7 @@ sdltest_randomAsciiStringOfSize(void *arg)
      SDLTest_AssertCheck(len == targetLen, "Validate that result length; expected: len=%d, got: %d", (int) targetLen, (int) len);
      nonAsciiCharacters = 0;
      for (i=0; i<len; i++) {
-       if (iscntrl(result[i])) {
+       if (SDL_iscntrl(result[i])) {
          nonAsciiCharacters++;
        }
      }
diff --git a/test/testevdev.c b/test/testevdev.c
index 9710972..5ce9537 100644
--- a/test/testevdev.c
+++ b/test/testevdev.c
@@ -961,11 +961,11 @@ run_test(void)
 
         printf("%s...\n", t->name);
 
-        memset(&caps, '\0', sizeof(caps));
-        memcpy(caps.ev, t->ev, sizeof(t->ev));
-        memcpy(caps.keys, t->keys, sizeof(t->keys));
-        memcpy(caps.abs, t->abs, sizeof(t->abs));
-        memcpy(caps.rel, t->rel, sizeof(t->rel));
+        SDL_memset(&caps, '\0', sizeof(caps));
+        SDL_memcpy(caps.ev, t->ev, sizeof(t->ev));
+        SDL_memcpy(caps.keys, t->keys, sizeof(t->keys));
+        SDL_memcpy(caps.abs, t->abs, sizeof(t->abs));
+        SDL_memcpy(caps.rel, t->rel, sizeof(t->rel));
 
         for (j = 0; j < SDL_arraysize(caps.ev); j++) {
             caps.ev[j] = SwapLongLE(caps.ev[j]);
diff --git a/test/testgl2.c b/test/testgl2.c
index 5056104..94c21c5 100644
--- a/test/testgl2.c
+++ b/test/testgl2.c
@@ -238,10 +238,10 @@ main(int argc, char *argv[])
         consumed = SDLTest_CommonArg(state, i);
         if (consumed == 0) {
             if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
-                fsaa = atoi(argv[i+1]);
+                fsaa = SDL_atoi(argv[i+1]);
                 consumed = 2;
             } else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
-                accel = atoi(argv[i+1]);
+                accel = SDL_atoi(argv[i+1]);
                 consumed = 2;
             } else {
                 consumed = -1;
diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c
index 3143626..4a63863 100644
--- a/test/testgles2_sdf.c
+++ b/test/testgles2_sdf.c
@@ -163,8 +163,8 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
 }
 
 /* Notes on a_angle:
-   * It is a vector containing sin and cos for rotation matrix
-   * To get correct rotation for most cases when a_angle is disabled cos
+   * It is a vector containing sine and cosine for rotation matrix
+   * To get correct rotation for most cases when a_angle is disabled SDL_cos
      value is decremented by 1.0 to get proper output with 0.0 which is
      default value
 */
diff --git a/test/testhaptic.c b/test/testhaptic.c
index 9613629..74be9e0 100644
--- a/test/testhaptic.c
+++ b/test/testhaptic.c
@@ -14,10 +14,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 /*
  * includes
  */
-#include <stdlib.h>
-#include <string.h>             /* strstr */
-#include <ctype.h>              /* isdigit */
-
 #include "SDL.h"
 
 #ifndef SDL_HAPTIC_DISABLED
@@ -55,7 +51,7 @@ main(int argc, char **argv)
     index = -1;
     if (argc > 1) {
         name = argv[1];
-        if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
+        if ((SDL_strcmp(name, "--help") == 0) || (SDL_strcmp(name, "-h") == 0)) {
             SDL_Log("USAGE: %s [device]\n"
                    "If device is a two-digit number it'll use it as an index, otherwise\n"
                    "it'll use it as if it were part of the device's name.\n",
@@ -63,9 +59,9 @@ main(int argc, char **argv)
             return 0;
         }
 
-        i = strlen(name);
-        if ((i < 3) && isdigit(name[0]) && ((i == 1) || isdigit(name[1]))) {
-            index = atoi(name);
+        i = SDL_strlen(name);
+        if ((i < 3) && SDL_isdigit(name[0]) && ((i == 1) || SDL_isdigit(name[1]))) {
+            index = SDL_atoi(name);
             name = NULL;
         }
     }
@@ -82,7 +78,7 @@ main(int argc, char **argv)
         /* Try to find matching device */
         else {
             for (i = 0; i < SDL_NumHaptics(); i++) {
-                if (strstr(SDL_HapticName(i), name) != NULL)
+                if (SDL_strstr(SDL_HapticName(i), name) != NULL)
                     break;
             }
 
@@ -110,7 +106,7 @@ main(int argc, char **argv)
     SDL_ClearError();
 
     /* Create effects. */
-    memset(&efx, 0, sizeof(efx));
+    SDL_memset(&efx, 0, sizeof(efx));
     nefx = 0;
     supported = SDL_HapticQuery(haptic);
 
diff --git a/test/testime.c b/test/testime.c
index 125bedc..73fc817 100644
--- a/test/testime.c
+++ b/test/testime.c
@@ -648,12 +648,12 @@ int main(int argc, char *argv[])
     }
     for (argc--, argv++; argc > 0; argc--, argv++)
     {
-        if (strcmp(argv[0], "--help") == 0) {
+        if (SDL_strcmp(argv[0], "--help") == 0) {
             usage();
             return 0;
         }
 
-        else if (strcmp(argv[0], "--font") == 0)
+        else if (SDL_strcmp(argv[0], "--font") == 0)
         {
             argc--;
             argv++;
diff --git a/test/testloadso.c b/test/testloadso.c
index 5e138c6..5b51c47 100644
--- a/test/testloadso.c
+++ b/test/testloadso.c
@@ -44,7 +44,7 @@ main(int argc, char *argv[])
         return 2;
     }
 
-    if (strcmp(argv[1], "--hello") == 0) {
+    if (SDL_strcmp(argv[1], "--hello") == 0) {
         hello = 1;
         libname = argv[2];
         symname = "puts";
diff --git a/test/testrumble.c b/test/testrumble.c
index 1dfcbe5..868e95e 100644
--- a/test/testrumble.c
+++ b/test/testrumble.c
@@ -25,10 +25,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 /*
  * includes
  */
-#include <stdlib.h>
-#include <string.h>             /* strstr */
-#include <ctype.h>              /* isdigit */
-
 #include "SDL.h"
 
 #ifndef SDL_HAPTIC_DISABLED
@@ -56,7 +52,7 @@ main(int argc, char **argv)
     if (argc > 1) {
         size_t l;
         name = argv[1];
-        if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
+        if ((SDL_strcmp(name, "--help") == 0) || (SDL_strcmp(name, "-h") == 0)) {
             SDL_Log("USAGE: %s [device]\n"
                    "If device is a two-digit number it'll use it as an index, otherwise\n"
                    "it'll use it as if it were part of the device's name.\n",
@@ -83,7 +79,7 @@ main(int argc, char **argv)
         /* Try to find matching device */
         else {
             for (i = 0; i < SDL_NumHaptics(); i++) {
-                if (strstr(SDL_HapticName(i), name) != NULL)
+                if (SDL_strstr(SDL_HapticName(i), name) != NULL)
                     break;
             }
 
diff --git a/test/testsem.c b/test/testsem.c
index 6a76280..e8721dc 100644
--- a/test/testsem.c
+++ b/test/testsem.c
@@ -262,7 +262,7 @@ main(int argc, char **argv)
     signal(SIGTERM, killed);
     signal(SIGINT, killed);
 
-    init_sem = atoi(argv[1]);
+    init_sem = SDL_atoi(argv[1]);
     if (init_sem > 0) {
         TestRealWorld(init_sem);
     }
diff --git a/test/testtimer.c b/test/testtimer.c
index fe30ab5..fbf3f66 100644
--- a/test/testtimer.c
+++ b/test/testtimer.c
@@ -72,7 +72,7 @@ main(int argc, char *argv[])
     /* Start the timer */
     desired = 0;
     if (argv[1]) {
-        desired = atoi(argv[1]);
+        desired = SDL_atoi(argv[1]);
     }
     if (desired == 0) {
         desired = DEFAULT_RESOLUTION;
diff --git a/test/testyuv_cvt.c b/test/testyuv_cvt.c
index 3dc18b7..31844c2 100644
--- a/test/testyuv_cvt.c
+++ b/test/testyuv_cvt.c
@@ -31,9 +31,9 @@ static void RGBtoYUV(Uint8 * rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int mo
         // This formula is from Microsoft's documentation:
         // https://msdn.microsoft.com/en-us/library/windows/desktop/dd206750(v=vs.85).aspx
         // L = Kr * R + Kb * B + (1 - Kr - Kb) * G
-        // Y =                   floor(2^(M-8) * (219*(L-Z)/S + 16) + 0.5);
-        // U = clip3(0, (2^M)-1, floor(2^(M-8) * (112*(B-L) / ((1-Kb)*S) + 128) + 0.5));
-        // V = clip3(0, (2^M)-1, floor(2^(M-8) * (112*(R-L) / ((1-Kr)*S) + 128) + 0.5));
+        // Y =                   SDL_floor(2^(M-8) * (219*(L-Z)/S + 16) + 0.5);
+        // U = clip3(0, (2^M)-1, SDL_floor(2^(M-8) * (112*(B-L) / ((1-Kb)*S) + 128) + 0.5));
+        // V = clip3(0, (2^M)-1, SDL_floor(2^(M-8) * (112*(R-L) / ((1-Kr)*S) + 128) + 0.5));
         float S, Z, R, G, B, L, Kr, Kb, Y, U, V;
 
         if (mode == SDL_YUV_CONVERSION_BT709) {