~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/csv/transparent_file.cc

  • Committer: Monty Taylor
  • Date: 2008-11-16 06:29:53 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116062953-ivdltjmfe009b5fr
Moved stuff into item/

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
 
17
 
#include "config.h"
18
 
#include <cstdlib>
19
 
#include "drizzled/internal/my_sys.h"
 
17
#include <drizzled/common_includes.h>
20
18
#include "transparent_file.h"
21
19
 
22
 
using namespace drizzled;
23
 
 
24
20
Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
25
 
{
26
 
  buff= static_cast<unsigned char *>(malloc(buff_size*sizeof(unsigned char)));
 
21
 
22
  buff= (unsigned char *) my_malloc(buff_size*sizeof(unsigned char),  MYF(MY_WME)); 
27
23
}
28
24
 
29
25
Transparent_file::~Transparent_file()
30
 
{
31
 
  free(buff);
 
26
 
27
  free((unsigned char*)buff); 
32
28
}
33
29
 
34
 
void Transparent_file::init_buff(int filedes_arg)
 
30
void Transparent_file::init_buff(File filedes_arg)
35
31
{
36
32
  filedes= filedes_arg;
37
33
  /* read the beginning of the file */
38
34
  lower_bound= 0;
39
 
  lseek(filedes, 0, SEEK_SET);
 
35
  my_seek(filedes, 0, MY_SEEK_SET, MYF(0));
40
36
  if (filedes && buff)
41
 
    upper_bound= internal::my_read(filedes, buff, buff_size, MYF(0));
 
37
    upper_bound= my_read(filedes, buff, buff_size, MYF(0));
42
38
}
43
39
 
44
40
unsigned char *Transparent_file::ptr()
45
 
{
46
 
  return buff;
 
41
 
42
  return buff; 
47
43
}
48
44
 
49
45
off_t Transparent_file::start()
50
 
{
51
 
  return lower_bound;
 
46
 
47
  return lower_bound; 
52
48
}
53
49
 
54
50
off_t Transparent_file::end()
55
 
{
56
 
  return upper_bound;
 
51
 
52
  return upper_bound; 
57
53
}
58
54
 
59
55
off_t Transparent_file::read_next()
64
60
     No need to seek here, as the file managed by Transparent_file class
65
61
     always points to upper_bound byte
66
62
  */
67
 
  if ((bytes_read= internal::my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
 
63
  if ((bytes_read= my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
68
64
    return (off_t) -1;
69
65
 
70
66
  /* end of file */
86
82
  if ((lower_bound <= offset) && (offset < upper_bound))
87
83
    return buff[offset - lower_bound];
88
84
 
89
 
  lseek(filedes, offset, SEEK_SET);
 
85
  my_seek(filedes, offset, MY_SEEK_SET, MYF(0));
90
86
  /* read appropriate portion of the file */
91
 
  if ((bytes_read= internal::my_read(filedes, buff, buff_size,
 
87
  if ((bytes_read= my_read(filedes, buff, buff_size,
92
88
                           MYF(0))) == MY_FILE_ERROR)
93
89
    return 0;
94
90