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

#undef assert

static void write_assert_fail (const char *file, unsigned int line, const char *msg)
{
    char *q;
    char l[32];
    q = &l[30];
    *q = '\0';
    do {
        q--;
        *q = '0' + (line % 10);
        line /= 10;
    } while (line);
    write (2, file, strlen (file));
    write (2, ":", 1);
    write (2, q, strlen (q));
    write (2, ": ", 2);
    write (2, msg, strlen (msg));
    write (2, "\n", 1);
    ((long *) (unsigned long) -1L)[0] = -1;
}


#undef assert
#define assert(x) \
    do { \
        if (!(x)) { \
            write_assert_fail (__FILE__, __LINE__, #x); \
        } \
    } while (0)

