Esempio n. 1
0
int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...) {
  va_list ap;
  int str_l;

  *ptr = NULL;
  va_start(ap, fmt);                            /* measure the required size */
  str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap);
  va_end(ap);
  assert(str_l >= 0);        /* possible integer overflow if str_m > INT_MAX */
  if ((size_t)str_l + 1 < str_m) str_m = (size_t)str_l + 1;      /* truncate */
  /* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
  if (str_m == 0) {  /* not interested in resulting string, just return size */
  } else {
    *ptr = (char *) malloc(str_m);
    if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
    else {
      int str_l2;
      va_start(ap, fmt);
      str_l2 = portable_vsnprintf(*ptr, str_m, fmt, ap);
      va_end(ap);
      assert(str_l2 == str_l);
    }
  }
  return str_l;
}
Esempio n. 2
0
void BenchmarkResult::write(
    const BenchmarkSuite&   benchmark_suite,
    const IBenchmarkCase&   benchmark_case,
    const char*             file,
    const size_t            line,
    PRINTF_FMT const char*  format, ...)
{
    // Size in bytes of the temporary message buffer.
    const size_t BufferSize = 4096;

    // Print the formatted message into the temporary buffer.
    va_list argptr;
    va_start(argptr, format);
    char message[BufferSize];
    portable_vsnprintf(message, BufferSize, format, argptr);

    // Send the message to all the listeners.
    for (each<Impl::BenchmarkListenerContainer> i = impl->m_listeners; i; ++i)
    {
        (*i)->write(
            benchmark_suite,
            benchmark_case,
            file,
            line,
            message);
    }
}
void TestListenerHelper::write(
    ITestListener&                      test_listener,
    const TestSuite&                    test_suite,
    const char*                         test_case_name,
    const char*                         file,
    const size_t                        line,
    const TestMessage::Type             message_type,
    APPLESEED_PRINTF_FMT const char*    format, ...)
{
    // Size in bytes of the temporary message buffer.
    const size_t BufferSize = 4096;

    // Print the formatted message into the temporary buffer.
    va_list argptr;
    va_start(argptr, format);
    char message[BufferSize];
    portable_vsnprintf(message, BufferSize, format, argptr);

    // Forward the message to the test listener.
    test_listener.write(
        test_suite,
        test_case_name,
        file,
        line,
        message_type,
        message);
}
Esempio n. 4
0
int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...) {
  va_list ap;
  int str_l;

  va_start(ap, fmt);
  str_l = portable_vsnprintf(str, str_m, fmt, ap);
  va_end(ap);
  return str_l;
}
Esempio n. 5
0
int vasprintf(char **ptr, const char *fmt, va_list ap) {
  size_t str_m;
  int str_l;

  *ptr = NULL;
  { va_list ap2;
    va_copy(ap2, ap);  /* don't consume the original ap, we'll need it again */
    str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap2);/*get required size*/
    va_end(ap2);
  }
  assert(str_l >= 0);        /* possible integer overflow if str_m > INT_MAX */
  *ptr = (char *) malloc(str_m = (size_t)str_l + 1);
  if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
  else {
    int str_l2 = portable_vsnprintf(*ptr, str_m, fmt, ap);
    assert(str_l2 == str_l);
  }
  return str_l;
}
Esempio n. 6
0
int asprintf(char **ptr, const char *fmt, /*args*/ ...) {
  va_list ap;
  size_t str_m;
  int str_l;

  *ptr = NULL;
  va_start(ap, fmt);                            /* measure the required size */
  str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap);
  va_end(ap);
  assert(str_l >= 0);        /* possible integer overflow if str_m > INT_MAX */
  *ptr = (char *) malloc(str_m = (size_t)str_l + 1);
  if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
  else {
    int str_l2;
    va_start(ap, fmt);
    str_l2 = portable_vsnprintf(*ptr, str_m, fmt, ap);
    va_end(ap);
    assert(str_l2 == str_l);
  }
  return str_l;
}
Esempio n. 7
0
int vasnprintf (char **ptr, size_t str_m, const char *fmt, va_list ap) {
  int str_l;

  *ptr = NULL;
  { va_list ap2;
    va_copy(ap2, ap);  /* don't consume the original ap, we'll need it again */
    str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap2);/*get required size*/
    va_end(ap2);
  }
  assert(str_l >= 0);        /* possible integer overflow if str_m > INT_MAX */
  if ((size_t)str_l + 1 < str_m) str_m = (size_t)str_l + 1;      /* truncate */
  /* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
  if (str_m == 0) {  /* not interested in resulting string, just return size */
  } else {
    *ptr = (char *) malloc(str_m);
    if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
    else {
      int str_l2 = portable_vsnprintf(*ptr, str_m, fmt, ap);
      assert(str_l2 == str_l);
    }
  }
  return str_l;
}
Esempio n. 8
0
void MapleFile::print(const char* format, ...)
{
    // Size in bytes of the temporary text buffer.
    static const size_t BufferSize = 4096;

    // Print the formatted message into a temporary C string.
    va_list argptr;
    va_start(argptr, format);
    char text[BufferSize];
    portable_vsnprintf(text, BufferSize, format, argptr);

    // Print the result into the file.
    fprintf(m_file, "%s", text);
}
Esempio n. 9
0
void MessageList::add(
    const LogMessage::Category  category,
    const char*                 format, ...)
{
    // Size in bytes of the temporary message buffer.
    static const size_t BufferSize = 4096;

    // Print the formatted message into the temporary buffer.
    va_list argptr;
    va_start(argptr, format);
    char buffer[BufferSize];
    portable_vsnprintf(buffer, BufferSize, format, argptr);

    // Create and append a message.
    Impl::Message msg;
    msg.m_category = category;
    msg.m_text = buffer;
    impl->m_messages.push_back(msg);
}