Пример #1
0
END_TEST

START_TEST(test_fstr_add_str)
{
	char buf[11];
	fstr_t fstr;

	FSTR_INIT_FOR_BUF(&fstr, buf);
	str_t *str = str_from_cstr("hello");

	fstr_add_str(&fstr, str);
	CHECK_STR(&fstr, == 10, == 5, "hello");
	str_free(str);

	str = str_from_cstr("world!");
	fstr_add_str(&fstr, str);
	CHECK_STR(&fstr, == 10, == 10, "helloworld");
	str_free(str);

	FSTR_INIT_FOR_BUF(&fstr, buf);
	str = str_from_cstr("");
	fstr_add_str(&fstr, str);
	CHECK_STR(&fstr, == 10, == 0, "");
	str_free(str);
}
Пример #2
0
static int create_server_socket(const str_t *file)
{
	int sock = socket(AF_UNIX, SOCK_STREAM, 0);
	if (sock == -1)
		return -1;

	struct sockaddr_un addr;
	fstr_t addrpath;

	addr.sun_family = AF_UNIX;

	FSTR_INIT_FOR_BUF(&addrpath, addr.sun_path);
	fstr_add_str(&addrpath, file);

	if (-1 == bind(sock, (struct sockaddr*)&addr, sizeof addr))
		return -1;

	if (-1 == listen(sock, SERVER_SOCKET_BACKLOG))
		return -1;

	return sock;
}