Beispiel #1
0
static void
octstr_bitwise(octstr_t *dst, const octstr_t *a, const octstr_t *b, int op)
{
	octstr_t copy;
	unsigned char *ap, *bp;
	int alen, blen, i;

	assert(dst != NULL && a != NULL && b != NULL);

	if (octstr_len(a) > octstr_len(b)) {
		const octstr_t *tmp;

		tmp = a;
		a = b;
		b = tmp;
	}

	ap = octstr_ptr((octstr_t *)a);
	bp = octstr_ptr((octstr_t *)b);
	alen = octstr_len((octstr_t *)a);
	blen = octstr_len((octstr_t *)b);

	octstr_init(&copy);

	switch (op) {
	case OCTSTR_OP_AND:
		for (i = 0; i < alen; i++)
			octstr_putc(&copy, *ap++ & *bp++);

		for (i = alen; i < blen; i++)
			octstr_putc(&copy, 0);
		break;
	case OCTSTR_OP_OR:
		for (i = 0; i < alen; i++)
			octstr_putc(&copy, *ap++ | *bp++);

		for (i = alen; i < blen; i++)
			octstr_putc(&copy, *bp++);
		break;
	case OCTSTR_OP_XOR:
		for (i = 0; i < alen; i++)
			octstr_putc(&copy, *ap++ ^ *bp++);

		for (i = alen; i < blen; i++)
			octstr_putc(&copy, *bp++);
		break;
	default:
		SHOULDNT_REACH();
	}

	octstr_copy(dst, &copy);
	octstr_clear(&copy);
}
Beispiel #2
0
void
message(const char *fmt, ...)
{
    char fmtbuf[255];
    char buf[1024];
    va_list ap;
    int n;

    return_if_fail(fmt != NULL);

    va_start(ap, fmt);

    snprintf(fmtbuf, sizeof(fmtbuf), "%s" CRLF, fmt);

    n = vsnprintf(buf, sizeof(buf), fmtbuf, ap);

    if (n > 0)
        write(STDERR_FILENO, buf, n);
    else {
        SHOULDNT_REACH();
    }
}