示例#1
0
int lib_rawvprintf(const char *fmt, va_list ap)
{
#if CONFIG_NFILE_DESCRIPTORS > 0

  struct lib_rawoutstream_s rawoutstream;

  /* Wrap the stdout in a stream object and let lib_vsprintf
   * do the work.
   */

  lib_rawoutstream(&rawoutstream, 1);
  return lib_vsprintf(&rawoutstream.public, fmt, ap);

#elif defined(CONFIG_ARCH_LOWPUTC)

  struct lib_outstream_s stream;

  /* Wrap the low-level output in a stream object and let lib_vsprintf
   * do the work.
   */

  lib_lowoutstream((FAR struct lib_outstream_s *)&stream);
  return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);

#else
  return 0;
#endif
}
示例#2
0
int asprintf (FAR char **ptr, const char *fmt, ...)
{
  struct lib_outstream_s nulloutstream;
  struct lib_memoutstream_s memoutstream;
  FAR char *buf;
  va_list ap;
  int     nbytes;

  DEBUGASSERT(ptr && fmt);

  /* First, use a nullstream to get the size of the buffer.  The number
   * of bytes returned may or may not include the null terminator.
   */
  
  lib_nulloutstream(&nulloutstream);
  va_start(ap, fmt);
  nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&nulloutstream, fmt, ap);
  va_end(ap);

  /* Then allocate a buffer to hold that number of characters, adding one
   * for the null terminator.
   */

  buf = (FAR char *)malloc(nulloutstream.nput + 1);
  if (!buf)
    {
      return ERROR;
    }

  /* Initialize a memory stream to write into the allocated buffer.  The
   * memory stream will reserve one byte at the end of the buffer for the
   * null terminator and will not report this in the number of output bytes.
   */

  lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream,
                   buf, nulloutstream.nput + 1);

  /* Then let lib_vsprintf do it's real thing */

  va_start(ap, fmt);
  nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap);
  va_end(ap);

  /* Return a pointer to the string to the caller.  NOTE: the memstream put()
   * method has already added the NUL terminator to the end of the string (not
   * included in the nput count).
   *
   * Hmmm.. looks like the memory would be stranded if lib_vsprintf() returned
   * an error.  Does that ever happen?
   */

  DEBUGASSERT(nbytes < 0 || nbytes == nulloutstream.nput);
  *ptr = buf;
  return nbytes;
}
示例#3
0
int lib_lowvprintf(const char *fmt, va_list ap)
{
  struct lib_outstream_s stream;

  /* Wrap the stdout in a stream object and let lib_vsprintf
   * do the work.
   */

  lib_lowoutstream((FAR struct lib_outstream_s *)&stream);
  return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
}
示例#4
0
int lib_sprintf(FAR struct lib_outstream_s *obj, const char *fmt, ...)
{
    va_list ap;
    int     n;

    /* Let lib_vsprintf do the real work */

    va_start(ap, fmt);
    n = lib_vsprintf(obj, fmt, ap);
    va_end(ap);
    return n;
}
示例#5
0
static inline int lowvsyslog_internal(FAR const IPTR char *fmt, va_list ap)
{
  struct lib_outstream_s stream;

  /* Wrap the stdout in a stream object and let lib_vsprintf do the work. */

#ifdef CONFIG_SYSLOG
  lib_syslogstream((FAR struct lib_outstream_s *)&stream);
#else
  lib_lowoutstream((FAR struct lib_outstream_s *)&stream);
#endif
  return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, ap);
}
示例#6
0
文件: vsyslog.c 项目: a1ien/nuttx
int _vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
{
  struct lib_outstream_s stream;
#ifdef CONFIG_SYSLOG_TIMESTAMP
  struct timespec ts;

  /* Get the current time.  Since debug output may be generated very early
   * in the start-up sequence, hardware timer support may not yet be
   * available.
   */

  if (!OSINIT_HW_READY() || clock_systimespec(&ts) < 0)
    {
      /* Timer hardware is not available, or clock_systimespec failed */

      ts.tv_sec  = 0;
      ts.tv_nsec = 0;
    }
#endif

  /* Wrap the low-level output in a stream object and let lib_vsprintf
   * do the work.  NOTE that emergency priority output is handled
   * differently.. it will use the SYSLOG emergency stream.
   */

  if (priority == LOG_EMERG)
    {
      /* Use the SYSLOG emergency stream */

      emergstream((FAR struct lib_outstream_s *)&stream);
    }
  else
    {
      /* Use the normal SYSLOG stream */

      syslogstream((FAR struct lib_outstream_s *)&stream);
    }

#if defined(CONFIG_SYSLOG_TIMESTAMP)
  /* Pre-pend the message with the current time, if available */

  (void)lib_sprintf((FAR struct lib_outstream_s *)&stream,
                    "[%6d.%06d]", ts.tv_sec, ts.tv_nsec/1000);
#endif

  return lib_vsprintf((FAR struct lib_outstream_s *)&stream, fmt, *ap);
}