~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/csv/transparent_file.cc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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
16
19
 
17
 
#include "config.h"
18
 
#include <cstdlib>
19
 
#include "drizzled/internal/my_sys.h"
 
20
#include "mysql_priv.h"
20
21
#include "transparent_file.h"
21
22
 
22
23
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
23
 
{
24
 
  buff= static_cast<unsigned char *>(malloc(buff_size*sizeof(unsigned char)));
 
24
 
25
  buff= (uchar *) my_malloc(buff_size*sizeof(uchar),  MYF(MY_WME)); 
25
26
}
26
27
 
27
28
Transparent_file::~Transparent_file()
28
 
{
29
 
  free(buff);
 
29
 
30
  my_free((uchar*)buff, MYF(MY_ALLOW_ZERO_PTR)); 
30
31
}
31
32
 
32
 
void Transparent_file::init_buff(int filedes_arg)
 
33
void Transparent_file::init_buff(File filedes_arg)
33
34
{
34
35
  filedes= filedes_arg;
35
36
  /* read the beginning of the file */
36
37
  lower_bound= 0;
37
 
  lseek(filedes, 0, SEEK_SET);
 
38
  VOID(my_seek(filedes, 0, MY_SEEK_SET, MYF(0)));
38
39
  if (filedes && buff)
39
40
    upper_bound= my_read(filedes, buff, buff_size, MYF(0));
40
41
}
41
42
 
42
 
unsigned char *Transparent_file::ptr()
43
 
{
44
 
  return buff;
 
43
uchar *Transparent_file::ptr()
 
44
 
45
  return buff; 
45
46
}
46
47
 
47
48
off_t Transparent_file::start()
48
 
{
49
 
  return lower_bound;
 
49
 
50
  return lower_bound; 
50
51
}
51
52
 
52
53
off_t Transparent_file::end()
53
 
{
54
 
  return upper_bound;
 
54
 
55
  return upper_bound; 
55
56
}
56
57
 
57
58
off_t Transparent_file::read_next()
84
85
  if ((lower_bound <= offset) && (offset < upper_bound))
85
86
    return buff[offset - lower_bound];
86
87
 
87
 
  lseek(filedes, offset, SEEK_SET);
 
88
  VOID(my_seek(filedes, offset, MY_SEEK_SET, MYF(0)));
88
89
  /* read appropriate portion of the file */
89
90
  if ((bytes_read= my_read(filedes, buff, buff_size,
90
91
                           MYF(0))) == MY_FILE_ERROR)