Portability: terminate abnormally via abort() instead of segfault,

watch the return value from write(), and avoid signed arithmetic on
unsigned values.
This commit is contained in:
Tim Kientzle 2009-12-28 02:20:23 +00:00
parent 06225a399b
commit e9cb23e15d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=201089

View File

@ -50,7 +50,16 @@ __FBSDID("$FreeBSD$");
static void
errmsg(const char *m)
{
write(2, m, strlen(m));
size_t s = strlen(m);
ssize_t written;
while (s > 0) {
written = write(2, m, strlen(m));
if (written <= 0)
return;
m += written;
s -= written;
}
}
static void
@ -60,8 +69,7 @@ diediedie(void)
/* Cause a breakpoint exception */
DebugBreak();
#endif
*(char *)0 = 1; /* Deliberately segfault and force a coredump. */
_exit(1); /* If that didn't work, just exit with an error. */
abort(); /* Terminate the program abnormally. */
}
static const char *
@ -85,7 +93,7 @@ write_all_states(unsigned int states)
unsigned int lowbit;
/* A trick for computing the lowest set bit. */
while ((lowbit = states & (-states)) != 0) {
while ((lowbit = states & (1 + ~states)) != 0) {
states &= ~lowbit; /* Clear the low bit. */
errmsg(state_name(lowbit));
if (states != 0)