X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Funix%2Fhandle.cpp;h=cbffa48e62a7354522a8d9efb8fcafe8f8c36c60;hp=9546df9f579c657f61f658ee235db3e172eec7dd;hb=292aed8e23ea543b089d5f2a73000de4640befe7;hpb=609c9a508cfdc7b42c46c4f21d17639204165a00 diff --git a/source/io/unix/handle.cpp b/source/io/unix/handle.cpp index 9546df9..cbffa48 100644 --- a/source/io/unix/handle.cpp +++ b/source/io/unix/handle.cpp @@ -8,16 +8,16 @@ namespace Msp { namespace IO { -Handle::operator const void *() const +void sys_set_blocking(Handle &handle, bool b) { - return priv->handle!=-1 ? this : 0; + int flags = fcntl(*handle, F_GETFL); + fcntl(*handle, F_SETFL, (flags&~O_NONBLOCK)|(b?0:O_NONBLOCK)); } - -void sys_set_blocking(Handle &handle, bool b) +void sys_set_inherit(Handle &handle, bool i) { int flags = fcntl(*handle, F_GETFD); - fcntl(*handle, F_SETFL, (flags&~O_NONBLOCK)|(b?0:O_NONBLOCK)); + fcntl(*handle, F_SETFD, (flags&~O_CLOEXEC)|(i?O_CLOEXEC:0)); } unsigned sys_read(Handle &handle, char *buf, unsigned size) @@ -50,7 +50,11 @@ unsigned sys_write(Handle &handle, const char *buf, unsigned size) void sys_close(Handle &handle) { - close(*handle); + if(handle) + { + close(*handle); + *handle = INVALID_HANDLE_VALUE; + } } } // namespace IO