Home | History | Annotate | Download | only in nacl_io
      1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2  * Use of this source code is governed by a BSD-style license that can be
      3  * found in the LICENSE file. */
      4 
      5 #include "nacl_io/log.h"
      6 
      7 #include "nacl_io/kernel_wrap_real.h"
      8 
      9 #include <alloca.h>
     10 #include <stdarg.h>
     11 #include <stdio.h>
     12 #include <string.h>
     13 
     14 void nacl_io_log(const char* format, ...) {
     15   va_list args;
     16   size_t wrote;
     17   char* output;
     18 
     19 #ifdef _MSC_VER
     20   /* TODO(sbc): vsnprintf on win32 does not return the
     21    * size of the buffer needed.  This can be implemented
     22    * on win32 in terms of _vscprintf; */
     23 #error "not implemented for win32"
     24 #endif
     25 
     26   va_start(args, format);
     27   int len = vsnprintf(NULL, 0, format, args);
     28   va_end(args);
     29   output = alloca(len + 1);
     30 
     31   va_start(args, format);
     32   vsnprintf(output, len + 1, format, args);
     33   va_end(args);
     34 
     35   _real_write(2, output, strlen(output), &wrote);
     36 }
     37