David Crawshaw | 72faffb | 2014-07-03 21:04:48 -0400 | [diff] [blame^] | 1 | // Copyright 2014 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | #include <stdarg.h> |
| 6 | #include <android/log.h> |
| 7 | #include "libcgo.h" |
| 8 | |
| 9 | void |
| 10 | fatalf(const char* format, ...) |
| 11 | { |
| 12 | va_list ap; |
| 13 | |
| 14 | // Write to both stderr and logcat. |
| 15 | // |
| 16 | // When running from an .apk, /dev/stderr and /dev/stdout |
| 17 | // redirect to /dev/null. And when running a test binary |
| 18 | // via adb shell, it's easy to miss logcat. |
| 19 | |
| 20 | fprintf(stderr, "runtime/cgo: "); |
| 21 | va_start(ap, format); |
| 22 | vfprintf(stderr, format, ap); |
| 23 | va_end(ap); |
| 24 | fprintf(stderr, "\n"); |
| 25 | |
| 26 | va_start(ap, format); |
| 27 | __android_log_vprint(ANDROID_LOG_FATAL, "runtime/cgo", format, ap); |
| 28 | va_end(ap); |
| 29 | |
| 30 | abort(); |
| 31 | } |