From b5fe41f41a88f3763d02db4f2dfa7e13617e9fc3 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 4 Feb 2020 16:55:24 +0100 Subject: 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 --- src/core.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 252b7e0e..dca411ae 100644 --- a/src/core.c +++ b/src/core.c @@ -151,14 +151,12 @@ #define SUPPORT_HIGH_DPI // Force HighDPI support on macOS #endif -#include // Standard input / output lib #include // Required for: srand(), rand(), atexit() -#include // Required for: typedef unsigned long long int uint64_t, used by hi-res timer +#include // Required for: FILE, fopen(), fseek(), fread(), fwrite(), fclose() [Used in StorageSaveValue()/StorageLoadValue()] +#include // Required for: strrchr(), strcmp(), strlen() #include // Required for: time() - Android/RPI hi-res timer (NOTE: Linux only!) -#include // Required for: tan() [Used in BeginMode3D() to set perspective] -#include // Required for: strrchr(), strcmp() -//#include // Macros for reporting and retrieving error conditions through error codes -#include // Required for: tolower() [Used in IsFileExtension()] +#include // Required for: tan() [Used in BeginMode3D()] + #include // Required for stat() [Used in GetLastWriteTime()] #if (defined(PLATFORM_DESKTOP) || defined(PLATFORM_UWP)) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__)) @@ -1635,7 +1633,7 @@ double GetTime(void) #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); - uint64_t time = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec; + unsigned long long int time = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec; return (double)(time - CORE.Time.base)*1e-9; // Elapsed time since InitTimer() #endif @@ -2205,7 +2203,7 @@ int StorageLoadValue(int position) // Get file size fseek(storageFile, 0, SEEK_END); int fileSize = ftell(storageFile); // Size in bytes - rewind(storageFile); + fseek(storageFile, 0, SEEK_SET); // Reset file pointer if (fileSize < (position*4)) TRACELOG(LOG_WARNING, "Storage position could not be found"); else @@ -3349,7 +3347,7 @@ static void InitTimer(void) if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) // Success { - CORE.Time.base = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec; + CORE.Time.base = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; } else TRACELOG(LOG_WARNING, "No hi-resolution timer available"); #endif -- cgit v1.2.3