mailing list of musl libc
 help / color / mirror / code / Atom feed
* printf() less __assert_fail()
@ 2014-10-01 14:45 Daniel Cegiełka
  2014-10-01 14:54 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Cegiełka @ 2014-10-01 14:45 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 81 bytes --]

It makes no sense to use printf() in this function. Is this a good idea?

Daniel

[-- Attachment #2: assert.c --]
[-- Type: text/x-csrc, Size: 635 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

static void print(const char *s)
{
	write(2, s, strlen(s));
}

static unsigned int fmt_uint(char *s, int n)
{
	unsigned int l = 1, q = n;

	while (q > 9) { ++l; q /= 10; }
	if (s) {
		s += l;
		do { *--s = '0' + (n % 10); n /= 10; } while (n);
	}
	return l;
}

void __assert_fail(const char *expr, const char *file, int line, const char *func)
{
	char buf[10];

	print("Assertion failed: ");
	print(expr);
	print(" (");
	print(file);
	print(": ");
	print(func);
	print(": ");
	write(2, buf, fmt_uint(buf, line));
	print(")\n");
	fflush(NULL);
	abort();
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-01 15:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-01 14:45 printf() less __assert_fail() Daniel Cegiełka
2014-10-01 14:54 ` Rich Felker
2014-10-01 15:13   ` Daniel Cegiełka

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).