]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/unix/handle.cpp
Use size_t for sizes in I/O classes
[libs/core.git] / source / io / unix / handle.cpp
index cb3ce4cae54c16aae8ceb83194044aac98aca94c..c9bf3b1384f08dce4c2f44d2e4edfdc5fc4114be 100644 (file)
@@ -5,6 +5,8 @@
 #include "handle.h"
 #include "handle_private.h"
 
+using namespace std;
+
 namespace Msp {
 namespace IO {
 
@@ -14,9 +16,15 @@ void sys_set_blocking(Handle &handle, bool b)
        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)