~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/csv/transparent_file.cc

Merge Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
  along with this program; if not, write to the Free Software
14
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#ifdef USE_PRAGMA_IMPLEMENTATION
17
 
#pragma implementation        // gcc: Class implementation
18
 
#endif
19
16
 
20
 
#include "mysql_priv.h"
 
17
#include "config.h"
 
18
#include <cstdlib>
 
19
#include "drizzled/internal/my_sys.h"
21
20
#include "transparent_file.h"
22
21
 
23
22
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
24
 
25
 
  buff= (uchar *) my_malloc(buff_size*sizeof(uchar),  MYF(MY_WME)); 
 
23
{
 
24
  buff= static_cast<unsigned char *>(malloc(buff_size*sizeof(unsigned char)));
26
25
}
27
26
 
28
27
Transparent_file::~Transparent_file()
29
 
30
 
  my_free((uchar*)buff, MYF(MY_ALLOW_ZERO_PTR)); 
 
28
{
 
29
  free(buff);
31
30
}
32
31
 
33
 
void Transparent_file::init_buff(File filedes_arg)
 
32
void Transparent_file::init_buff(int filedes_arg)
34
33
{
35
34
  filedes= filedes_arg;
36
35
  /* read the beginning of the file */
37
36
  lower_bound= 0;
38
 
  VOID(my_seek(filedes, 0, MY_SEEK_SET, MYF(0)));
 
37
  lseek(filedes, 0, SEEK_SET);
39
38
  if (filedes && buff)
40
39
    upper_bound= my_read(filedes, buff, buff_size, MYF(0));
41
40
}
42
41
 
43
 
uchar *Transparent_file::ptr()
44
 
45
 
  return buff; 
 
42
unsigned char *Transparent_file::ptr()
 
43
{
 
44
  return buff;
46
45
}
47
46
 
48
47
off_t Transparent_file::start()
49
 
50
 
  return lower_bound; 
 
48
{
 
49
  return lower_bound;
51
50
}
52
51
 
53
52
off_t Transparent_file::end()
54
 
55
 
  return upper_bound; 
 
53
{
 
54
  return upper_bound;
56
55
}
57
56
 
58
57
off_t Transparent_file::read_next()
85
84
  if ((lower_bound <= offset) && (offset < upper_bound))
86
85
    return buff[offset - lower_bound];
87
86
 
88
 
  VOID(my_seek(filedes, offset, MY_SEEK_SET, MYF(0)));
 
87
  lseek(filedes, offset, SEEK_SET);
89
88
  /* read appropriate portion of the file */
90
89
  if ((bytes_read= my_read(filedes, buff, buff_size,
91
90
                           MYF(0))) == MY_FILE_ERROR)