2 #include "handle_private.h"
9 File::File(const string &fn, Mode m, CreateMode cm)
12 throw invalid_argument("File::File mode");
13 if(cm&~(C_CREATE|C_TRUNCATE|C_EXCLUSIVE))
14 throw invalid_argument("File::File create");
15 if((cm&C_EXCLUSIVE) && (!(cm&C_CREATE) || (cm&C_TRUNCATE)))
16 throw invalid_argument("File::File create");
20 platform_init(fn, cm);
25 signal_flush_required.emit();
29 void File::set_block(bool b)
31 adjust_mode(mode, M_NONBLOCK, !b);
32 sys_set_blocking(handle, b);
35 void File::set_inherit(bool i)
37 adjust_mode(mode, M_INHERIT, i);
38 sys_set_inherit(handle, i);
41 unsigned File::do_write(const char *buf, unsigned size)
43 check_access(M_WRITE);
53 return sys_write(handle, buf, size);
56 unsigned File::do_read(char *buf, unsigned size)
63 unsigned ret = sys_read(handle, buf, size);
70 SeekOffset File::seek(SeekOffset off, SeekType type)
72 signal_flush_required.emit();
73 off = sys_seek(handle, off, type);
79 SeekOffset File::tell() const
81 return sys_seek(const_cast<Handle &>(handle), 0, S_CUR);
84 const Handle &File::get_handle(Mode m)
91 BufferedFile::BufferedFile(const string &fn, Mode m, File::CreateMode cm):
97 file.signal_end_of_file.connect(sigc::mem_fun(this, &BufferedFile::set_eof));
100 void BufferedFile::set_block(bool b)
105 void BufferedFile::set_inherit(bool)
107 throw logic_error("BufferedFile::set_inherit");
110 unsigned BufferedFile::do_write(const char *buf, unsigned size)
112 unsigned ret = buffer.write(buf, size);
117 unsigned BufferedFile::do_read(char *buf, unsigned size)
119 unsigned ret = buffer.read(buf, size);
124 unsigned BufferedFile::put(char c)
126 unsigned ret = buffer.put(c);
131 bool BufferedFile::getline(string &line)
133 bool ret = buffer.getline(line);
135 position += line.size();
139 int BufferedFile::get()
141 int ret = buffer.get();
147 const Handle &BufferedFile::get_handle(Mode)
149 throw logic_error("BufferedFile::get_handle");
152 SeekOffset BufferedFile::seek(SeekOffset offset, SeekType type)
160 signal_flush_required.emit();
161 position = file.seek(offset, type);