38
38
}
39
39
#endif
40
40
41
- GGML_ATTRIBUTE_FORMAT (1 , 2 )
42
- static std::string fmt(const char * fmt, ...) {
43
- va_list ap;
44
- va_list ap2;
45
- va_start (ap, fmt);
46
- va_copy (ap2, ap);
47
- const int size = vsnprintf (NULL , 0 , fmt, ap);
48
- GGML_ASSERT (size >= 0 && size < INT_MAX); // NOLINT
49
- std::string buf;
50
- buf.resize (size);
51
- const int size2 = vsnprintf (const_cast <char *>(buf.data ()), buf.size () + 1 , fmt, ap2);
52
- GGML_ASSERT (size2 == size);
53
- va_end (ap2);
54
- va_end (ap);
55
-
56
- return buf;
57
- }
58
-
59
41
GGML_ATTRIBUTE_FORMAT (1 , 2 )
60
42
static int printe(const char * fmt, ...) {
61
43
va_list args;
@@ -525,11 +507,11 @@ class HttpClient {
525
507
int secs = static_cast <int >(seconds) % 60 ;
526
508
527
509
if (hrs > 0 ) {
528
- return fmt (" %dh %02dm %02ds" , hrs, mins, secs);
510
+ return string_format (" %dh %02dm %02ds" , hrs, mins, secs);
529
511
} else if (mins > 0 ) {
530
- return fmt (" %dm %02ds" , mins, secs);
512
+ return string_format (" %dm %02ds" , mins, secs);
531
513
} else {
532
- return fmt (" %ds" , secs);
514
+ return string_format (" %ds" , secs);
533
515
}
534
516
}
535
517
@@ -544,7 +526,7 @@ class HttpClient {
544
526
}
545
527
}
546
528
547
- return fmt (" %.2f %s" , dbl_size, suffix[i]);
529
+ return string_format (" %.2f %s" , dbl_size, suffix[i]);
548
530
}
549
531
550
532
static int update_progress (void * ptr, curl_off_t total_to_download, curl_off_t now_downloaded, curl_off_t ,
@@ -578,7 +560,9 @@ class HttpClient {
578
560
return (now_downloaded_plus_file_size * 100 ) / total_to_download;
579
561
}
580
562
581
- static std::string generate_progress_prefix (curl_off_t percentage) { return fmt (" %3ld%% |" , static_cast <long int >(percentage)); }
563
+ static std::string generate_progress_prefix (curl_off_t percentage) {
564
+ return string_format (" %3ld%% |" , static_cast <long int >(percentage));
565
+ }
582
566
583
567
static double calculate_speed (curl_off_t now_downloaded, const std::chrono::steady_clock::time_point & start_time) {
584
568
const auto now = std::chrono::steady_clock::now ();
@@ -589,9 +573,9 @@ class HttpClient {
589
573
static std::string generate_progress_suffix (curl_off_t now_downloaded_plus_file_size, curl_off_t total_to_download,
590
574
double speed, double estimated_time) {
591
575
const int width = 10 ;
592
- return fmt (" %*s/%*s%*s/s%*s" , width, human_readable_size (now_downloaded_plus_file_size).c_str (), width ,
593
- human_readable_size (total_to_download). c_str (), width, human_readable_size (speed ).c_str (), width,
594
- human_readable_time (estimated_time).c_str ());
576
+ return string_format (" %*s/%*s%*s/s%*s" , width, human_readable_size (now_downloaded_plus_file_size).c_str (),
577
+ width, human_readable_size (total_to_download ).c_str (), width,
578
+ human_readable_size (speed). c_str (), width, human_readable_time (estimated_time).c_str ());
595
579
}
596
580
597
581
static int calculate_progress_bar_width (const std::string & progress_prefix, const std::string & progress_suffix) {
0 commit comments