SDL_image: Removed C runtime dependency from testimage

From 120bce1eaf893e65c248c268c9c75ab07dd52650 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 25 May 2022 09:47:24 -0700
Subject: [PATCH] Removed C runtime dependency from testimage

---
 test/main.c | 59 ++++++++++++++++++++++++-----------------------------
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/test/main.c b/test/main.c
index 45b7d3b..3946ff3 100644
--- a/test/main.c
+++ b/test/main.c
@@ -13,11 +13,6 @@
 
 #include "SDL_image.h"
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-
 #include "SDL.h"
 #include "SDL_test.h"
 
@@ -489,11 +484,11 @@ static const Format formats[] =
 static SDL_bool
 StrHasSuffix(const char *str, const char *suffix)
 {
-    size_t str_len = strlen(str);
-    size_t suffix_len = strlen(suffix);
+    size_t str_len = SDL_strlen(str);
+    size_t suffix_len = SDL_strlen(suffix);
 
     return (str_len >= suffix_len
-            && strcmp(str + (str_len - suffix_len), suffix) == 0);
+            && SDL_strcmp(str + (str_len - suffix_len), suffix) == 0);
 }
 
 typedef enum
@@ -533,7 +528,7 @@ DumpPixels(const char *filename, SDL_Surface *surface)
     size_t w, h, pitch;
     size_t i, j;
 
-    fprintf(stderr, "%s:\n", filename);
+    SDL_Log("%s:\n", filename);
 
     if (surface->format->palette) {
         size_t n = 0;
@@ -542,9 +537,9 @@ DumpPixels(const char *filename, SDL_Surface *surface)
             n = (size_t) surface->format->palette->ncolors;
         }
 
-        fprintf(stderr, "  Palette:\n");
+        SDL_Log("  Palette:\n");
         for (i = 0; i < n; i++) {
-            fprintf(stderr, "    RGBA[0x%02x] = %02x%02x%02x%02x\n",
+            SDL_Log("    RGBA[0x%02x] = %02x%02x%02x%02x\n",
                     (unsigned) i,
                     surface->format->palette->colors[i].r,
                     surface->format->palette->colors[i].g,
@@ -554,17 +549,17 @@ DumpPixels(const char *filename, SDL_Surface *surface)
     }
 
     if (surface->w < 0) {
-        fprintf(stderr, "    Invalid width %d\n", surface->w);
+        SDL_Log("    Invalid width %d\n", surface->w);
         return;
     }
 
     if (surface->h < 0) {
-        fprintf(stderr, "    Invalid height %d\n", surface->h);
+        SDL_Log("    Invalid height %d\n", surface->h);
         return;
     }
 
     if (surface->pitch < 0) {
-        fprintf(stderr, "    Invalid pitch %d\n", surface->pitch);
+        SDL_Log("    Invalid pitch %d\n", surface->pitch);
         return;
     }
 
@@ -572,10 +567,10 @@ DumpPixels(const char *filename, SDL_Surface *surface)
     h = (size_t) surface->h;
     pitch = (size_t) surface->pitch;
 
-    fprintf(stderr, "  Pixels:\n");
+    SDL_Log("  Pixels:\n");
 
     for (j = 0; j < h; j++) {
-        fprintf(stderr, "    ");
+        SDL_Log("    ");
 
         for (i = 0; i < w; i++) {
             p = pixels + (j * pitch) + (i * surface->format->BytesPerPixel);
@@ -584,32 +579,32 @@ DumpPixels(const char *filename, SDL_Surface *surface)
                 case 1:
                 case 4:
                 case 8:
-                    fprintf(stderr, "%02x ", *p);
+                    SDL_Log("%02x ", *p);
                     break;
 
                 case 12:
                 case 15:
                 case 16:
-                    fprintf(stderr, "%02x", *p++);
-                    fprintf(stderr, "%02x ", *p);
+                    SDL_Log("%02x", *p++);
+                    SDL_Log("%02x ", *p);
                     break;
 
                 case 24:
-                    fprintf(stderr, "%02x", *p++);
-                    fprintf(stderr, "%02x", *p++);
-                    fprintf(stderr, "%02x ", *p);
+                    SDL_Log("%02x", *p++);
+                    SDL_Log("%02x", *p++);
+                    SDL_Log("%02x ", *p);
                     break;
 
                 case 32:
-                    fprintf(stderr, "%02x", *p++);
-                    fprintf(stderr, "%02x", *p++);
-                    fprintf(stderr, "%02x", *p++);
-                    fprintf(stderr, "%02x ", *p);
+                    SDL_Log("%02x", *p++);
+                    SDL_Log("%02x", *p++);
+                    SDL_Log("%02x", *p++);
+                    SDL_Log("%02x ", *p);
                     break;
             }
         }
 
-        fprintf(stderr, "\n");
+        SDL_Log("\n");
     }
 }
 
@@ -721,7 +716,7 @@ FormatLoadTest(const Format *format,
             break;
 
         case LOAD_SIZED:
-            if (strcmp(format->name, "SVG-sized") == 0) {
+            if (SDL_strcmp(format->name, "SVG-sized") == 0) {
                 surface = IMG_LoadSizedSVG_RW(src, 64, 64);
             }
             break;
@@ -820,7 +815,7 @@ FormatSaveTest(const Format *format,
                             format->initFlag, initResult);
     }
 
-    if (strcmp (format->name, "PNG") == 0) {
+    if (SDL_strcmp (format->name, "PNG") == 0) {
         if (rw) {
             dest = SDL_RWFromFile(filename, "wb");
             result = IMG_SavePNG_RW(reference, dest, SDL_FALSE);
@@ -828,7 +823,7 @@ FormatSaveTest(const Format *format,
         } else {
             result = IMG_SavePNG(reference, filename);
         }
-    } else if (strcmp(format->name, "JPG") == 0) {
+    } else if (SDL_strcmp(format->name, "JPG") == 0) {
         if (rw) {
             dest = SDL_RWFromFile(filename, "wb");
             result = IMG_SaveJPG_RW(reference, dest, SDL_FALSE, 90);
@@ -904,12 +899,12 @@ FormatTest(const Format *format)
     if (format->canLoad || forced) {
         SDLTest_Log("Testing ability to load format %s", format->name);
 
-        if (strcmp(format->name, "SVG-sized") == 0) {
+        if (SDL_strcmp(format->name, "SVG-sized") == 0) {
             FormatLoadTest(format, LOAD_SIZED);
         } else {
             FormatLoadTest(format, LOAD_CONVENIENCE);
 
-            if (strcmp(format->name, "TGA") == 0) {
+            if (SDL_strcmp(format->name, "TGA") == 0) {
                 SDLTest_Log("SKIP: Recognising %s by magic number is not supported", format->name);
             } else {
                 FormatLoadTest(format, LOAD_RW);