Logo Search packages:      
Sourcecode: sam2p version File versions

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

appends at most `n' chars, no trailing ''. This is different from ANSI (old and C99) stdio.h, because those insert at most `n-1' chars (not counting the ''), _and_ a trailing ''. Truncates the output to `n' chars if it would be longer. (Truncation semantics changed at Tue Jun 11 14:27:12 CEST 2002. Old: truncate to no chars if longer)

Reimplemented from GenBuffer::Writable.

Definition at line 74 of file gensio.cpp.

References vi_grow2().

Referenced by format(), Files::FILEW::vformat(), and GenBuffer::Writable::vformat().

                                                                            {
  /* Imp: test this code in various systems and architectures. */
  /* Dat: vsnprintf semantics are verified in configure AC_PTS_HAVE_VSNPRINTF,
   * and a replacement vsnprintf is provided in case of problems. We don't
   * depend on HAVE_PTS_VSNPRINTF_C99, because C99-vsnprintf is a run-time
   * property.
   *
   * C99 vsnprintf semantics: vsnprintf() always returns a non-negative value:
   *   the number of characters (trailing \0 not included) that would have been
   *   printed if there were enough space. Only the first maxlen (@param)
   *   characters may be modified. The output is terminated by \0 iff maxlen!=0.
   *   NULL @param dststr is OK iff maxlen==0. Since glibc 2.1.
   * old vsnprintf semantics: vsnprintf() returns a non-negative value or -1:
   *   0 if maxlen==0, otherwise: -1 if maxlen is shorter than all the characters
   *   plus the trailing \0, otherwise: the number of characters (trailing \0 not
   *   included) that were printed. Only the first maxlen (@param)
   *   characters may be modified. The output is terminated by \0 iff maxlen!=0.
   *   NULL @param dststr is OK iff maxlen==0.
   */
  if (n>0) { /* avoid problems with old-style vsnprintf */
    char *s; vi_grow2(0, n+1, 0, &s); len-=n+1; /* +1: sprintf appends '\0' */
    const_cast<char*>(beg)[len]='\0'; /* failsafe sentinel */
    slen_t did=VSNPRINTF(s, n+1, fmt, ap);
    if (did>n) did=n;
    /* ^^^ Dat: always true: (unsigned)-1>n, so this works with both old and c99 */
    /* Now: did contains the # chars to append, without trailing '\0' */
    /* Dat: we cannot check for -1, because `did' is unsigned */
    /* Dat: trailer '\0' doesn't count into `did' */
    len+=did;
  }
  return *this;
}


Generated by  Doxygen 1.6.0   Back to index