summaryrefslogtreecommitdiff
path: root/storage/csv/transparent_file.cc
diff options
context:
space:
mode:
authorbrian@zim.(none) <>2007-01-03 17:26:45 -0800
committerbrian@zim.(none) <>2007-01-03 17:26:45 -0800
commit6ff70926985c49a32bab682d5ef6e54dcca86782 (patch)
treeda45ed3f5a6f4370b7c05fb2e7d171f8f3257565 /storage/csv/transparent_file.cc
parent7b9a5f6de2a97a5ac245c6fba81d0adf157702ff (diff)
downloadmariadb-git-6ff70926985c49a32bab682d5ef6e54dcca86782.tar.gz
Split out the hidden class from the ha_tina file (probably should have just deleted it...) but this is a bit better.
Diffstat (limited to 'storage/csv/transparent_file.cc')
-rw-r--r--storage/csv/transparent_file.cc104
1 files changed, 104 insertions, 0 deletions
diff --git a/storage/csv/transparent_file.cc b/storage/csv/transparent_file.cc
new file mode 100644
index 00000000000..27cc8c024b4
--- /dev/null
+++ b/storage/csv/transparent_file.cc
@@ -0,0 +1,104 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifdef USE_PRAGMA_IMPLEMENTATION
+#pragma implementation // gcc: Class implementation
+#endif
+
+#include "mysql_priv.h"
+#include "transparent_file.h"
+
+Transparent_file::Transparent_file() : lower_bound(0), buff_size(IO_SIZE)
+{
+ buff= (byte *) my_malloc(buff_size*sizeof(byte), MYF(MY_WME));
+}
+
+Transparent_file::~Transparent_file()
+{
+ my_free((gptr)buff, MYF(MY_ALLOW_ZERO_PTR));
+}
+
+void Transparent_file::init_buff(File filedes_arg)
+{
+ filedes= filedes_arg;
+ /* read the beginning of the file */
+ lower_bound= 0;
+ VOID(my_seek(filedes, 0, MY_SEEK_SET, MYF(0)));
+ if (filedes && buff)
+ upper_bound= my_read(filedes, buff, buff_size, MYF(0));
+}
+
+byte *Transparent_file::ptr()
+{
+ return buff;
+}
+
+off_t Transparent_file::start()
+{
+ return lower_bound;
+}
+
+off_t Transparent_file::end()
+{
+ return upper_bound;
+}
+
+off_t Transparent_file::read_next()
+{
+ off_t bytes_read;
+
+ /*
+ No need to seek here, as the file managed by Transparent_file class
+ always points to upper_bound byte
+ */
+ if ((bytes_read= my_read(filedes, buff, buff_size, MYF(0))) == MY_FILE_ERROR)
+ return -1;
+
+ /* end of file */
+ if (!bytes_read)
+ return -1;
+
+ lower_bound= upper_bound;
+ upper_bound+= bytes_read;
+
+ return lower_bound;
+}
+
+
+char Transparent_file::get_value(off_t offset)
+{
+ off_t bytes_read;
+
+ /* check boundaries */
+ if ((lower_bound <= offset) && (offset < upper_bound))
+ return buff[offset - lower_bound];
+ else
+ {
+ VOID(my_seek(filedes, offset, MY_SEEK_SET, MYF(0)));
+ /* read appropriate portion of the file */
+ if ((bytes_read= my_read(filedes, buff, buff_size,
+ MYF(0))) == MY_FILE_ERROR)
+ return 0;
+
+ lower_bound= offset;
+ upper_bound= lower_bound + bytes_read;
+
+ /* end of file */
+ if (upper_bound == offset)
+ return 0;
+
+ return buff[0];
+ }
+}