Review libc dependencies and remove when possible

Just for clarification, no plans to remove libc dependency, just did some code analysis to see how much raylib depend on stardard C library. My conclusions:

 - stdlib.h: primary dependency is for malloc() and free()
 - stdio.h: primary dependency is for FILE access, maybe it could go through a custom ABI?
 - string.h: just around 8 functions required
 - math.h: just around 8 functions required
 - others: 1-2 functions required for some other headers
This commit is contained in:
Ray 2020-02-04 16:55:24 +01:00
parent 3cd9e3896a
commit b5fe41f41a
11 changed files with 73 additions and 67 deletions

View file

@ -78,8 +78,6 @@
#include "utils.h" // Required for: fopen() Android mapping
#endif
#if defined(_WIN32)
// @raysan5: To avoid conflicting windows.h symbols with raylib, so flags are defined
// WARNING: Those flags avoid inclusion of some Win32 headers that could be required
@ -163,9 +161,12 @@ typedef struct tagBITMAPINFOHEADER {
#undef PlaySound // Win32 API: windows.h > mmsystem.h defines PlaySound macro
#include <stdlib.h> // Required for: malloc(), free()
#include <string.h> // Required for: strcmp(), strncmp()
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
#if defined(RAUDIO_STANDALONE)
#include <string.h> // Required for: strcmp() [Used in IsFileExtension()]
#endif
#if defined(SUPPORT_FILEFORMAT_OGG)
#define STB_VORBIS_IMPLEMENTATION
#include "external/stb_vorbis.h" // OGG loading functions
@ -1860,8 +1861,14 @@ static Wave LoadWAV(const char *fileName)
fread(&wavRiffHeader, sizeof(WAVRiffHeader), 1, wavFile);
// Check for RIFF and WAVE tags
if (strncmp(wavRiffHeader.chunkID, "RIFF", 4) ||
strncmp(wavRiffHeader.format, "WAVE", 4))
if ((wavRiffHeader.chunkID[0] != 'R') ||
(wavRiffHeader.chunkID[1] != 'I') ||
(wavRiffHeader.chunkID[2] != 'F') ||
(wavRiffHeader.chunkID[3] != 'F') ||
(wavRiffHeader.format[0] != 'W') ||
(wavRiffHeader.format[1] != 'A') ||
(wavRiffHeader.format[2] != 'V') ||
(wavRiffHeader.format[3] != 'E'))
{
TRACELOG(LOG_WARNING, "[%s] Invalid RIFF or WAVE Header", fileName);
}
@ -2037,7 +2044,7 @@ static Wave LoadOGG(const char *fileName)
wave.data = (short *)RL_MALLOC(wave.sampleCount*wave.channels*sizeof(short));
// NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!)
int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, (short *)wave.data, wave.sampleCount*wave.channels);
//int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, (short *)wave.data, wave.sampleCount*wave.channels);
TRACELOGD("[%s] Samples obtained: %i", fileName, numSamplesOgg);