Skip to content

Commit

Permalink
read(2) and write(2) should return a native long sized value
Browse files Browse the repository at this point in the history
  • Loading branch information
vp-of-awesome committed Mar 13, 2012
1 parent 0c99b96 commit 09ca35c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/jnr/enxio/channels/Native.java
Expand Up @@ -39,8 +39,8 @@ public static interface LibC {
public static final int O_NONBLOCK = jnr.constants.platform.OpenFlags.O_NONBLOCK.intValue();

public int close(int fd);
public int read(int fd, @Out ByteBuffer data, long size);
public int write(int fd, @In ByteBuffer data, long size);
public long read(int fd, @Out ByteBuffer data, long size);
public long write(int fd, @In ByteBuffer data, long size);
public int fcntl(int fd, int cmd, int data);
public int poll(@In @Out ByteBuffer pfds, int nfds, int timeout);
public int kqueue();
Expand Down Expand Up @@ -83,33 +83,33 @@ public static int read(int fd, ByteBuffer dst) throws IOException {
throw new IllegalArgumentException("Read-only buffer");
}

int n;
long n;
do {
n = libc().read(fd, dst, dst.remaining());
} while (n < 0 && Errno.EINTR.equals(getLastError()));

if (n > 0) {
dst.position(dst.position() + n);
dst.position(dst.position() + (int) n);
}

return n;
return (int) n;
}

public static int write(int fd, ByteBuffer src) throws IOException {
if (src == null) {
throw new NullPointerException("Source buffer cannot be null");
}

int n;
long n;
do {
n = libc().write(fd, src, src.remaining());
} while (n < 0 && Errno.EINTR.equals(getLastError()));

if (n > 0) {
src.position(src.position() + n);
src.position(src.position() + (int) n);
}

return n;
return (int) n;
}

public static void setBlocking(int fd, boolean block) {
Expand Down

0 comments on commit 09ca35c

Please sign in to comment.