summaryrefslogtreecommitdiff
path: root/libc/stdlib/assert.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-07-27 17:40:29 -0700
committerElliott Hughes <enh@google.com>2012-07-27 17:43:38 -0700
commit52d6233296ec84eb5b58fcbf7bc9da4b96a943aa (patch)
treeb0186ce62c2aedc309501f0bfc641a291d91d3e6 /libc/stdlib/assert.c
parenta7916509a3446afd0e863b03e4204cee73e81555 (diff)
Report errors to the log, not just stderr.
In particular this affects assert(3) and __cxa_pure_virtual, both of which have managed to confuse people this week by apparently aborting without reason. (Because stderr goes nowhere, normally.) Bug: 6852995 Bug: 6840813 Change-Id: I7f5d17d5ddda439e217b7932096702dc013b9142
Diffstat (limited to 'libc/stdlib/assert.c')
-rw-r--r--libc/stdlib/assert.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/libc/stdlib/assert.c b/libc/stdlib/assert.c
index 816b050cf..7c0a86018 100644
--- a/libc/stdlib/assert.c
+++ b/libc/stdlib/assert.c
@@ -32,23 +32,23 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <private/logd.h>
-void
-__assert(const char *file, int line, const char *failedexpr)
-{
- (void)fprintf(stderr,
- "assertion \"%s\" failed: file \"%s\", line %d\n",
- failedexpr, file, line);
- abort();
- /* NOTREACHED */
+// We log to stderr for the benefit of "adb shell" users, and the log for the benefit
+// of regular app developers who want to see their asserts.
+
+void __assert(const char* file, int line, const char* failed_expression) {
+ const char* fmt = "%s:%d: assertion \"%s\" failed\n";
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc", fmt, file, line, failed_expression);
+ fprintf(stderr, fmt, file, line, failed_expression);
+ abort();
+ /* NOTREACHED */
}
-void
-__assert2(const char *file, int line, const char *func, const char *failedexpr)
-{
- (void)fprintf(stderr,
- "assertion \"%s\" failed: file \"%s\", line %d, function \"%s\"\n",
- failedexpr, file, line, func);
- abort();
- /* NOTREACHED */
+void __assert2(const char* file, int line, const char* function, const char* failed_expression) {
+ const char* fmt = "%s:%d: %s: assertion \"%s\" failed\n";
+ __libc_android_log_print(ANDROID_LOG_FATAL, "libc", fmt, file, line, function, failed_expression);
+ fprintf(stderr, fmt, file, line, function, failed_expression);
+ abort();
+ /* NOTREACHED */
}