Commit 95b09b62b for llama.cpp

commit 95b09b62beb95c40fc6b317a0c1473c27b5f27fa
Author: Adrien Gallouët <angt@huggingface.co>
Date:   Thu Nov 19 08:57:57 2026 +0100

    llama : remove PATH_MAX (#32557)

    Signed-off-by: Adrien Gallouët <angt@huggingface.co>

diff --git a/src/llama-mmap.cpp b/src/llama-mmap.cpp
index 93496c3b7..02e4ede7c 100644
--- a/src/llama-mmap.cpp
+++ b/src/llama-mmap.cpp
@@ -5,7 +5,6 @@
 #include "ggml.h"

 #include <cstring>
-#include <climits>
 #include <cstdlib>
 #include <stdexcept>
 #include <cerrno>
@@ -32,9 +31,6 @@
     #endif
     #include <malloc.h>
     #include <windows.h>
-    #ifndef PATH_MAX
-        #define PATH_MAX MAX_PATH
-    #endif
     #include <io.h>
 #endif

@@ -1140,7 +1136,3 @@ void llama_prefetch(llama_memory_ranges mr) {
     GGML_UNUSED(mr);
 #endif
 }
-
-size_t llama_path_max() {
-    return PATH_MAX;
-}
diff --git a/src/llama-mmap.h b/src/llama-mmap.h
index 6c6393d57..39715bfc3 100644
--- a/src/llama-mmap.h
+++ b/src/llama-mmap.h
@@ -88,5 +88,3 @@ using llama_memory_ranges = std::vector<llama_memory_range>;

 // Prefetch the host pages covering these memory ranges.
 void llama_prefetch(llama_memory_ranges mr);
-
-size_t llama_path_max();
diff --git a/src/llama-model-loader.cpp b/src/llama-model-loader.cpp
index 548ade101..808fb44d8 100644
--- a/src/llama-model-loader.cpp
+++ b/src/llama-model-loader.cpp
@@ -84,7 +84,7 @@ const char * llama_ftype_name(llama_ftype ftype) {
 static std::vector<std::string> llama_get_list_splits(const std::string & path, const int idx, const int n_split) {
     std::vector<std::string> paths;
     std::string split_prefix;
-    std::vector<char> buf(llama_path_max(), 0);
+    std::vector<char> buf(path.size() + 1, 0);

     {
         int ret = llama_split_prefix(buf.data(), buf.size(), path.c_str(), idx, n_split);
@@ -610,7 +610,7 @@ llama_model_loader::llama_model_loader(
                 throw std::runtime_error(format("illegal split file idx: %d (file: %s), model must be loaded with the first split", idx, fname.c_str()));
             }

-            std::vector<char> prefix(llama_path_max(), 0);
+            std::vector<char> prefix(fname.size() + 1, 0);
             if (paths.empty() || llama_split_prefix(prefix.data(), prefix.size(), fname.c_str(), idx, n_split)) {
                 auto backbone = llama_get_list_splits(fname, idx, n_split);
                 auto file_name = [](const std::string & path) {
diff --git a/src/llama-quant.cpp b/src/llama-quant.cpp
index 0f3f982b0..79d964972 100644
--- a/src/llama-quant.cpp
+++ b/src/llama-quant.cpp
@@ -1266,7 +1266,7 @@ static void llama_model_quantize_impl(const std::string & fname_inp, const std::
         GGML_ASSERT(ctx_outs[cur_split] && "Find uninitialized gguf_context");
         std::string fname = fname_out;
         if (params->keep_split) {
-            std::vector<char> split_path(llama_path_max(), 0);
+            std::vector<char> split_path(fname_out.size() + sizeof("-00000-of-00000.gguf"), 0);
             llama_split_path(split_path.data(), split_path.size(), fname_out.c_str(), cur_split, n_split);
             fname = std::string(split_path.data());
         }