|
@@ -1095,25 +1095,55 @@ int32_t llama_chat_apply_template(
|
|
|
// model split
|
|
// model split
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
-int llama_split_path(char * split_path, size_t maxlen, const char * path_prefix, int split_no, int split_count) {
|
|
|
|
|
|
|
+int32_t llama_split_path(
|
|
|
|
|
+ char * split_path,
|
|
|
|
|
+ size_t maxlen,
|
|
|
|
|
+ const char * path_prefix,
|
|
|
|
|
+ int32_t split_no,
|
|
|
|
|
+ int32_t split_count) {
|
|
|
|
|
+
|
|
|
static const char * const SPLIT_PATH_FORMAT = "%s-%05d-of-%05d.gguf";
|
|
static const char * const SPLIT_PATH_FORMAT = "%s-%05d-of-%05d.gguf";
|
|
|
- if (snprintf(split_path, maxlen, SPLIT_PATH_FORMAT, path_prefix, split_no + 1, split_count)) {
|
|
|
|
|
- return strlen(split_path);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const int written = snprintf(
|
|
|
|
|
+ split_path,
|
|
|
|
|
+ maxlen,
|
|
|
|
|
+ SPLIT_PATH_FORMAT,
|
|
|
|
|
+ path_prefix,
|
|
|
|
|
+ split_no + 1,
|
|
|
|
|
+ split_count
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (written < 0 || (size_t) written >= maxlen) {
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
- return 0;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return (int32_t) written;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int llama_split_prefix(char * split_prefix, size_t maxlen, const char * split_path, int split_no, int split_count) {
|
|
|
|
|
- std::string str_split_path(split_path);
|
|
|
|
|
|
|
+int32_t llama_split_prefix(
|
|
|
|
|
+ char * split_prefix,
|
|
|
|
|
+ size_t maxlen,
|
|
|
|
|
+ const char * split_path,
|
|
|
|
|
+ int32_t split_no,
|
|
|
|
|
+ int32_t split_count) {
|
|
|
|
|
+
|
|
|
|
|
+ const std::string str_split_path(split_path);
|
|
|
|
|
+
|
|
|
char postfix[32];
|
|
char postfix[32];
|
|
|
- snprintf(postfix, 32, "-%05d-of-%05d.gguf", split_no + 1, split_count);
|
|
|
|
|
- std::string str_postfix(postfix);
|
|
|
|
|
-
|
|
|
|
|
- // check if split_prefix ends with postfix
|
|
|
|
|
- int size_prefix = str_split_path.size() - str_postfix.size();
|
|
|
|
|
- if (size_prefix > 0 && str_split_path.find(str_postfix, size_prefix) != std::string::npos) {
|
|
|
|
|
- snprintf(split_prefix, std::min((size_t) size_prefix + 1, maxlen), "%s", split_path);
|
|
|
|
|
- return size_prefix;
|
|
|
|
|
|
|
+ snprintf(postfix, sizeof(postfix), "-%05d-of-%05d.gguf", split_no + 1, split_count);
|
|
|
|
|
+
|
|
|
|
|
+ const std::string str_postfix(postfix);
|
|
|
|
|
+ if (str_split_path.size() <= str_postfix.size()) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const size_t size_prefix = str_split_path.size() - str_postfix.size();
|
|
|
|
|
+
|
|
|
|
|
+ if (str_split_path.compare(size_prefix, std::string::npos, str_postfix) == 0) {
|
|
|
|
|
+ const size_t copy_len = std::min(size_prefix + 1, maxlen);
|
|
|
|
|
+ snprintf(split_prefix, copy_len, "%s", split_path);
|
|
|
|
|
+
|
|
|
|
|
+ return (int32_t) size_prefix;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|