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"
23
using namespace drizzled;
25
TransparentFile::TransparentFile() : lower_bound(0), buff_size(IO_SIZE)
27
buff= static_cast<unsigned char *>(malloc(buff_size*sizeof(unsigned char)));
30
TransparentFile::~TransparentFile()
35
void TransparentFile::init_buff(int filedes_arg)
38
/* read the beginning of the file */
40
lseek(filedes, 0, SEEK_SET);
42
upper_bound= ::read(filedes, buff, buff_size);
45
unsigned char *TransparentFile::ptr()
50
off_t TransparentFile::start()
55
off_t TransparentFile::end()
60
off_t TransparentFile::read_next()
65
No need to seek here, as the file managed by TransparentFile class
66
always points to upper_bound byte
68
if ((bytes_read= ::read(filedes, buff, buff_size)) < 0)
75
lower_bound= upper_bound;
76
upper_bound+= bytes_read;
82
char TransparentFile::get_value(off_t offset)
86
/* check boundaries */
87
if ((lower_bound <= offset) && (offset < upper_bound))
88
return buff[offset - lower_bound];
90
lseek(filedes, offset, SEEK_SET);
91
/* read appropriate portion of the file */
92
if ((bytes_read= ::read(filedes, buff, buff_size)) < 0)
96
upper_bound= lower_bound + bytes_read;
99
if (upper_bound == offset)