ack/tests/plat/lib/test.c
George Koehler a4e6595032 Remove '\0' from output. Fix a compiler warning.
Don't output '\0' in "@@FINISHED\0".

Cast code to unsigned int.  This helps platforms with 16-bit int, by
doing only the low 16 bits of the bitwise-and.  It also removes the
"(warning) conversion of long to pointer loses accuracy".
2017-12-18 21:17:42 -05:00

36 lines
663 B
C

#include "test.h"
/* No CRT in this file (this includes stdio and stdlib!). */
void finished(void)
{
static const char s[] = "@@FINISHED\n";
write(1, s, sizeof(s)-1);
_exit(0);
}
void writehex(uint32_t code)
{
char buf[8];
char* p = &buf[sizeof(buf)];
do
{
*--p = "0123456789abcdef"[(unsigned int)code & 0xf];
code >>= 4;
}
while (code > 0);
write(1, p, buf + sizeof(buf) - p);
}
void fail(uint32_t code)
{
static const char fail_msg[] = "@@FAIL 0x";
static const char nl_msg[] = "\n";
write(1, fail_msg, sizeof(fail_msg)-1);
writehex(code);
write(1, nl_msg, sizeof(nl_msg)-1);
}