Posix.java revision 039f7599559fd7e48c354b99dcb94ff391f53349
1ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes/* 2ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * Copyright (C) 2011 The Android Open Source Project 3ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * 4ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License"); 5ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * you may not use this file except in compliance with the License. 6ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * You may obtain a copy of the License at 7ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * 8ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * http://www.apache.org/licenses/LICENSE-2.0 9ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * 10ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * Unless required by applicable law or agreed to in writing, software 11ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS, 12ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * See the License for the specific language governing permissions and 14ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes * limitations under the License. 15ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes */ 16ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes 17ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughespackage libcore.io; 18ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes 1952724d3ebd4ccaaa4b9f5576e329d4272cde8ea9Elliott Hughesimport java.io.FileDescriptor; 200a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughesimport java.net.InetAddress; 2123ec09188303a874b3b391f96ae0a29af002bff9Elliott Hughesimport java.net.InetSocketAddress; 220a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughesimport java.net.SocketAddress; 2326010ab930a2cee3bf10b9612cf070183c21228bElliott Hughesimport java.net.SocketException; 2426c7025a7a919044771fb89031161bd26fe03032Elliott Hughesimport java.nio.ByteBuffer; 254af0d8c99d68bcacff182699527d983a1d34fdbeElliott Hughesimport java.nio.NioUtils; 268b15dcc5890963edad4dfcf558cc16027c7985e5Elliott Hughesimport libcore.util.MutableInt; 278b15dcc5890963edad4dfcf558cc16027c7985e5Elliott Hughesimport libcore.util.MutableLong; 2852724d3ebd4ccaaa4b9f5576e329d4272cde8ea9Elliott Hughes 29ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughespublic final class Posix implements Os { 30ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes Posix() { } 31ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes 3226010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes public native FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException, SocketException; 33ddfdbb9d172fe9b72e08e8d7deab0aa3b8acf044Elliott Hughes public native boolean access(String path, int mode) throws ErrnoException; 3426010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes public native void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException; 35b7190190e0ef8de883c952efb319ce7748831faaElliott Hughes public native void chmod(String path, int mode) throws ErrnoException; 3644f7875f2985d7944c5afecc8394ad9f2219c806Elliott Hughes public native void chown(String path, int uid, int gid) throws ErrnoException; 37462bdac45c10f43d88d8f07f6994e272a27c14a2Elliott Hughes public native void close(FileDescriptor fd) throws ErrnoException; 3826010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes public native void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException; 39396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException; 40396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException; 41ddfdbb9d172fe9b72e08e8d7deab0aa3b8acf044Elliott Hughes public native String[] environ(); 4244f7875f2985d7944c5afecc8394ad9f2219c806Elliott Hughes public native void fchmod(FileDescriptor fd, int mode) throws ErrnoException; 4344f7875f2985d7944c5afecc8394ad9f2219c806Elliott Hughes public native void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException; 44fc549a0b0388987b26dea524894d75a63d14783bElliott Hughes public native int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException; 45fc549a0b0388987b26dea524894d75a63d14783bElliott Hughes public native int fcntlLong(FileDescriptor fd, int cmd, long arg) throws ErrnoException; 46fc549a0b0388987b26dea524894d75a63d14783bElliott Hughes public native int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException; 4752724d3ebd4ccaaa4b9f5576e329d4272cde8ea9Elliott Hughes public native void fdatasync(FileDescriptor fd) throws ErrnoException; 4847cb338d43f75dd998b29caaaa9446c5705217d1Elliott Hughes public native StructStat fstat(FileDescriptor fd) throws ErrnoException; 4959fa7163774d6930a174bc038414a4b780581957Elliott Hughes public native StructStatFs fstatfs(FileDescriptor fd) throws ErrnoException; 5052724d3ebd4ccaaa4b9f5576e329d4272cde8ea9Elliott Hughes public native void fsync(FileDescriptor fd) throws ErrnoException; 51f5333fd2094bdac4d6506177b1964b79afa64d77Elliott Hughes public native void ftruncate(FileDescriptor fd, long length) throws ErrnoException; 524f11ebea266eada830d507b8f011e811a8e5d7bcElliott Hughes public native String gai_strerror(int error); 531c039d71d3879f39e3a75b8788e656f7b4f88f08Elliott Hughes public native InetAddress[] getaddrinfo(String node, StructAddrinfo hints) throws GaiException; 54396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native int getegid(); 55396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native int geteuid(); 56396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native int getgid(); 57ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes public native String getenv(String name); 584f11ebea266eada830d507b8f011e811a8e5d7bcElliott Hughes public native String getnameinfo(InetAddress address, int flags) throws GaiException; 59396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native int getpid(); 60396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native int getppid(); 61d4419fce71d11ec8494525eca65e54d1aab51de6Elliott Hughes public native StructPasswd getpwnam(String name) throws ErrnoException; 62d4419fce71d11ec8494525eca65e54d1aab51de6Elliott Hughes public native StructPasswd getpwuid(int uid) throws ErrnoException; 630a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughes public native SocketAddress getsockname(FileDescriptor fd) throws ErrnoException; 640a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughes public native int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException; 650a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughes public native InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException; 660a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughes public native int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException; 670a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughes public native StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException; 680a9d1ee45a9884a9616624d747172e18734e8fe0Elliott Hughes public native StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException; 69396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native int getuid(); 70a37e971343883bb582a93ffbd9f0ba84f10e55baElliott Hughes public native String if_indextoname(int index); 71fc041ff241f9a7556e72236f130de0215ecd17dbElliott Hughes public native InetAddress inet_pton(int family, String address); 72a37e971343883bb582a93ffbd9f0ba84f10e55baElliott Hughes public native InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException; 738b15dcc5890963edad4dfcf558cc16027c7985e5Elliott Hughes public native int ioctlInt(FileDescriptor fd, int cmd, MutableInt arg) throws ErrnoException; 749a3f363523000704205df288f8b6f2f48c0d8563Elliott Hughes public native boolean isatty(FileDescriptor fd); 75a5fb706fe4a6dbeaaf4cb1f8bbc2c68b0a2a3f3cElliott Hughes public native void kill(int pid, int signal) throws ErrnoException; 7644f7875f2985d7944c5afecc8394ad9f2219c806Elliott Hughes public native void lchown(String path, int uid, int gid) throws ErrnoException; 77e1502d64e937001636fca3d62b2552ef2a34d05fElliott Hughes public native void listen(FileDescriptor fd, int backlog) throws ErrnoException; 78dedaccdfa07c370a58cba08b096133ad9eec0ec3Elliott Hughes public native long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException; 79e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes public native StructStat lstat(String path) throws ErrnoException; 800f746ff511162add42eeabaf14ba70ace874c6f4Elliott Hughes public native void mincore(long address, long byteCount, byte[] vector) throws ErrnoException; 81c7fa20701d5e9398c38f4615ed293acfce1c0cf6Elliott Hughes public native void mkdir(String path, int mode) throws ErrnoException; 827e13c0f05ac9e7c55682d10e953dd4cbd5e6107cElliott Hughes public native void mlock(long address, long byteCount) throws ErrnoException; 837e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes public native long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException; 847e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes public native void msync(long address, long byteCount, int flags) throws ErrnoException; 857e13c0f05ac9e7c55682d10e953dd4cbd5e6107cElliott Hughes public native void munlock(long address, long byteCount) throws ErrnoException; 867e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes public native void munmap(long address, long byteCount) throws ErrnoException; 870ac77ac8e915bff1a863e371f9b363033f9cf759Elliott Hughes public native FileDescriptor open(String path, int flags, int mode) throws ErrnoException; 8841f0605d2c809bd9bc1c0fb68d86b49a0f59b6c5Elliott Hughes public native FileDescriptor[] pipe() throws ErrnoException; 8970c820401677ca251ad09ac64cc23c760764e75dElliott Hughes public native int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException; 90e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException { 91e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes if (buffer.isDirect()) { 92e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes return preadBytes(fd, buffer, buffer.position(), buffer.remaining(), offset); 93e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes } else { 94e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes return preadBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining(), offset); 95e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes } 96e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes } 97e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException { 98e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes // This indirection isn't strictly necessary, but ensures that our public interface is type safe. 99e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes return preadBytes(fd, bytes, byteOffset, byteCount, offset); 100e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes } 101e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes private native int preadBytes(FileDescriptor fd, Object buffer, int bufferOffset, int byteCount, long offset) throws ErrnoException; 102e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException { 103e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes if (buffer.isDirect()) { 104e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes return pwriteBytes(fd, buffer, buffer.position(), buffer.remaining(), offset); 105e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes } else { 106e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes return pwriteBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining(), offset); 107e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes } 108e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes } 109e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes public int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException { 110e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes // This indirection isn't strictly necessary, but ensures that our public interface is type safe. 111e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes return pwriteBytes(fd, bytes, byteOffset, byteCount, offset); 112e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes } 113e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7Elliott Hughes private native int pwriteBytes(FileDescriptor fd, Object buffer, int bufferOffset, int byteCount, long offset) throws ErrnoException; 11426c7025a7a919044771fb89031161bd26fe03032Elliott Hughes public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException { 11526c7025a7a919044771fb89031161bd26fe03032Elliott Hughes if (buffer.isDirect()) { 1160568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes return readBytes(fd, buffer, buffer.position(), buffer.remaining()); 1170568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes } else { 1180568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes return readBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining()); 11926c7025a7a919044771fb89031161bd26fe03032Elliott Hughes } 12026c7025a7a919044771fb89031161bd26fe03032Elliott Hughes } 1210568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException { 1220568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes // This indirection isn't strictly necessary, but ensures that our public interface is type safe. 1230568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes return readBytes(fd, bytes, byteOffset, byteCount); 1240568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes } 1250568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes private native int readBytes(FileDescriptor fd, Object buffer, int offset, int byteCount) throws ErrnoException; 126bbac92e691de7d570928ddfba639067978e55b06Elliott Hughes public native int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException; 12726010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { 12823ec09188303a874b3b391f96ae0a29af002bff9Elliott Hughes if (buffer.isDirect()) { 129553d98af897f7202de5e5a776287de0b5ca8fe39Elliott Hughes return recvfromBytes(fd, buffer, buffer.position(), buffer.remaining(), flags, srcAddress); 13023ec09188303a874b3b391f96ae0a29af002bff9Elliott Hughes } else { 131553d98af897f7202de5e5a776287de0b5ca8fe39Elliott Hughes return recvfromBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining(), flags, srcAddress); 13223ec09188303a874b3b391f96ae0a29af002bff9Elliott Hughes } 13323ec09188303a874b3b391f96ae0a29af002bff9Elliott Hughes } 13426010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes public int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { 13523ec09188303a874b3b391f96ae0a29af002bff9Elliott Hughes // This indirection isn't strictly necessary, but ensures that our public interface is type safe. 136553d98af897f7202de5e5a776287de0b5ca8fe39Elliott Hughes return recvfromBytes(fd, bytes, byteOffset, byteCount, flags, srcAddress); 13723ec09188303a874b3b391f96ae0a29af002bff9Elliott Hughes } 13826010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes private native int recvfromBytes(FileDescriptor fd, Object buffer, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException; 139c7fa20701d5e9398c38f4615ed293acfce1c0cf6Elliott Hughes public native void remove(String path) throws ErrnoException; 140a20cc6fca30d18e05db67ceeb0403b7b58ffd364Elliott Hughes public native void rename(String oldPath, String newPath) throws ErrnoException; 1418b15dcc5890963edad4dfcf558cc16027c7985e5Elliott Hughes public native long sendfile(FileDescriptor outFd, FileDescriptor inFd, MutableLong inOffset, long byteCount) throws ErrnoException; 14226010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes public int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { 14390d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes if (buffer.isDirect()) { 14490d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes return sendtoBytes(fd, buffer, buffer.position(), buffer.remaining(), flags, inetAddress, port); 14590d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes } else { 14690d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes return sendtoBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining(), flags, inetAddress, port); 14790d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes } 14890d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes } 14926010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes public int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { 15090d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes // This indirection isn't strictly necessary, but ensures that our public interface is type safe. 15190d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes return sendtoBytes(fd, bytes, byteOffset, byteCount, flags, inetAddress, port); 15290d96a4f168b7e56cff54dc94dca2f3cde60ebcdElliott Hughes } 15326010ab930a2cee3bf10b9612cf070183c21228bElliott Hughes private native int sendtoBytes(FileDescriptor fd, Object buffer, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException; 154396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native void setegid(int egid) throws ErrnoException; 155895a613aa2aec6aa6d03b29755cf2fea584909adElliott Hughes public native void setenv(String name, String value, boolean overwrite) throws ErrnoException; 156396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native void seteuid(int euid) throws ErrnoException; 157396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native void setgid(int gid) throws ErrnoException; 1586c9b5377550a9649ed1532d1fcdfeba116c74eadElliott Hughes public native int setsid() throws ErrnoException; 159c63f0d4e80a9fd3bdf99cd438d108b750226736aElliott Hughes public native void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException; 160b974666d79ebc392b37ec1ae83aae57ae6331c08Elliott Hughes public native void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException; 161454a95f6a28855aa3c88d168b15a45bf315efc99Elliott Hughes public native void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException; 162b974666d79ebc392b37ec1ae83aae57ae6331c08Elliott Hughes public native void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException; 163438cb9e440d250c8aa5daf4fae0c400dce8b1499Elliott Hughes public native void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException; 164c63f0d4e80a9fd3bdf99cd438d108b750226736aElliott Hughes public native void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException; 165c63f0d4e80a9fd3bdf99cd438d108b750226736aElliott Hughes public native void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException; 166396a9c666da353b910b515d12eb1c43adfddb0c8Elliott Hughes public native void setuid(int uid) throws ErrnoException; 16759e4744d27231f260271dbbca406e0cc39768116Elliott Hughes public native void shutdown(FileDescriptor fd, int how) throws ErrnoException; 168454a95f6a28855aa3c88d168b15a45bf315efc99Elliott Hughes public native FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException; 1693218082325b6b8713a8ac15731482e3da86a7df9Elliott Hughes public native void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException; 17047cb338d43f75dd998b29caaaa9446c5705217d1Elliott Hughes public native StructStat stat(String path) throws ErrnoException; 17159fa7163774d6930a174bc038414a4b780581957Elliott Hughes public native StructStatFs statfs(String path) throws ErrnoException; 172ddfdbb9d172fe9b72e08e8d7deab0aa3b8acf044Elliott Hughes public native String strerror(int errno); 173a20cc6fca30d18e05db67ceeb0403b7b58ffd364Elliott Hughes public native void symlink(String oldPath, String newPath) throws ErrnoException; 1746fc1a0e1e68dc2e0d12341548e58fa7f1c5dafc4Elliott Hughes public native long sysconf(int name); 175bb5816aa1626eb2f6263bd21479600b114c8a1bdJohan Redestig public native void tcdrain(FileDescriptor fd) throws ErrnoException; 176039f7599559fd7e48c354b99dcb94ff391f53349Elliott Hughes public native void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException; 177c79d3ef4dcd25f0e264bf957861e2632da93e62dNick Kralevich public int umask(int mask) { 178c79d3ef4dcd25f0e264bf957861e2632da93e62dNick Kralevich if ((mask & 0777) != mask) { 179c79d3ef4dcd25f0e264bf957861e2632da93e62dNick Kralevich throw new IllegalArgumentException("Invalid umask: " + mask); 180c79d3ef4dcd25f0e264bf957861e2632da93e62dNick Kralevich } 181c79d3ef4dcd25f0e264bf957861e2632da93e62dNick Kralevich return umaskImpl(mask); 182c79d3ef4dcd25f0e264bf957861e2632da93e62dNick Kralevich } 183c79d3ef4dcd25f0e264bf957861e2632da93e62dNick Kralevich private native int umaskImpl(int mask); 1849b510df35b57946d843ffc34cf23fdcfc84c5220Elliott Hughes public native StructUtsname uname(); 185895a613aa2aec6aa6d03b29755cf2fea584909adElliott Hughes public native void unsetenv(String name) throws ErrnoException; 1869e67ca71d3d4a489a157abadc5ba519ced7a0b50Elliott Hughes public native int waitpid(int pid, MutableInt status, int options) throws ErrnoException; 18778c7cc547101002b9f9043cf3845970719d1bda8Elliott Hughes public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException { 18878c7cc547101002b9f9043cf3845970719d1bda8Elliott Hughes if (buffer.isDirect()) { 1890568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes return writeBytes(fd, buffer, buffer.position(), buffer.remaining()); 1900568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes } else { 1910568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes return writeBytes(fd, NioUtils.unsafeArray(buffer), NioUtils.unsafeArrayOffset(buffer) + buffer.position(), buffer.remaining()); 19278c7cc547101002b9f9043cf3845970719d1bda8Elliott Hughes } 19378c7cc547101002b9f9043cf3845970719d1bda8Elliott Hughes } 1940568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException { 1950568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes // This indirection isn't strictly necessary, but ensures that our public interface is type safe. 1960568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes return writeBytes(fd, bytes, byteOffset, byteCount); 1970568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes } 1980568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes private native int writeBytes(FileDescriptor fd, Object buffer, int offset, int byteCount) throws ErrnoException; 199bbac92e691de7d570928ddfba639067978e55b06Elliott Hughes public native int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException; 200ec617e2cb4a374f0fd8fbda4a633214cf23a59a9Elliott Hughes} 201