1 // Copyright 2016 The Fuchsia 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 #pragma once
6 
7 #pragma GCC visibility push(hidden)
8 
9 #include <stdarg.h>
10 #include <zircon/status.h>
11 #include <zircon/types.h>
12 
13 // printl() is printf-like, understanding %s %p %d %u %x %zu %zd %zx.
14 // No other formatting features are supported.
15 void __PRINTFLIKE(2, 3) printl(zx_handle_t log, const char* fmt, ...);
16 void vprintl(zx_handle_t log, const char* fmt, va_list ap);
17 
18 // fail() combines printl() with process exit
19 _Noreturn void __PRINTFLIKE(2, 3) fail(zx_handle_t log, const char* fmt, ...);
20 
21 #define check(log, status, fmt, ...)                                    \
22     do {                                                                \
23         if (status != ZX_OK)                                            \
24             fail(log, "%s: " fmt,                                       \
25                  zx_status_get_string(status),##__VA_ARGS__);           \
26     } while (0)
27 
28 #pragma GCC visibility pop
29