~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/csv/transparent_file.cc

  • Committer: Brian Aker
  • Date: 2010-05-27 01:25:56 UTC
  • mfrom: (1567.1.4 new-staging)
  • Revision ID: brian@gaz-20100527012556-5zgkirkl7swbigd6
Merge of Brian, Paul. PBXT compile issue, and test framework cleanup. 

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