~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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
17
#include "config.h"
18
#include <cstdlib>
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
19
#include "drizzled/internal/my_sys.h"
1 by brian
clean slate
20
#include "transparent_file.h"
21
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
22
using namespace drizzled;
23
1 by brian
clean slate
24
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
25
{
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
26
  buff= static_cast<unsigned char *>(malloc(buff_size*sizeof(unsigned char)));
1 by brian
clean slate
27
}
28
29
Transparent_file::~Transparent_file()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
30
{
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
31
  free(buff);
1 by brian
clean slate
32
}
33
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
34
void Transparent_file::init_buff(int filedes_arg)
1 by brian
clean slate
35
{
36
  filedes= filedes_arg;
37
  /* read the beginning of the file */
38
  lower_bound= 0;
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
39
  lseek(filedes, 0, SEEK_SET);
1 by brian
clean slate
40
  if (filedes && buff)
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
41
    upper_bound= internal::my_read(filedes, buff, buff_size, MYF(0));
1 by brian
clean slate
42
}
43
481 by Brian Aker
Remove all of uchar.
44
unsigned char *Transparent_file::ptr()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
45
{
46
  return buff;
1 by brian
clean slate
47
}
48
49
off_t Transparent_file::start()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
50
{
51
  return lower_bound;
1 by brian
clean slate
52
}
53
54
off_t Transparent_file::end()
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
55
{
56
  return upper_bound;
1 by brian
clean slate
57
}
58
59
off_t Transparent_file::read_next()
60
{
61
  size_t bytes_read;
62
63
  /*
64
     No need to seek here, as the file managed by Transparent_file class
65
     always points to upper_bound byte
66
  */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
67
  if ((bytes_read= internal::my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
1 by brian
clean slate
68
    return (off_t) -1;
69
70
  /* end of file */
71
  if (!bytes_read)
72
    return (off_t) -1;
73
74
  lower_bound= upper_bound;
75
  upper_bound+= bytes_read;
76
77
  return lower_bound;
78
}
79
80
81
char Transparent_file::get_value(off_t offset)
82
{
83
  size_t bytes_read;
84
85
  /* check boundaries */
86
  if ((lower_bound <= offset) && (offset < upper_bound))
87
    return buff[offset - lower_bound];
88
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
89
  lseek(filedes, offset, SEEK_SET);
1 by brian
clean slate
90
  /* read appropriate portion of the file */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
91
  if ((bytes_read= internal::my_read(filedes, buff, buff_size,
1 by brian
clean slate
92
                           MYF(0))) == MY_FILE_ERROR)
93
    return 0;
94
95
  lower_bound= offset;
96
  upper_bound= lower_bound + bytes_read;
97
98
  /* end of file */
99
  if (upper_bound == offset)
100
    return 0;
101
102
  return buff[0];
103
}