1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#ifdef USE_PRAGMA_IMPLEMENTATION
17
#pragma implementation // gcc: Class implementation
20
#include "mysql_priv.h"
21
#include "transparent_file.h"
23
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
25
buff= (uchar *) my_malloc(buff_size*sizeof(uchar), MYF(MY_WME));
28
Transparent_file::~Transparent_file()
30
my_free((uchar*)buff, MYF(MY_ALLOW_ZERO_PTR));
33
void Transparent_file::init_buff(File filedes_arg)
36
/* read the beginning of the file */
38
VOID(my_seek(filedes, 0, MY_SEEK_SET, MYF(0)));
40
upper_bound= my_read(filedes, buff, buff_size, MYF(0));
43
uchar *Transparent_file::ptr()
48
off_t Transparent_file::start()
53
off_t Transparent_file::end()
58
off_t Transparent_file::read_next()
63
No need to seek here, as the file managed by Transparent_file class
64
always points to upper_bound byte
66
if ((bytes_read= my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
73
lower_bound= upper_bound;
74
upper_bound+= bytes_read;
80
char Transparent_file::get_value(off_t offset)
84
/* check boundaries */
85
if ((lower_bound <= offset) && (offset < upper_bound))
86
return buff[offset - lower_bound];
88
VOID(my_seek(filedes, offset, MY_SEEK_SET, MYF(0)));
89
/* read appropriate portion of the file */
90
if ((bytes_read= my_read(filedes, buff, buff_size,
91
MYF(0))) == MY_FILE_ERROR)
95
upper_bound= lower_bound + bytes_read;
98
if (upper_bound == offset)