From 9bad248b549379a02ac6167f9369cd4370295124 Mon Sep 17 00:00:00 2001
From: Michael Vetter <jubalh@iodoru.org>
Date: Thu, 25 Oct 2018 16:09:38 +0200
Subject: [PATCH 1/3] Use filepath define

On Linux systems the length of the path is defined in linux/limits.h as
PATH_MAX.
Lets use that for MAX_FILEPATH_LENGTH, which is a define that we can
find in some comments in the code that is actually never used. Instead
often we see 256 handwritten.
So lets have MAX_FILEPATH_LENGTH as a proper define, being set to
PATH_MAX on Linux and to 256 on Windows systems.
---
 src/core.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/core.c b/src/core.c
index ffbf110e8..993e4e834 100644
--- a/src/core.c
+++ b/src/core.c
@@ -158,6 +158,8 @@
             unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
             unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
         #endif
+
+        #define MAX_FILEPATH_LENGTH 256
     #elif defined(__linux__)
         #include <sys/time.h>           // Required for: timespec, nanosleep(), select() - POSIX
         
@@ -172,6 +174,9 @@
         //#define GLFW_EXPOSE_NATIVE_COCOA      // WARNING: Fails due to type redefinition
         #define GLFW_EXPOSE_NATIVE_NSGL
         #include <GLFW/glfw3native.h>   // Required for: glfwGetCocoaWindow(), glfwGetNSGLContext()
+
+        #include <linux/limits.h> // for NAME_MAX and PATH_MAX defines
+        #define MAX_FILEPATH_LENGTH PATH_MAX // Use Linux define (4096)
     #endif
 #endif
 
@@ -1596,8 +1601,8 @@ const char *GetFileNameWithoutExt(const char *filePath)
 const char *GetDirectoryPath(const char *fileName)
 {
     const char *lastSlash = NULL;
-    static char filePath[256];      // MAX_DIRECTORY_PATH_SIZE = 256
-    memset(filePath, 0, 256);
+    static char filePath[MAX_FILEPATH_LENGTH];
+    memset(filePath, 0, MAX_FILEPATH_LENGTH);
 
     lastSlash = strprbrk(fileName, "\\/");
     if (!lastSlash) return NULL;
@@ -1612,10 +1617,10 @@ const char *GetDirectoryPath(const char *fileName)
 // Get current working directory
 const char *GetWorkingDirectory(void)
 {
-    static char currentDir[256];    // MAX_DIRECTORY_PATH_SIZE = 256
-    memset(currentDir, 0, 256);
+    static char currentDir[MAX_FILEPATH_LENGTH];
+    memset(currentDir, 0, MAX_FILEPATH_LENGTH);
     
-    GETCWD(currentDir, 256 - 1);
+    GETCWD(currentDir, MAX_FILEPATH_LENGTH - 1);
     
     return currentDir;
 }
@@ -1624,7 +1629,6 @@ const char *GetWorkingDirectory(void)
 // NOTE: Files count is returned by parameters pointer
 char **GetDirectoryFiles(const char *dirPath, int *fileCount)
 {
-    #define MAX_FILEPATH_LENGTH     256
     #define MAX_DIRECTORY_FILES     512
     
     ClearDirectoryFiles();
@@ -3289,7 +3293,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
 
     for (int i = 0; i < count; i++)
     {
-        dropFilesPath[i] = (char *)malloc(sizeof(char)*256);     // Max path length set to 256 char
+        dropFilesPath[i] = (char *)malloc(sizeof(char)*MAX_FILEPATH_LENGTH);     // Max path length using MAX_FILEPATH_LENGTH set to 256 char
         strcpy(dropFilesPath[i], paths[i]);
     }
 
@@ -3862,7 +3866,7 @@ static void RestoreKeyboard(void)
 // Mouse initialization (including mouse thread)
 static void InitMouse(void)
 {
-    char Path[256];
+    char Path[MAX_FILEPATH_LENGTH];
     DIR *directory;
     struct dirent *entity;
 

From 65b5de962d47e65876368499883cf2aa286c5617 Mon Sep 17 00:00:00 2001
From: Michael Vetter <jubalh@iodoru.org>
Date: Thu, 25 Oct 2018 16:16:44 +0200
Subject: [PATCH 2/3] Use seperate blog for MAX_FILEPATH_LENGTH define

Let's have a seperate if linux block for this. Since we will need to
define MAX_FILEPATH_LENGTH for all other cases. And its more readable
like this.
---
 src/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/core.c b/src/core.c
index 993e4e834..a324bf0f6 100644
--- a/src/core.c
+++ b/src/core.c
@@ -159,7 +159,6 @@
             unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
         #endif
 
-        #define MAX_FILEPATH_LENGTH 256
     #elif defined(__linux__)
         #include <sys/time.h>           // Required for: timespec, nanosleep(), select() - POSIX
         
@@ -175,9 +174,14 @@
         #define GLFW_EXPOSE_NATIVE_NSGL
         #include <GLFW/glfw3native.h>   // Required for: glfwGetCocoaWindow(), glfwGetNSGLContext()
 
+    #endif
+#endif
+
+#if defined(__linux__)
         #include <linux/limits.h> // for NAME_MAX and PATH_MAX defines
         #define MAX_FILEPATH_LENGTH PATH_MAX // Use Linux define (4096)
-    #endif
+#else
+        #define MAX_FILEPATH_LENGTH 256 // Use common value
 #endif
 
 #if defined(PLATFORM_ANDROID)

From b13c9716e48baac89a72d2c394b297b79e7384ef Mon Sep 17 00:00:00 2001
From: Michael Vetter <jubalh@iodoru.org>
Date: Thu, 25 Oct 2018 16:18:44 +0200
Subject: [PATCH 3/3] Fix GetDirectoryFiles description

The comment sais it allows max 256 files, but the MAX_DIRECTORY_FILES
define actually is set to 512.
---
 src/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/core.c b/src/core.c
index a324bf0f6..af601e1d8 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1629,7 +1629,7 @@ const char *GetWorkingDirectory(void)
     return currentDir;
 }
 
-// Get filenames in a directory path (max 256 files)
+// Get filenames in a directory path (max 512 files)
 // NOTE: Files count is returned by parameters pointer
 char **GetDirectoryFiles(const char *dirPath, int *fileCount)
 {