فهرست منبع

ADDED: UnloadFileData() / UnloadFileText() #1440

Ray 4 سال پیش
والد
کامیت
d360a49f36
2فایلهای تغییر یافته به همراه14 افزوده شده و 0 حذف شده
  1. 2 0
      src/raylib.h
  2. 12 0
      src/utils.c

+ 2 - 0
src/raylib.h

@@ -974,8 +974,10 @@ RLAPI int GetRandomValue(int min, int max);                       // Returns a r
 
 
 // Files management functions
 // Files management functions
 RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead);     // Load file data as byte array (read)
 RLAPI unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead);     // Load file data as byte array (read)
+RLAPI void UnloadFileData(unsigned char *data);                   // Unload file data allocated by LoadFileData()
 RLAPI bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite); // Save data to file from byte array (write), returns true on success
 RLAPI bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite); // Save data to file from byte array (write), returns true on success
 RLAPI char *LoadFileText(const char *fileName);                   // Load text data from file (read), returns a '\0' terminated string
 RLAPI char *LoadFileText(const char *fileName);                   // Load text data from file (read), returns a '\0' terminated string
+RLAPI void UnloadFileText(unsigned char *text);                   // Unload file text data allocated by LoadFileText()
 RLAPI bool SaveFileText(const char *fileName, char *text);        // Save text data to file (write), string must be '\0' terminated, returns true on success
 RLAPI bool SaveFileText(const char *fileName, char *text);        // Save text data to file (write), string must be '\0' terminated, returns true on success
 RLAPI bool FileExists(const char *fileName);                      // Check if file exists
 RLAPI bool FileExists(const char *fileName);                      // Check if file exists
 RLAPI bool DirectoryExists(const char *dirPath);                  // Check if a directory path exists
 RLAPI bool DirectoryExists(const char *dirPath);                  // Check if a directory path exists

+ 12 - 0
src/utils.c

@@ -203,6 +203,12 @@ unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead)
     return data;
     return data;
 }
 }
 
 
+// Unload file data allocated by LoadFileData()
+void UnloadFileData(unsigned char *data)
+{
+    RL_FREE(data);
+}
+
 // Save data to file from buffer
 // Save data to file from buffer
 bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite)
 bool SaveFileData(const char *fileName, void *data, unsigned int bytesToWrite)
 {
 {
@@ -274,6 +280,12 @@ char *LoadFileText(const char *fileName)
     return text;
     return text;
 }
 }
 
 
+// Unload file text data allocated by LoadFileText()
+void UnloadFileText(unsigned char *text)
+{
+    RL_FREE(text);
+}
+
 // Save text data to file (write), string must be '\0' terminated
 // Save text data to file (write), string must be '\0' terminated
 bool SaveFileText(const char *fileName, char *text)
 bool SaveFileText(const char *fileName, char *text)
 {
 {