summaryrefslogtreecommitdiff
path: root/libc/misc/assert
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-10-28 21:29:21 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-10-28 21:29:21 +0000
commitb7df7e6da8876ee40e61d457e2e37523e380aad7 (patch)
treeec4c17307d441153d623e1b5bd4f0e0420afe37e /libc/misc/assert
parent6072ec712b72521d7a13a22b6d9ccf6127c8c005 (diff)
ANSI/ISO C99 requires assert() to write to stderr. This means that
writing to STDERR_FILENO is insufficient, as the user could freopen stderr. It is also insufficient to output to fileno(stderr) since this would fail in the custom stream case. I didn't remove the old code though, as it doesn't use stdio stream functionality and is useful in debugging the stdio code.
Diffstat (limited to 'libc/misc/assert')
-rw-r--r--libc/misc/assert/__assert.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/libc/misc/assert/__assert.c b/libc/misc/assert/__assert.c
index db5f9a7a9..efffff1de 100644
--- a/libc/misc/assert/__assert.c
+++ b/libc/misc/assert/__assert.c
@@ -17,6 +17,16 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+/* Oct 28, 2002
+ *
+ * ANSI/ISO C99 requires assert() to write to stderr. This means that
+ * writing to STDERR_FILENO is insufficient, as the user could freopen
+ * stderr. It is also insufficient to output to fileno(stderr) since
+ * this would fail in the custom stream case. I didn't remove the
+ * old code though, as it doesn't use stdio stream functionality
+ * and is useful in debugging the stdio code.
+ */
+
#define _STDIO_UTILITY /* For _stdio_fdout and _int10tostr. */
#include <stdio.h>
#include <stdlib.h>
@@ -27,6 +37,29 @@
#include <assert.h>
#undef assert
+#if 1
+
+void __assert(const char *assertion, const char * filename,
+ int linenumber, register const char * function)
+{
+ fprintf(stderr,
+#if 0
+ /* TODO: support program_name like glibc? */
+ "%s: %s: %d: %s: Assertion `%s' failed.\n", program_name,
+#else
+ "%s: %d: %s: Assertion `%s' failed.\n",
+#endif
+ filename,
+ linenumber,
+ /* Function name isn't available with some compilers. */
+ ((function == NULL) ? "?function?" : function),
+ assertion
+ );
+ abort();
+}
+
+#else
+
void __assert(const char *assertion, const char * filename,
int linenumber, register const char * function)
{
@@ -50,3 +83,5 @@ void __assert(const char *assertion, const char * filename,
);
abort();
}
+
+#endif