~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2003 MySQL AB
2
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.
6
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.
11
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 */
15
16
670.2.2 by Monty Taylor
Got rid of the rest of common_includes. Now on to server_includes.
17
#include <drizzled/server_includes.h>
1 by brian
clean slate
18
#include "transparent_file.h"
19
20
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
21
{
656.1.25 by Monty Taylor
Removed my_malloc stuff from storage/
22
  buff= (unsigned char *) malloc(buff_size*sizeof(unsigned char));
1 by brian
clean slate
23
}
24
25
Transparent_file::~Transparent_file()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
26
{
27
  free((unsigned char*)buff);
1 by brian
clean slate
28
}
29
30
void Transparent_file::init_buff(File filedes_arg)
31
{
32
  filedes= filedes_arg;
33
  /* read the beginning of the file */
34
  lower_bound= 0;
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
35
  lseek(filedes, 0, SEEK_SET);
1 by brian
clean slate
36
  if (filedes && buff)
37
    upper_bound= my_read(filedes, buff, buff_size, MYF(0));
38
}
39
481 by Brian Aker
Remove all of uchar.
40
unsigned char *Transparent_file::ptr()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
41
{
42
  return buff;
1 by brian
clean slate
43
}
44
45
off_t Transparent_file::start()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
46
{
47
  return lower_bound;
1 by brian
clean slate
48
}
49
50
off_t Transparent_file::end()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
51
{
52
  return upper_bound;
1 by brian
clean slate
53
}
54
55
off_t Transparent_file::read_next()
56
{
57
  size_t bytes_read;
58
59
  /*
60
     No need to seek here, as the file managed by Transparent_file class
61
     always points to upper_bound byte
62
  */
63
  if ((bytes_read= my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
64
    return (off_t) -1;
65
66
  /* end of file */
67
  if (!bytes_read)
68
    return (off_t) -1;
69
70
  lower_bound= upper_bound;
71
  upper_bound+= bytes_read;
72
73
  return lower_bound;
74
}
75
76
77
char Transparent_file::get_value(off_t offset)
78
{
79
  size_t bytes_read;
80
81
  /* check boundaries */
82
  if ((lower_bound <= offset) && (offset < upper_bound))
83
    return buff[offset - lower_bound];
84
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
85
  lseek(filedes, offset, SEEK_SET);
1 by brian
clean slate
86
  /* read appropriate portion of the file */
87
  if ((bytes_read= my_read(filedes, buff, buff_size,
88
                           MYF(0))) == MY_FILE_ERROR)
89
    return 0;
90
91
  lower_bound= offset;
92
  upper_bound= lower_bound + bytes_read;
93
94
  /* end of file */
95
  if (upper_bound == offset)
96
    return 0;
97
98
  return buff[0];
99
}