o_stream_temp_close(struct iostream_private *stream,
bool close_parent ATTR_UNUSED)
{
- struct temp_ostream *tstream = (struct temp_ostream *)stream;
+ struct temp_ostream *tstream =
+ container_of(stream, struct temp_ostream, ostream.iostream);
i_close_fd(&tstream->fd);
buffer_free(&tstream->buf);
int o_stream_temp_move_to_memory(struct ostream *output)
{
struct temp_ostream *tstream =
- (struct temp_ostream *)output->real_stream;
+ container_of(output->real_stream, struct temp_ostream, ostream);
unsigned char buf[IO_BLOCK_SIZE];
uoff_t offset = 0;
ssize_t ret = 0;
o_stream_temp_sendv(struct ostream_private *stream,
const struct const_iovec *iov, unsigned int iov_count)
{
- struct temp_ostream *tstream = (struct temp_ostream *)stream;
+ struct temp_ostream *tstream =
+ container_of(stream, struct temp_ostream, ostream);
ssize_t ret = 0;
unsigned int i;
enum ostream_send_istream_result res;
o_stream_temp_send_istream(struct ostream_private *_outstream,
struct istream *instream)
{
- struct temp_ostream *outstream = (struct temp_ostream *)_outstream;
+ struct temp_ostream *outstream =
+ container_of(_outstream, struct temp_ostream, ostream);
enum ostream_send_istream_result res;
if ((outstream->flags & IOSTREAM_TEMP_FLAG_TRY_FD_DUP) != 0) {
o_stream_temp_write_at(struct ostream_private *stream,
const void *data, size_t size, uoff_t offset)
{
- struct temp_ostream *tstream = (struct temp_ostream *)stream;
+ struct temp_ostream *tstream =
+ container_of(stream, struct temp_ostream, ostream);
if (tstream->fd == -1) {
i_assert(stream->ostream.offset == tstream->buf->used);
size_t max_buffer_size)
{
struct temp_ostream *tstream =
- (struct temp_ostream *)(*output)->real_stream;
+ container_of((*output)->real_stream, struct temp_ostream,
+ ostream);
struct istream *input, *input2;
uoff_t abs_offset, size;
const char *for_path;
static ssize_t i_stream_base64_decoder_read(struct istream_private *stream)
{
struct base64_decoder_istream *bstream =
- (struct base64_decoder_istream *)stream;
+ container_of(stream, struct base64_decoder_istream, istream);
size_t pre_count, post_count;
int ret;
uoff_t v_offset, bool mark)
{
struct base64_decoder_istream *bstream =
- (struct base64_decoder_istream *)stream;
+ container_of(stream, struct base64_decoder_istream, istream);
if (v_offset < stream->istream.v_offset) {
/* seeking backwards - go back to beginning and seek
static ssize_t i_stream_base64_encoder_read(struct istream_private *stream)
{
struct base64_encoder_istream *bstream =
- (struct base64_encoder_istream *)stream;
+ container_of(stream, struct base64_encoder_istream, istream);
size_t pre_count, post_count;
int ret;
uoff_t v_offset, bool mark)
{
struct base64_encoder_istream *bstream =
- (struct base64_encoder_istream *)stream;
+ container_of(stream, struct base64_encoder_istream, istream);
if (v_offset < stream->istream.v_offset) {
/* seeking backwards - go back to beginning and seek
bool exact ATTR_UNUSED)
{
struct base64_encoder_istream *bstream =
- (struct base64_encoder_istream *)stream;
+ container_of(stream, struct base64_encoder_istream, istream);
const struct stat *st;
if (i_stream_stat(stream->parent, exact, &st) < 0) {
static void i_stream_callback_destroy(struct iostream_private *stream)
{
- struct callback_istream *cstream = (struct callback_istream *)stream;
+ struct callback_istream *cstream =
+ container_of(stream, struct callback_istream, istream.iostream);
buffer_free(&cstream->buf);
}
static ssize_t i_stream_callback_read(struct istream_private *stream)
{
- struct callback_istream *cstream = (struct callback_istream *)stream;
+ struct callback_istream *cstream =
+ container_of(stream, struct callback_istream, istream);
size_t pos;
if (cstream->callback == NULL) {
const void *data, size_t size)
{
struct callback_istream *cstream =
- (struct callback_istream *)input->real_stream;
+ container_of(input->real_stream,
+ struct callback_istream, istream);
buffer_append(cstream->buf, data, size);
}
buffer_t *i_stream_callback_get_buffer(struct istream *input)
{
struct callback_istream *cstream =
- (struct callback_istream *)input->real_stream;
+ container_of(input->real_stream,
+ struct callback_istream, istream);
return cstream->buf;
}
i_stream_ref(stream);
if (chain->head == NULL && stream != NULL) {
- struct chain_istream *cstream = (struct chain_istream *)chain->stream;
+ struct chain_istream *cstream = chain->stream;
if (cstream->have_explicit_max_buffer_size) {
i_stream_set_max_buffer_size(stream,
i_stream_chain_set_max_buffer_size(struct iostream_private *stream,
size_t max_size)
{
- struct chain_istream *cstream = (struct chain_istream *)stream;
+ struct chain_istream *cstream =
+ container_of(stream, struct chain_istream, istream.iostream);
struct istream_chain_link *link = cstream->chain.head;
cstream->have_explicit_max_buffer_size = TRUE;
static void i_stream_chain_destroy(struct iostream_private *stream)
{
- struct chain_istream *cstream = (struct chain_istream *)stream;
+ struct chain_istream *cstream =
+ container_of(stream, struct chain_istream, istream.iostream);
struct istream_chain_link *link = cstream->chain.head;
while (link != NULL) {
static ssize_t i_stream_chain_read(struct istream_private *stream)
{
- struct chain_istream *cstream = (struct chain_istream *)stream;
+ struct chain_istream *cstream =
+ container_of(stream, struct chain_istream, istream);
struct istream_chain_link *link = cstream->chain.head;
const unsigned char *data;
size_t data_size, cur_data_pos, new_pos;
static void i_stream_chain_close(struct iostream_private *stream,
bool close_parent)
{
- struct chain_istream *cstream = (struct chain_istream *)stream;
+ struct chain_istream *cstream =
+ container_of(stream, struct chain_istream, istream.iostream);
/* seek to the correct position in parent stream in case it didn't
end with EOF */
static void i_stream_concat_close(struct iostream_private *stream,
bool close_parent)
{
- struct concat_istream *cstream = (struct concat_istream *)stream;
+ struct concat_istream *cstream =
+ container_of(stream, struct concat_istream, istream.iostream);
i_assert(cstream->cur_input == cstream->input[cstream->cur_idx]);
unsigned int i;
static void i_stream_concat_destroy(struct iostream_private *stream)
{
- struct concat_istream *cstream = (struct concat_istream *)stream;
+ struct concat_istream *cstream =
+ container_of(stream, struct concat_istream, istream.iostream);
i_assert(cstream->cur_input == cstream->input[cstream->cur_idx]);
unsigned int i;
i_stream_concat_set_max_buffer_size(struct iostream_private *stream,
size_t max_size)
{
- struct concat_istream *cstream = (struct concat_istream *)stream;
+ struct concat_istream *cstream =
+ container_of(stream, struct concat_istream, istream.iostream);
i_assert(cstream->cur_input == cstream->input[cstream->cur_idx]);
unsigned int i;
static ssize_t i_stream_concat_read(struct istream_private *stream)
{
- struct concat_istream *cstream = (struct concat_istream *)stream;
+ struct concat_istream *cstream =
+ container_of(stream, struct concat_istream, istream);
i_assert(cstream->cur_input == cstream->input[cstream->cur_idx]);
const unsigned char *data;
size_t size, data_size, cur_data_pos, new_pos;
static void i_stream_concat_seek(struct istream_private *stream,
uoff_t v_offset, bool mark ATTR_UNUSED)
{
- struct concat_istream *cstream = (struct concat_istream *)stream;
+ struct concat_istream *cstream =
+ container_of(stream, struct concat_istream, istream);
i_assert(cstream->cur_input == cstream->input[cstream->cur_idx]);
stream->istream.v_offset = v_offset;
static int
i_stream_concat_stat(struct istream_private *stream, bool exact ATTR_UNUSED)
{
- struct concat_istream *cstream = (struct concat_istream *)stream;
+ struct concat_istream *cstream =
+ container_of(stream, struct concat_istream, istream);
i_assert(cstream->cur_input == cstream->input[cstream->cur_idx]);
uoff_t v_offset = UOFF_T_MAX;
unsigned int i, cur_idx;
static ssize_t i_stream_crlf_read_crlf(struct istream_private *stream)
{
- struct crlf_istream *cstream = (struct crlf_istream *)stream;
+ struct crlf_istream *cstream =
+ container_of(stream, struct crlf_istream, istream);
const unsigned char *data, *ptr, *src, *src_end;
unsigned char *dest, *dest_end;
size_t size, copy_len;
static ssize_t i_stream_crlf_read_lf(struct istream_private *stream)
{
- struct crlf_istream *cstream = (struct crlf_istream *)stream;
+ struct crlf_istream *cstream =
+ container_of(stream, struct crlf_istream, istream);
const unsigned char *data, *p;
size_t i, dest, size, max;
ssize_t ret;
static void i_stream_failure_at_destroy(struct iostream_private *stream)
{
struct failure_at_istream *fstream =
- (struct failure_at_istream *)stream;
+ container_of(stream, struct failure_at_istream,
+ istream.iostream);
i_free(fstream->error_string);
}
static ssize_t
i_stream_failure_at_read(struct istream_private *stream)
{
- struct failure_at_istream *fstream = (struct failure_at_istream *)stream;
+ struct failure_at_istream *fstream =
+ container_of(stream, struct failure_at_istream, istream);
uoff_t new_offset;
ssize_t ret;
void i_stream_file_close(struct iostream_private *stream,
bool close_parent ATTR_UNUSED)
{
- struct file_istream *fstream = (struct file_istream *)stream;
- struct istream_private *_stream = (struct istream_private *)stream;
+ struct istream_private *_stream =
+ container_of(stream, struct istream_private, iostream);
+ struct file_istream *fstream =
+ container_of(_stream, struct file_istream, istream);
if (fstream->autoclose_fd && _stream->fd != -1) {
/* Ignore ECONNRESET because we don't really care about it here,
ssize_t i_stream_file_read(struct istream_private *stream)
{
- struct file_istream *fstream = (struct file_istream *) stream;
+ struct file_istream *fstream =
+ container_of(stream, struct file_istream, istream);
uoff_t offset;
size_t size;
ssize_t ret;
static void i_stream_file_seek(struct istream_private *stream, uoff_t v_offset,
bool mark ATTR_UNUSED)
{
- struct file_istream *fstream = (struct file_istream *) stream;
+ struct file_istream *fstream =
+ container_of(stream, struct file_istream, istream);
if (!stream->istream.seekable) {
if (v_offset < stream->istream.v_offset)
static int
i_stream_file_stat(struct istream_private *stream, bool exact ATTR_UNUSED)
{
- struct file_istream *fstream = (struct file_istream *) stream;
+ struct file_istream *fstream =
+ container_of(stream, struct file_istream, istream);
const char *name = i_stream_get_name(&stream->istream);
if (!fstream->file) {
static ssize_t
i_stream_hash_read(struct istream_private *stream)
{
- struct hash_istream *hstream = (struct hash_istream *)stream;
+ struct hash_istream *hstream =
+ container_of(stream, struct hash_istream, istream);
const unsigned char *data;
size_t size;
uoff_t skip;
i_stream_hash_seek(struct istream_private *stream,
uoff_t v_offset, bool mark ATTR_UNUSED)
{
- struct hash_istream *hstream = (struct hash_istream *)stream;
+ struct hash_istream *hstream =
+ container_of(stream, struct hash_istream, istream);
if (hstream->hash_context != NULL) {
io_stream_set_error(&stream->iostream,
static ssize_t i_stream_jsonstr_read(struct istream_private *stream)
{
- struct jsonstr_istream *jstream = (struct jsonstr_istream *)stream;
+ struct jsonstr_istream *jstream =
+ container_of(stream, struct jsonstr_istream, istream);
const unsigned char *data;
unsigned int srcskip, destskip, extra;
size_t i, dest, size;
static void i_stream_limit_destroy(struct iostream_private *stream)
{
- struct limit_istream *lstream = (struct limit_istream *) stream;
+ struct limit_istream *lstream =
+ container_of(stream, struct limit_istream, istream.iostream);
uoff_t v_offset;
v_offset = lstream->istream.parent_start_offset +
static ssize_t i_stream_limit_read(struct istream_private *stream)
{
- struct limit_istream *lstream = (struct limit_istream *) stream;
+ struct limit_istream *lstream =
+ container_of(stream, struct limit_istream, istream);
uoff_t left;
ssize_t ret;
size_t pos;
static int
i_stream_limit_stat(struct istream_private *stream, bool exact)
{
- struct limit_istream *lstream = (struct limit_istream *) stream;
+ struct limit_istream *lstream =
+ container_of(stream, struct limit_istream, istream);
const struct stat *st;
if (i_stream_stat(stream->parent, exact, &st) < 0) {
static int i_stream_limit_get_size(struct istream_private *stream,
bool exact, uoff_t *size_r)
{
- struct limit_istream *lstream = (struct limit_istream *) stream;
+ struct limit_istream *lstream =
+ container_of(stream, struct limit_istream, istream);
const struct stat *st;
if (lstream->v_size != UOFF_T_MAX) {
static ssize_t i_stream_multiplex_ichannel_read(struct istream_private *stream)
{
- struct multiplex_ichannel *channel = (struct multiplex_ichannel*)stream;
+ struct multiplex_ichannel *channel =
+ container_of(stream, struct multiplex_ichannel, istream);
/* if previous multiplex read dumped data for us
actually serve it here. */
if (channel->pending_pos > 0) {
i_stream_multiplex_ichannel_switch_ioloop_to(struct istream_private *stream,
struct ioloop *ioloop)
{
- struct multiplex_ichannel *channel = (struct multiplex_ichannel*)stream;
+ struct multiplex_ichannel *channel =
+ container_of(stream, struct multiplex_ichannel, istream);
i_stream_switch_ioloop_to(channel->mstream->parent, ioloop);
}
i_stream_multiplex_ichannel_close(struct iostream_private *stream, bool close_parent)
{
struct multiplex_ichannel *const *channelp;
- struct multiplex_ichannel *channel = (struct multiplex_ichannel*)stream;
+ struct multiplex_ichannel *channel =
+ container_of(stream, struct multiplex_ichannel,
+ istream.iostream);
channel->closed = TRUE;
if (close_parent) {
array_foreach(&channel->mstream->channels, channelp)
static void i_stream_multiplex_ichannel_destroy(struct iostream_private *stream)
{
struct multiplex_ichannel **channelp;
- struct multiplex_ichannel *channel = (struct multiplex_ichannel*)stream;
+ struct multiplex_ichannel *channel =
+ container_of(stream, struct multiplex_ichannel,
+ istream.iostream);
i_stream_multiplex_ichannel_close(stream, TRUE);
i_stream_free_buffer(&channel->istream);
array_foreach_modifiable(&channel->mstream->channels, channelp) {
struct istream *i_stream_multiplex_add_channel(struct istream *stream, uint8_t cid)
{
struct multiplex_ichannel *chan =
- (struct multiplex_ichannel *)stream->real_stream;
+ container_of(stream->real_stream,
+ struct multiplex_ichannel, istream);
i_assert(get_channel(chan->mstream, cid) == NULL);
return i_stream_add_channel_real(chan->mstream, cid);
uint8_t i_stream_multiplex_get_channel_id(struct istream *stream)
{
struct multiplex_ichannel *channel =
- (struct multiplex_ichannel *)stream->real_stream;
+ container_of(stream->real_stream,
+ struct multiplex_ichannel, istream);
return channel->cid;
}
static void i_stream_rawlog_close(struct iostream_private *stream,
bool close_parent)
{
- struct rawlog_istream *rstream = (struct rawlog_istream *)stream;
+ struct rawlog_istream *rstream =
+ container_of(stream, struct rawlog_istream, istream.iostream);
iostream_rawlog_close(&rstream->riostream);
if (close_parent)
static void i_stream_rawlog_destroy(struct iostream_private *stream)
{
- struct rawlog_istream *rstream = (struct rawlog_istream *)stream;
+ struct rawlog_istream *rstream =
+ container_of(stream, struct rawlog_istream, istream.iostream);
uoff_t v_offset;
v_offset = rstream->istream.parent_start_offset +
static ssize_t i_stream_rawlog_read(struct istream_private *stream)
{
- struct rawlog_istream *rstream = (struct rawlog_istream *)stream;
+ struct rawlog_istream *rstream =
+ container_of(stream, struct rawlog_istream, istream);
ssize_t ret;
size_t pos;
static void i_stream_seekable_close(struct iostream_private *stream,
bool close_parent ATTR_UNUSED)
{
- struct seekable_istream *sstream = (struct seekable_istream *)stream;
+ struct seekable_istream *sstream =
+ container_of(stream, struct seekable_istream, istream.iostream);
sstream->fd = -1;
i_stream_close(sstream->fd_input);
static void i_stream_seekable_destroy(struct iostream_private *stream)
{
- struct seekable_istream *sstream = (struct seekable_istream *)stream;
+ struct seekable_istream *sstream =
+ container_of(stream, struct seekable_istream, istream.iostream);
i_stream_free_buffer(&sstream->istream);
i_stream_unref(&sstream->fd_input);
i_stream_seekable_set_max_buffer_size(struct iostream_private *stream,
size_t max_size)
{
- struct seekable_istream *sstream = (struct seekable_istream *)stream;
+ struct seekable_istream *sstream =
+ container_of(stream, struct seekable_istream, istream.iostream);
unsigned int i;
sstream->istream.max_buffer_size = max_size;
static ssize_t i_stream_seekable_read(struct istream_private *stream)
{
- struct seekable_istream *sstream = (struct seekable_istream *)stream;
+ struct seekable_istream *sstream =
+ container_of(stream, struct seekable_istream, istream);
const unsigned char *data;
size_t size, pos;
ssize_t ret;
static int
i_stream_seekable_stat(struct istream_private *stream, bool exact)
{
- struct seekable_istream *sstream = (struct seekable_istream *)stream;
+ struct seekable_istream *sstream =
+ container_of(stream, struct seekable_istream, istream);
const struct stat *st;
uoff_t old_offset, len;
ssize_t ret;
i_stream_seekable_snapshot(struct istream_private *stream,
struct istream_snapshot *prev_snapshot)
{
- struct seekable_istream *sstream = (struct seekable_istream *)stream;
+ struct seekable_istream *sstream =
+ container_of(stream, struct seekable_istream, istream);
if (sstream->fd == -1) {
/* still in memory */
stream = i_stream_create_seekable(input, max_buffer_size,
seekable_fd_callback,
i_strdup(temp_path_prefix));
- sstream = (struct seekable_istream *)stream->real_stream;
+ sstream = container_of(stream->real_stream,
+ struct seekable_istream, istream);
sstream->free_context = TRUE;
return stream;
}
static void i_stream_sized_destroy(struct iostream_private *stream)
{
- struct sized_istream *sstream = (struct sized_istream *)stream;
+ struct sized_istream *sstream =
+ container_of(stream, struct sized_istream, istream.iostream);
uoff_t v_offset;
v_offset = sstream->istream.parent_start_offset +
static ssize_t i_stream_sized_read(struct istream_private *stream)
{
struct sized_istream *sstream =
- (struct sized_istream *)stream;
+ container_of(stream, struct sized_istream, istream);
struct istream_sized_error_data data;
const char *error;
uoff_t left;
static int
i_stream_sized_stat(struct istream_private *stream, bool exact ATTR_UNUSED)
{
- struct sized_istream *sstream = (struct sized_istream *)stream;
+ struct sized_istream *sstream =
+ container_of(stream, struct sized_istream, istream);
const struct stat *st;
/* parent stream may be base64-decoder. don't waste time decoding the
struct istream *ret;
ret= i_stream_create_sized(input, min_size);
- ((struct sized_istream *)ret->real_stream)->min_size_only = TRUE;
+ struct sized_istream *ret_sstream =
+ container_of(ret->real_stream, struct sized_istream, istream);
+ ret_sstream->min_size_only = TRUE;
return ret;
}
struct istream *ret;
ret = i_stream_create_sized_range(input, offset, min_size);
- ((struct sized_istream *)ret->real_stream)->min_size_only = TRUE;
+ struct sized_istream *ret_sstream =
+ container_of(ret->real_stream, struct sized_istream, istream);
+ ret_sstream->min_size_only = TRUE;
return ret;
}
static void i_stream_tee_close(struct iostream_private *stream,
bool close_parent ATTR_UNUSED)
{
- struct tee_child_istream *tstream = (struct tee_child_istream *)stream;
+ struct tee_child_istream *tstream =
+ container_of(stream, struct tee_child_istream,
+ istream.iostream);
tee_streams_skip(tstream->tee);
}
static void i_stream_tee_destroy(struct iostream_private *stream)
{
- struct tee_child_istream *tstream = (struct tee_child_istream *)stream;
+ struct tee_child_istream *tstream =
+ container_of(stream, struct tee_child_istream,
+ istream.iostream);
struct tee_istream *tee = tstream->tee;
struct tee_child_istream **p;
i_stream_tee_set_max_buffer_size(struct iostream_private *stream,
size_t max_size)
{
- struct tee_child_istream *tstream = (struct tee_child_istream *)stream;
+ struct tee_child_istream *tstream =
+ container_of(stream, struct tee_child_istream,
+ istream.iostream);
tstream->istream.max_buffer_size = max_size;
i_stream_set_max_buffer_size(tstream->tee->input, max_size);
static ssize_t i_stream_tee_read(struct istream_private *stream)
{
- struct tee_child_istream *tstream = (struct tee_child_istream *)stream;
+ struct tee_child_istream *tstream =
+ container_of(stream, struct tee_child_istream, istream);
struct istream *input = tstream->tee->input;
const unsigned char *data;
size_t size;
static int
i_stream_tee_stat(struct istream_private *stream, bool exact)
{
- struct tee_child_istream *tstream = (struct tee_child_istream *)stream;
+ struct tee_child_istream *tstream =
+ container_of(stream, struct tee_child_istream, istream);
const struct stat *st;
if (i_stream_stat(tstream->tee->input, exact, &st) < 0)
static void i_stream_tee_sync(struct istream_private *stream)
{
- struct tee_child_istream *tstream = (struct tee_child_istream *)stream;
+ struct tee_child_istream *tstream =
+ container_of(stream, struct tee_child_istream, istream);
tee_streams_skip(tstream->tee);
if (i_stream_get_data_size(tstream->tee->input) != 0) {
bool tee_i_stream_child_is_waiting(struct istream *input)
{
struct tee_child_istream *tstream =
- (struct tee_child_istream *)input->real_stream;
+ container_of(input->real_stream,
+ struct tee_child_istream, istream);
return tstream->last_read_waiting;
}
static void i_stream_timeout_close(struct iostream_private *stream,
bool close_parent)
{
- struct timeout_istream *tstream = (struct timeout_istream *)stream;
+ struct timeout_istream *tstream =
+ container_of(stream, struct timeout_istream, istream.iostream);
timeout_remove(&tstream->to);
if (close_parent)
static void i_stream_timeout_switch_ioloop_to(struct istream_private *stream,
struct ioloop *ioloop)
{
- struct timeout_istream *tstream = (struct timeout_istream *)stream;
+ struct timeout_istream *tstream =
+ container_of(stream, struct timeout_istream, istream);
if (tstream->to != NULL)
tstream->to = io_loop_move_timeout_to(ioloop, &tstream->to);
static ssize_t
i_stream_timeout_read(struct istream_private *stream)
{
- struct timeout_istream *tstream = (struct timeout_istream *)stream;
+ struct timeout_istream *tstream =
+ container_of(stream, struct timeout_istream, istream);
struct iostream_private *iostream = &tstream->istream.iostream;
ssize_t ret;
static void i_stream_try_close(struct iostream_private *stream,
bool close_parent)
{
- struct try_istream *tstream = (struct try_istream *)stream;
+ struct try_istream *tstream =
+ container_of(stream, struct try_istream, istream.iostream);
if (close_parent) {
if (tstream->istream.parent != NULL)
static ssize_t
i_stream_try_read(struct istream_private *stream)
{
- struct try_istream *tstream = (struct try_istream *)stream;
+ struct try_istream *tstream =
+ container_of(stream, struct try_istream, istream);
int ret;
if (stream->parent == NULL) {
static void
i_stream_unix_close(struct iostream_private *stream, bool close_parent)
{
- struct unix_istream *ustream = (struct unix_istream *)stream;
+ struct unix_istream *ustream =
+ container_of(stream, struct unix_istream,
+ fstream.istream.iostream);
i_close_fd(&ustream->read_fd);
i_stream_file_close(stream, close_parent);
static ssize_t i_stream_unix_read(struct istream_private *stream)
{
- struct unix_istream *ustream = (struct unix_istream *)stream;
+ struct unix_istream *ustream =
+ container_of(stream, struct unix_istream, fstream.istream);
size_t size;
ssize_t ret;
void i_stream_unix_set_read_fd(struct istream *input)
{
struct unix_istream *ustream =
- (struct unix_istream *)input->real_stream;
+ container_of(input->real_stream, struct unix_istream,
+ fstream.istream);
ustream->next_read_fd = TRUE;
}
void i_stream_unix_unset_read_fd(struct istream *input)
{
struct unix_istream *ustream =
- (struct unix_istream *)input->real_stream;
+ container_of(input->real_stream, struct unix_istream,
+ fstream.istream);
ustream->next_read_fd = FALSE;
}
int i_stream_unix_get_read_fd(struct istream *input)
{
struct unix_istream *ustream =
- (struct unix_istream *)input->real_stream;
+ container_of(input->real_stream, struct unix_istream,
+ fstream.istream);
int fd;
fd = ustream->read_fd;
i_stream_default_set_max_buffer_size(struct iostream_private *stream,
size_t max_size)
{
- struct istream_private *_stream = (struct istream_private *)stream;
+ struct istream_private *_stream =
+ container_of(stream, struct istream_private, iostream);
_stream->max_buffer_size = max_size;
if (_stream->parent != NULL)
static void i_stream_default_close(struct iostream_private *stream,
bool close_parent)
{
- struct istream_private *_stream = (struct istream_private *)stream;
+ struct istream_private *_stream =
+ container_of(stream, struct istream_private, iostream);
if (close_parent)
i_stream_close(_stream->parent);
static void i_stream_default_destroy(struct iostream_private *stream)
{
- struct istream_private *_stream = (struct istream_private *)stream;
+ struct istream_private *_stream =
+ container_of(stream, struct istream_private, iostream);
i_stream_free_buffer(_stream);
i_stream_unref(&_stream->parent);
static int o_stream_buffer_seek(struct ostream_private *stream, uoff_t offset)
{
- struct buffer_ostream *bstream = (struct buffer_ostream *)stream;
+ struct buffer_ostream *bstream =
+ container_of(stream, struct buffer_ostream, ostream);
bstream->seeked = TRUE;
stream->ostream.offset = offset;
o_stream_buffer_write_at(struct ostream_private *stream,
const void *data, size_t size, uoff_t offset)
{
- struct buffer_ostream *bstream = (struct buffer_ostream *)stream;
+ struct buffer_ostream *bstream =
+ container_of(stream, struct buffer_ostream, ostream);
buffer_write(bstream->buf, offset, data, size);
return 0;
o_stream_buffer_sendv(struct ostream_private *stream,
const struct const_iovec *iov, unsigned int iov_count)
{
- struct buffer_ostream *bstream = (struct buffer_ostream *)stream;
+ struct buffer_ostream *bstream =
+ container_of(stream, struct buffer_ostream, ostream);
size_t left, n, offset;
ssize_t ret = 0;
unsigned int i;
static size_t
o_stream_buffer_get_buffer_used_size(const struct ostream_private *stream)
{
- struct buffer_ostream *bstream = (struct buffer_ostream *)stream;
+ const struct buffer_ostream *bstream =
+ container_of(stream, const struct buffer_ostream, ostream);
return bstream->buf->used;
}
static void o_stream_failure_at_destroy(struct iostream_private *stream)
{
struct failure_at_ostream *fstream =
- (struct failure_at_ostream *)stream;
+ container_of(stream, struct failure_at_ostream,
+ ostream.iostream);
i_free(fstream->error_string);
o_stream_unref(&fstream->ostream.parent);
const struct const_iovec *iov, unsigned int iov_count)
{
struct failure_at_ostream *fstream =
- (struct failure_at_ostream *)stream;
+ container_of(stream, struct failure_at_ostream, ostream);
unsigned int i;
struct const_iovec *iov_dup;
unsigned int iov_dup_count;
o_stream_failure_at_flush(struct ostream_private *stream)
{
struct failure_at_ostream *fstream =
- (struct failure_at_ostream *)stream;
+ container_of(stream, struct failure_at_ostream, ostream);
if (fstream->failed) {
io_stream_set_error(&stream->iostream, "%s",
void o_stream_file_close(struct iostream_private *stream,
bool close_parent ATTR_UNUSED)
{
- struct file_ostream *fstream = (struct file_ostream *)stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream.iostream);
stream_closed(fstream);
}
static void o_stream_file_destroy(struct iostream_private *stream)
{
- struct file_ostream *fstream = (struct file_ostream *)stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream.iostream);
i_free(fstream->buffer);
}
static void o_stream_file_cork(struct ostream_private *stream, bool set)
{
- struct file_ostream *fstream = (struct file_ostream *)stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream);
struct iostream_private *iostream = &fstream->ostream.iostream;
int ret;
static int o_stream_file_flush(struct ostream_private *stream)
{
- struct file_ostream *fstream = (struct file_ostream *) stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream);
return buffer_flush(fstream);
}
static void
o_stream_file_flush_pending(struct ostream_private *stream, bool set)
{
- struct file_ostream *fstream = (struct file_ostream *) stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream);
struct iostream_private *iostream = &fstream->ostream.iostream;
fstream->flush_pending = set;
o_stream_file_get_buffer_used_size(const struct ostream_private *stream)
{
const struct file_ostream *fstream =
- (const struct file_ostream *)stream;
+ container_of(stream, const struct file_ostream, ostream);
return fstream->buffer_size - get_unused_space(fstream);
}
static int o_stream_file_seek(struct ostream_private *stream, uoff_t offset)
{
- struct file_ostream *fstream = (struct file_ostream *)stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream);
if (offset > OFF_T_MAX) {
stream->ostream.stream_errno = EINVAL;
const struct const_iovec *iov,
unsigned int iov_count)
{
- struct file_ostream *fstream = (struct file_ostream *)stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream);
size_t size, total_size, added, optimal_size;
unsigned int i;
ssize_t ret = 0;
o_stream_file_write_at(struct ostream_private *stream,
const void *data, size_t size, uoff_t offset)
{
- struct file_ostream *fstream = (struct file_ostream *)stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream);
size_t used, pos, skip, left;
/* update buffer if the write overlaps it */
struct istream *instream, int in_fd,
enum ostream_send_istream_result *res_r)
{
- struct file_ostream *foutstream = (struct file_ostream *)outstream;
+ struct file_ostream *foutstream =
+ container_of(outstream, struct file_ostream, ostream);
uoff_t in_size, offset, send_size, v_offset, abs_start_offset;
ssize_t ret;
bool sendfile_not_supported = FALSE;
io_stream_copy_backwards(struct ostream_private *outstream,
struct istream *instream, uoff_t in_size)
{
- struct file_ostream *foutstream = (struct file_ostream *)outstream;
+ struct file_ostream *foutstream =
+ container_of(outstream, struct file_ostream, ostream);
uoff_t in_start_offset, in_offset, in_limit, out_offset;
const unsigned char *data;
size_t buffer_size, size, read_size;
o_stream_file_send_istream(struct ostream_private *outstream,
struct istream *instream)
{
- struct file_ostream *foutstream = (struct file_ostream *)outstream;
+ struct file_ostream *foutstream =
+ container_of(outstream, struct file_ostream, ostream);
bool same_stream;
int in_fd;
enum ostream_send_istream_result res;
static void o_stream_file_switch_ioloop_to(struct ostream_private *stream,
struct ioloop *ioloop)
{
- struct file_ostream *fstream = (struct file_ostream *)stream;
+ struct file_ostream *fstream =
+ container_of(stream, struct file_ostream, ostream);
if (fstream->io != NULL)
fstream->io = io_loop_move_io_to(ioloop, &fstream->io);
o_stream_hash_sendv(struct ostream_private *stream,
const struct const_iovec *iov, unsigned int iov_count)
{
- struct hash_ostream *hstream = (struct hash_ostream *)stream;
+ struct hash_ostream *hstream =
+ container_of(stream, struct hash_ostream, ostream);
unsigned int i;
size_t bytes_left, block_len;
ssize_t ret;
static int o_stream_multiplex_ochannel_flush(struct ostream_private *stream)
{
ssize_t ret;
- struct multiplex_ochannel *channel = (struct multiplex_ochannel *)stream;
+ struct multiplex_ochannel *channel =
+ container_of(stream, struct multiplex_ochannel, ostream);
struct multiplex_ostream *mstream = channel->mstream;
/* flush parent stream always, so there is room for more. */
static void o_stream_multiplex_ochannel_cork(struct ostream_private *stream, bool set)
{
- struct multiplex_ochannel *channel = (struct multiplex_ochannel*)stream;
+ struct multiplex_ochannel *channel =
+ container_of(stream, struct multiplex_ochannel, ostream);
if (channel->corked != set && !set) {
/* flush */
(void)o_stream_multiplex_ochannel_flush(stream);
o_stream_multiplex_ochannel_sendv(struct ostream_private *stream,
const struct const_iovec *iov, unsigned int iov_count)
{
- struct multiplex_ochannel *channel = (struct multiplex_ochannel*)stream;
+ struct multiplex_ochannel *channel =
+ container_of(stream, struct multiplex_ochannel, ostream);
size_t total = 0, avail = o_stream_get_buffer_avail_size(&stream->ostream);
size_t optimal_size = I_MIN(IO_BLOCK_SIZE, avail);
o_stream_multiplex_ochannel_get_buffer_used_size(const struct ostream_private *stream)
{
const struct multiplex_ochannel *channel =
- (const struct multiplex_ochannel*)stream;
+ container_of(stream, const struct multiplex_ochannel, ostream);
return channel->buf->used +
o_stream_get_buffer_used_size(channel->mstream->parent);
o_stream_multiplex_ochannel_get_buffer_avail_size(const struct ostream_private *stream)
{
const struct multiplex_ochannel *channel =
- (const struct multiplex_ochannel*)stream;
+ container_of(stream, const struct multiplex_ochannel, ostream);
size_t max_avail = I_MIN(channel->mstream->bufsize,
o_stream_get_buffer_avail_size(stream->parent));
o_stream_multiplex_ochannel_close(struct iostream_private *stream, bool close_parent)
{
struct multiplex_ochannel *const *channelp;
- struct multiplex_ochannel *channel = (struct multiplex_ochannel*)stream;
+ struct multiplex_ochannel *channel =
+ container_of(stream, struct multiplex_ochannel, ostream.iostream);
channel->closed = TRUE;
if (close_parent) {
static void o_stream_multiplex_ochannel_destroy(struct iostream_private *stream)
{
struct multiplex_ochannel **channelp;
- struct multiplex_ochannel *channel = (struct multiplex_ochannel*)stream;
+ struct multiplex_ochannel *channel =
+ container_of(stream, struct multiplex_ochannel, ostream.iostream);
o_stream_unref(&channel->ostream.parent);
if (channel->buf != NULL)
buffer_free(&channel->buf);
struct ostream *o_stream_multiplex_add_channel(struct ostream *stream, uint8_t cid)
{
struct multiplex_ochannel *chan =
- (struct multiplex_ochannel *)stream->real_stream;
+ container_of(stream->real_stream, struct multiplex_ochannel,
+ ostream);
i_assert(get_channel(chan->mstream, cid) == NULL);
return o_stream_add_channel_real(chan->mstream, cid);
uint8_t o_stream_multiplex_get_channel_id(struct ostream *stream)
{
struct multiplex_ochannel *channel =
- (struct multiplex_ochannel *)stream->real_stream;
+ container_of(stream->real_stream, struct multiplex_ochannel,
+ ostream);
return channel->cid;
}
static void o_stream_rawlog_close(struct iostream_private *stream,
bool close_parent)
{
- struct rawlog_ostream *rstream = (struct rawlog_ostream *)stream;
+ struct rawlog_ostream *rstream =
+ container_of(stream, struct rawlog_ostream, ostream.iostream);
iostream_rawlog_close(&rstream->riostream);
if (close_parent)
o_stream_rawlog_sendv(struct ostream_private *stream,
const struct const_iovec *iov, unsigned int iov_count)
{
- struct rawlog_ostream *rstream = (struct rawlog_ostream *)stream;
+ struct rawlog_ostream *rstream =
+ container_of(stream, struct rawlog_ostream, ostream);
unsigned int i;
ssize_t ret, bytes;
static void
o_stream_unix_close(struct iostream_private *stream, bool close_parent)
{
- struct unix_ostream *ustream = (struct unix_ostream *)stream;
+ struct unix_ostream *ustream =
+ container_of(stream, struct unix_ostream,
+ fstream.ostream.iostream);
i_close_fd(&ustream->write_fd);
o_stream_file_close(stream, close_parent);
const struct const_iovec *iov,
unsigned int iov_count)
{
- struct unix_ostream *ustream = (struct unix_ostream *)fstream;
+ struct unix_ostream *ustream =
+ container_of(fstream, struct unix_ostream, fstream);
size_t sent;
ssize_t ret;
bool o_stream_unix_write_fd(struct ostream *output, int fd)
{
struct unix_ostream *ustream =
- (struct unix_ostream *)output->real_stream;
+ container_of(output->real_stream, struct unix_ostream,
+ fstream.ostream);
i_assert(fd >= 0);
wrapper_ostream_close(struct iostream_private *stream,
bool close_parent ATTR_UNUSED)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ struct wrapper_ostream *wostream =
+ container_of(stream, struct wrapper_ostream, ostream.iostream);
timeout_remove(&wostream->to_event);
wrapper_ostream_output_close(wostream);
static void wrapper_ostream_destroy(struct iostream_private *stream)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ struct wrapper_ostream *wostream =
+ container_of(stream, struct wrapper_ostream, ostream.iostream);
timeout_remove(&wostream->to_event);
i_free(wostream->pending_error);
static void wrapper_ostream_cork(struct ostream_private *stream, bool set)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ struct wrapper_ostream *wostream =
+ container_of(stream, struct wrapper_ostream, ostream);
int ret;
if (stream->ostream.closed || wostream->pending_errno != 0)
wrapper_ostream_sendv(struct ostream_private *stream,
const struct const_iovec *iov, unsigned int iov_count)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ struct wrapper_ostream *wostream =
+ container_of(stream, struct wrapper_ostream, ostream);
bool must_uncork = FALSE;
ssize_t sret;
static int wrapper_ostream_flush(struct ostream_private *stream)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ struct wrapper_ostream *wostream =
+ container_of(stream, struct wrapper_ostream, ostream);
struct ostream *ostream = &stream->ostream;
bool must_uncork = FALSE;
int ret;
stream_flush_callback_t *callback,
void *context)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ struct wrapper_ostream *wostream =
+ container_of(stream, struct wrapper_ostream, ostream);
stream->callback = callback;
stream->context = context;
static void
wrapper_ostream_flush_pending(struct ostream_private *stream, bool set)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ struct wrapper_ostream *wostream =
+ container_of(stream, struct wrapper_ostream, ostream);
wostream->flush_pending = set;
if (!set)
static size_t
wrapper_ostream_get_buffer_used_size(const struct ostream_private *stream)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ const struct wrapper_ostream *wostream =
+ container_of(stream, const struct wrapper_ostream, ostream);
size_t size = 0;
if (wostream->buffer != NULL)
static size_t
wrapper_ostream_get_buffer_avail_size(const struct ostream_private *stream)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ const struct wrapper_ostream *wostream =
+ container_of(stream, const struct wrapper_ostream, ostream);
size_t size = 0;
if (wostream->ostream.max_buffer_size == SIZE_MAX)
wrapper_ostream_switch_ioloop_to(struct ostream_private *stream,
struct ioloop *ioloop)
{
- struct wrapper_ostream *wostream = (struct wrapper_ostream *)stream;
+ struct wrapper_ostream *wostream =
+ container_of(stream, struct wrapper_ostream, ostream);
if (wostream->flush_ioloop != ioloop &&
wostream->switch_ioloop_to != NULL)
static void o_stream_default_close(struct iostream_private *stream,
bool close_parent)
{
- struct ostream_private *_stream = (struct ostream_private *)stream;
+ struct ostream_private *_stream =
+ container_of(stream, struct ostream_private, iostream);
(void)o_stream_flush(&_stream->ostream);
if (close_parent)
static void o_stream_default_destroy(struct iostream_private *stream)
{
- struct ostream_private *_stream = (struct ostream_private *)stream;
+ struct ostream_private *_stream =
+ container_of(stream, struct ostream_private, iostream);
o_stream_unref(&_stream->parent);
}
o_stream_default_set_max_buffer_size(struct iostream_private *stream,
size_t max_size)
{
- struct ostream_private *_stream = (struct ostream_private *)stream;
+ struct ostream_private *_stream =
+ container_of(stream, struct ostream_private, iostream);
if (_stream->parent != NULL)
o_stream_set_max_buffer_size(_stream->parent, max_size);