Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / irt_ext / error_report.c
1 /*
2  * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10
11 #include "native_client/src/include/nacl_assert.h"
12 #include "native_client/src/untrusted/nacl/nacl_irt.h"
13
14 static struct nacl_irt_fdio g_fdio;
15
16 void init_error_report_module(void) {
17   size_t bytes = nacl_interface_query(NACL_IRT_FDIO_v0_1,
18                                       &g_fdio, sizeof(g_fdio));
19   ASSERT_EQ(bytes, sizeof(g_fdio));
20 }
21
22 void irt_ext_test_print(const char *format, ...) {
23   char buffer[512];
24   int bufferlen;
25   size_t nwrote;
26
27   va_list args;
28   va_start (args, format);
29   bufferlen = vsnprintf(buffer, sizeof(buffer) - 1, format, args);
30   va_end (args);
31
32   if (bufferlen > 0) {
33     int ret = g_fdio.write(STDERR_FILENO, buffer, bufferlen, &nwrote);
34     if (ret != 0 || nwrote != bufferlen) {
35       __builtin_trap();
36     }
37   }
38 }