Logo Search packages:      
Sourcecode: sam2p version File versions

GenBuffer::Writable & SimBuffer::B::vformat ( char const *  fmt,
va_list  ap 
) [virtual]

appends as many chars as requrested

Reimplemented from GenBuffer::Writable.

Definition at line 106 of file gensio.cpp.

References vi_grow2().

                                                                  {
  char dummy, *s;
  slen_t did=VSNPRINTF(&dummy, 1, fmt, ap), n;
  if (did>0) { /* skip if nothing to be appended */
    /* vvv Dat: we cannot check for -1, because `did' is unsigned */
    if ((did+1)!=(slen_t)0) { /* C99 semantics; quick shortcut */
      vi_grow2(0, (n=did)+1, 0, &s); len-=n+1;
      ASSERT_SIDE2(VSNPRINTF(s, n+1, fmt, ap), * 1U==did);
    } else { /* old semantics: grow the buffer incrementally */
      if ((n=strlen(fmt))<16) n=16; /* initial guess */
      while (1) {
        vi_grow2(0, n+1, 0, &s); len-=n+1; /* +1: sprintf appends '\0' */
        const_cast<char*>(beg)[len]='\0'; /* failsafe sentinel */
        did=VSNPRINTF(s, n+1, fmt, ap);
        if ((did+1)!=(slen_t)0) {
          assert(did!=0); /* 0 is caught early in this function */
          assert(did<=n); /* non-C99 semantics */
          break;
        }
        n<<=1;
      }
    }
    len+=did;
  }
  return *this;
}


Generated by  Doxygen 1.6.0   Back to index