X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Funix%2Fhandle.cpp;h=c9bf3b1384f08dce4c2f44d2e4edfdc5fc4114be;hp=307da64fac0a374b32341c05c9092548d69f1ce4;hb=c8bf2d6c15893ccc9dbc4e04611b7229029f4808;hpb=0f5709b1262b17505c5bab06951611968a4bd326 diff --git a/source/io/unix/handle.cpp b/source/io/unix/handle.cpp index 307da64..c9bf3b1 100644 --- a/source/io/unix/handle.cpp +++ b/source/io/unix/handle.cpp @@ -5,18 +5,26 @@ #include "handle.h" #include "handle_private.h" +using namespace std; + namespace Msp { namespace IO { void sys_set_blocking(Handle &handle, bool b) { - int flags = fcntl(*handle, F_GETFD); + int flags = fcntl(*handle, F_GETFL); fcntl(*handle, F_SETFL, (flags&~O_NONBLOCK)|(b?0:O_NONBLOCK)); } -unsigned sys_read(Handle &handle, char *buf, unsigned size) +void sys_set_inherit(Handle &handle, bool i) +{ + int flags = fcntl(*handle, F_GETFD); + fcntl(*handle, F_SETFD, (flags&~O_CLOEXEC)|(i?O_CLOEXEC:0)); +} + +size_t sys_read(Handle &handle, char *buf, size_t size) { - int ret = read(*handle, buf, size); + ssize_t ret = read(*handle, buf, size); if(ret==-1) { if(errno==EAGAIN) @@ -28,9 +36,9 @@ unsigned sys_read(Handle &handle, char *buf, unsigned size) return ret; } -unsigned sys_write(Handle &handle, const char *buf, unsigned size) +size_t sys_write(Handle &handle, const char *buf, size_t size) { - int ret = write(*handle, buf, size); + ssize_t ret = write(*handle, buf, size); if(ret==-1) { if(errno==EAGAIN)