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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
19
#include <drizzled/internal/my_sys.h>
20
#include "transparent_file.h"
22
using namespace drizzled;
24
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
26
buff= static_cast<unsigned char *>(malloc(buff_size*sizeof(unsigned char)));
29
Transparent_file::~Transparent_file()
34
void Transparent_file::init_buff(int filedes_arg)
37
/* read the beginning of the file */
39
lseek(filedes, 0, SEEK_SET);
41
upper_bound= internal::my_read(filedes, buff, buff_size, MYF(0));
44
unsigned char *Transparent_file::ptr()
49
off_t Transparent_file::start()
54
off_t Transparent_file::end()
59
off_t Transparent_file::read_next()
64
No need to seek here, as the file managed by Transparent_file class
65
always points to upper_bound byte
67
if ((bytes_read= internal::my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
74
lower_bound= upper_bound;
75
upper_bound+= bytes_read;
81
char Transparent_file::get_value(off_t offset)
85
/* check boundaries */
86
if ((lower_bound <= offset) && (offset < upper_bound))
87
return buff[offset - lower_bound];
89
lseek(filedes, offset, SEEK_SET);
90
/* read appropriate portion of the file */
91
if ((bytes_read= internal::my_read(filedes, buff, buff_size,
92
MYF(0))) == MY_FILE_ERROR)
96
upper_bound= lower_bound + bytes_read;
99
if (upper_bound == offset)