compat / snprintf.con commit bash completion: Don't offer "a.." as a completion for "a." (6c36c9e)
   1#include "../git-compat-util.h"
   2
   3#undef vsnprintf
   4int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
   5{
   6        char *s;
   7        int ret;
   8
   9        ret = vsnprintf(str, maxsize, format, ap);
  10        if (ret != -1)
  11                return ret;
  12
  13        s = NULL;
  14        if (maxsize < 128)
  15                maxsize = 128;
  16
  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);
  24        }
  25        free(s);
  26        return ret;
  27}
  28
  29int git_snprintf(char *str, size_t maxsize, const char *format, ...)
  30{
  31        va_list ap;
  32        int ret;
  33
  34        va_start(ap, format);
  35        ret = git_vsnprintf(str, maxsize, format, ap);
  36        va_end(ap);
  37
  38        return ret;
  39}
  40