istream-file.c revision c06f4017027263cf3a08becc551f5126409e2a83
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2002-2003 Timo Sirainen */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* @UNSAFE: whole file */
9b7eeffb5752b500ac62ba1fd01c4a8c4ada14e9Timo Sirainen struct file_istream *fstream = (struct file_istream *) stream;
9b7eeffb5752b500ac62ba1fd01c4a8c4ada14e9Timo Sirainen struct _istream *_stream = (struct _istream *) stream;
93fa87cf1a96c4f279ec4f5c311820313ba12c34Timo Sirainen if (fstream->autoclose_fd && _stream->fd != -1) {
b565a6a7a66fb9f224d00c06a950e3c1c585c18eTimo Sirainen struct _istream *_stream = (struct _istream *) stream;
0c1835a90dd1dcedaeaedd1cd91672299cbeb5beTimo Sirainen p_free(_stream->iostream.pool, _stream->w_buffer);
f4735bf7ec2019fdc730e9ebdb39e5a4ea580405Timo Sirainenstatic void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen struct file_istream *fstream = (struct file_istream *) stream;
8b247780e911909a9fdc47f69ce6d1478902ad98Timo Sirainenstatic void i_stream_grow_buffer(struct _istream *stream, size_t bytes)
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen struct file_istream *fstream = (struct file_istream *) stream;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen pool_get_exp_grown_size(stream->iostream.pool,
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen stream->buffer_size > fstream->max_buffer_size)
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen stream->buffer_size = fstream->max_buffer_size;
eb98a038ca8b0ef33d1d11794803ce09547496faTimo Sirainen p_realloc(stream->iostream.pool, stream->w_buffer,
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainenstatic void i_stream_compress(struct _istream *stream)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen memmove(stream->w_buffer, stream->w_buffer + stream->skip,
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen struct file_istream *fstream = (struct file_istream *) stream;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* remove the unused bytes from beginning of buffer */
683eebe490bbe5caec246c535a10ea9f93f5c330Timo Sirainen stream->buffer_size < fstream->max_buffer_size) {
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen /* buffer is full - grow it */
5238111c460098d9cc8cc22527026138a278b9a4Timo Sirainen i_stream_grow_buffer(stream, I_STREAM_MIN_SIZE);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen ret = pread(stream->fd, stream->w_buffer + stream->pos,
ceb43cc04edb94445fab8f914bc4da6d740403d1Timo Sirainen ret = read(stream->fd, stream->w_buffer + stream->pos,
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen } while (ret < 0 && errno == EINTR && stream->istream.blocking);
static const struct stat *
return NULL;