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 mode = b?(mode&~M_NONBLOCK):(mode|M_NONBLOCK);
32 sys_set_blocking(handle, b);
35 unsigned File::do_write(const char *buf, unsigned size)
37 check_access(M_WRITE);
47 return sys_write(handle, buf, size);
50 unsigned File::do_read(char *buf, unsigned size)
57 unsigned ret = sys_read(handle, buf, size);
64 SeekOffset File::seek(SeekOffset off, SeekType type)
66 signal_flush_required.emit();
67 off = sys_seek(handle, off, type);
73 SeekOffset File::tell() const
75 return sys_seek(const_cast<Handle &>(handle), 0, S_CUR);
78 const Handle &File::get_handle(Mode m)
85 BufferedFile::BufferedFile(const string &fn, Mode m, File::CreateMode cm):
91 file.signal_end_of_file.connect(sigc::mem_fun(this, &BufferedFile::set_eof));
94 unsigned BufferedFile::do_write(const char *buf, unsigned size)
96 unsigned ret = buffer.write(buf, size);
101 unsigned BufferedFile::do_read(char *buf, unsigned size)
103 unsigned ret = buffer.read(buf, size);
108 unsigned BufferedFile::put(char c)
110 unsigned ret = buffer.put(c);
115 bool BufferedFile::getline(string &line)
117 bool ret = buffer.getline(line);
119 position += line.size();
123 int BufferedFile::get()
125 int ret = buffer.get();
131 SeekOffset BufferedFile::seek(SeekOffset offset, SeekType type)
139 signal_flush_required.emit();
140 position = file.seek(offset, type);