git-p4: Handle Windows EOLs properly after removal of p4 submit template handling.
[alt-git.git] / compat / snprintf.c
blobdbfc2d6b6e2bc115e9976c231ae9d8fef7b2e086
1 #include "../git-compat-util.h"
3 #undef vsnprintf
4 int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
6 char *s;
7 int ret;
9 ret = vsnprintf(str, maxsize, format, ap);
10 if (ret != -1)
11 return ret;
13 s = NULL;
14 if (maxsize < 128)
15 maxsize = 128;
17 while (ret == -1) {
18 maxsize *= 4;
19 str = realloc(s, maxsize);
20 if (! str)
21 break;
22 s = str;
23 ret = vsnprintf(str, maxsize, format, ap);
25 free(s);
26 return ret;
29 int git_snprintf(char *str, size_t maxsize, const char *format, ...)
31 va_list ap;
32 int ret;
34 va_start(ap, format);
35 ret = git_vsnprintf(str, maxsize, format, ap);
36 va_end(ap);
38 return ret;