X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fio%2Funix%2Ffile.cpp;fp=source%2Fio%2Funix%2Ffile.cpp;h=b2c9089a8d6ecdf108aee88ec30ab38b7b6732bd;hb=609c9a508cfdc7b42c46c4f21d17639204165a00;hp=0000000000000000000000000000000000000000;hpb=b4806214e905752617691f851717033fd3f266c2;p=libs%2Fcore.git diff --git a/source/io/unix/file.cpp b/source/io/unix/file.cpp new file mode 100644 index 0000000..b2c9089 --- /dev/null +++ b/source/io/unix/file.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include "file.h" +#include "handle_private.h" + +using namespace std; + +namespace Msp { +namespace IO { + +void File::platform_init(const string &fn, CreateMode cm) +{ + int flags = 0; + switch(mode&M_RDWR) + { + case M_READ: flags |= O_RDONLY; break; + case M_WRITE: flags |= O_WRONLY; break; + case M_RDWR: flags |= O_RDWR; break; + default:; + } + + if(mode&M_WRITE) + { + if(cm&C_CREATE) + flags |= O_CREAT; + if(cm&C_TRUNCATE) + flags |= O_TRUNC; + if(cm&C_EXCLUSIVE) + flags |= O_EXCL; + } + if(mode&M_APPEND) + flags |= O_APPEND; + if(mode&M_NONBLOCK) + flags |= O_NONBLOCK; + + *handle = ::open(fn.c_str(), flags, 0666); + if(!handle) + { + int err = errno; + if(err==ENOENT) + throw file_not_found(fn); + else if(err==EEXIST) + throw file_already_exists(fn); + else + throw system_error(format("open(%s)", fn), err); + } +} + +void File::sync() +{ + signal_flush_required.emit(); + + fsync(*handle); +} + +} // namespace IO +} // namespace Msp