1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.system; 18 19 import java.io.FileDescriptor; 20 import java.io.InterruptedIOException; 21 import java.net.InetAddress; 22 import java.net.InetSocketAddress; 23 import java.net.SocketAddress; 24 import java.net.SocketException; 25 import java.nio.ByteBuffer; 26 import libcore.io.Libcore; 27 28 /** 29 * Access to low-level system functionality. Most of these are system calls. Most users will want 30 * to use higher-level APIs where available, but this class provides access to the underlying 31 * primitives used to implement the higher-level APIs. 32 * 33 * <p>The corresponding constants can be found in {@link OsConstants}. 34 */ 35 public final class Os { Os()36 private Os() {} 37 38 /** 39 * See <a href="http://man7.org/linux/man-pages/man2/accept.2.html">accept(2)</a>. 40 */ accept(FileDescriptor fd, InetSocketAddress peerAddress)41 public static FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException, SocketException { return Libcore.os.accept(fd, peerAddress); } 42 43 /** 44 * TODO Change the public API by removing the overload above and unhiding this version. 45 * @hide 46 */ accept(FileDescriptor fd, SocketAddress peerAddress)47 public static FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException { return Libcore.os.accept(fd, peerAddress); } 48 49 /** 50 * See <a href="http://man7.org/linux/man-pages/man2/access.2.html">access(2)</a>. 51 */ access(String path, int mode)52 public static boolean access(String path, int mode) throws ErrnoException { return Libcore.os.access(path, mode); } 53 android_getaddrinfo(String node, StructAddrinfo hints, int netId)54 /** @hide */ public static InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException { return Libcore.os.android_getaddrinfo(node, hints, netId); } 55 56 /** 57 * See <a href="http://man7.org/linux/man-pages/man2/bind.2.html">bind(2)</a>. 58 */ bind(FileDescriptor fd, InetAddress address, int port)59 public static void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.bind(fd, address, port); } 60 bind(FileDescriptor fd, SocketAddress address)61 /** @hide */ public static void bind(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { Libcore.os.bind(fd, address); } 62 63 /** 64 * See <a href="http://man7.org/linux/man-pages/man2/capget.2.html">capget(2)</a>. 65 * 66 * @hide 67 */ capget(StructCapUserHeader hdr)68 public static StructCapUserData[] capget(StructCapUserHeader hdr) throws ErrnoException { 69 return Libcore.os.capget(hdr); 70 } 71 72 /** 73 * See <a href="http://man7.org/linux/man-pages/man2/capset.2.html">capset(2)</a>. 74 * 75 * @hide 76 */ capset(StructCapUserHeader hdr, StructCapUserData[] data)77 public static void capset(StructCapUserHeader hdr, StructCapUserData[] data) 78 throws ErrnoException { 79 Libcore.os.capset(hdr, data); 80 } 81 82 /** 83 * See <a href="http://man7.org/linux/man-pages/man2/chmod.2.html">chmod(2)</a>. 84 */ chmod(String path, int mode)85 public static void chmod(String path, int mode) throws ErrnoException { Libcore.os.chmod(path, mode); } 86 87 /** 88 * See <a href="http://man7.org/linux/man-pages/man2/chown.2.html">chown(2)</a>. 89 */ chown(String path, int uid, int gid)90 public static void chown(String path, int uid, int gid) throws ErrnoException { Libcore.os.chown(path, uid, gid); } 91 92 /** 93 * See <a href="http://man7.org/linux/man-pages/man2/close.2.html">close(2)</a>. 94 */ close(FileDescriptor fd)95 public static void close(FileDescriptor fd) throws ErrnoException { Libcore.os.close(fd); } 96 97 /** 98 * See <a href="http://man7.org/linux/man-pages/man2/connect.2.html">connect(2)</a>. 99 */ connect(FileDescriptor fd, InetAddress address, int port)100 public static void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.connect(fd, address, port); } 101 connect(FileDescriptor fd, SocketAddress address)102 /** @hide */ public static void connect(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { Libcore.os.connect(fd, address); } 103 104 /** 105 * See <a href="http://man7.org/linux/man-pages/man2/dup.2.html">dup(2)</a>. 106 */ dup(FileDescriptor oldFd)107 public static FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return Libcore.os.dup(oldFd); } 108 109 /** 110 * See <a href="http://man7.org/linux/man-pages/man2/dup2.2.html">dup2(2)</a>. 111 */ dup2(FileDescriptor oldFd, int newFd)112 public static FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return Libcore.os.dup2(oldFd, newFd); } 113 114 /** 115 * See <a href="http://man7.org/linux/man-pages/man3/environ.3.html">environ(3)</a>. 116 */ environ()117 public static String[] environ() { return Libcore.os.environ(); } 118 119 /** 120 * See <a href="http://man7.org/linux/man-pages/man2/execv.2.html">execv(2)</a>. 121 */ execv(String filename, String[] argv)122 public static void execv(String filename, String[] argv) throws ErrnoException { Libcore.os.execv(filename, argv); } 123 124 /** 125 * See <a href="http://man7.org/linux/man-pages/man2/execve.2.html">execve(2)</a>. 126 */ execve(String filename, String[] argv, String[] envp)127 public static void execve(String filename, String[] argv, String[] envp) throws ErrnoException { Libcore.os.execve(filename, argv, envp); } 128 129 /** 130 * See <a href="http://man7.org/linux/man-pages/man2/fchmod.2.html">fchmod(2)</a>. 131 */ fchmod(FileDescriptor fd, int mode)132 public static void fchmod(FileDescriptor fd, int mode) throws ErrnoException { Libcore.os.fchmod(fd, mode); } 133 134 /** 135 * See <a href="http://man7.org/linux/man-pages/man2/fchown.2.html">fchown(2)</a>. 136 */ fchown(FileDescriptor fd, int uid, int gid)137 public static void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException { Libcore.os.fchown(fd, uid, gid); } 138 fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg)139 /** @hide */ public static int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException, InterruptedIOException { return Libcore.os.fcntlFlock(fd, cmd, arg); } fcntlInt(FileDescriptor fd, int cmd, int arg)140 /** @hide */ public static int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException { return Libcore.os.fcntlInt(fd, cmd, arg); } fcntlVoid(FileDescriptor fd, int cmd)141 /** @hide */ public static int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return Libcore.os.fcntlVoid(fd, cmd); } 142 143 /** 144 * See <a href="http://man7.org/linux/man-pages/man2/fdatasync.2.html">fdatasync(2)</a>. 145 */ fdatasync(FileDescriptor fd)146 public static void fdatasync(FileDescriptor fd) throws ErrnoException { Libcore.os.fdatasync(fd); } 147 148 /** 149 * See <a href="http://man7.org/linux/man-pages/man2/fstat.2.html">fstat(2)</a>. 150 */ fstat(FileDescriptor fd)151 public static StructStat fstat(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstat(fd); } 152 153 /** 154 * See <a href="http://man7.org/linux/man-pages/man2/fstatvfs.2.html">fstatvfs(2)</a>. 155 */ fstatvfs(FileDescriptor fd)156 public static StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstatvfs(fd); } 157 158 /** 159 * See <a href="http://man7.org/linux/man-pages/man2/fsync.2.html">fsync(2)</a>. 160 */ fsync(FileDescriptor fd)161 public static void fsync(FileDescriptor fd) throws ErrnoException { Libcore.os.fsync(fd); } 162 163 /** 164 * See <a href="http://man7.org/linux/man-pages/man2/ftruncate.2.html">ftruncate(2)</a>. 165 */ ftruncate(FileDescriptor fd, long length)166 public static void ftruncate(FileDescriptor fd, long length) throws ErrnoException { Libcore.os.ftruncate(fd, length); } 167 168 /** 169 * See <a href="http://man7.org/linux/man-pages/man3/gai_strerror.3.html">gai_strerror(3)</a>. 170 */ gai_strerror(int error)171 public static String gai_strerror(int error) { return Libcore.os.gai_strerror(error); } 172 173 /** 174 * See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html">getegid(2)</a>. 175 */ getegid()176 public static int getegid() { return Libcore.os.getegid(); } 177 178 /** 179 * See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html">geteuid(2)</a>. 180 */ geteuid()181 public static int geteuid() { return Libcore.os.geteuid(); } 182 183 /** 184 * See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html">getgid(2)</a>. 185 */ getgid()186 public static int getgid() { return Libcore.os.getgid(); } 187 188 /** 189 * See <a href="http://man7.org/linux/man-pages/man3/getenv.3.html">getenv(3)</a>. 190 */ getenv(String name)191 public static String getenv(String name) { return Libcore.os.getenv(name); } 192 193 /** 194 * See <a href="http://man7.org/linux/man-pages/man3/getifaddrs.3.html">getifaddrs(3)</a>. 195 */ getifaddrs()196 /** @hide */ public static StructIfaddrs[] getifaddrs() throws ErrnoException { return Libcore.os.getifaddrs(); } 197 getnameinfo(InetAddress address, int flags)198 /** @hide */ public static String getnameinfo(InetAddress address, int flags) throws GaiException { return Libcore.os.getnameinfo(address, flags); } 199 200 /** 201 * See <a href="http://man7.org/linux/man-pages/man2/getpeername.2.html">getpeername(2)</a>. 202 */ getpeername(FileDescriptor fd)203 public static SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return Libcore.os.getpeername(fd); } 204 205 /** 206 * See <a href="http://man7.org/linux/man-pages/man2/getpgid.2.html">getpgid(2)</a>. 207 */ getpgid(int pid)208 /** @hide */ public static int getpgid(int pid) throws ErrnoException { return Libcore.os.getpgid(pid); } 209 210 /** 211 * See <a href="http://man7.org/linux/man-pages/man2/getpid.2.html">getpid(2)</a>. 212 */ getpid()213 public static int getpid() { return Libcore.os.getpid(); } 214 215 /** 216 * See <a href="http://man7.org/linux/man-pages/man2/getppid.2.html">getppid(2)</a>. 217 */ getppid()218 public static int getppid() { return Libcore.os.getppid(); } 219 getpwnam(String name)220 /** @hide */ public static StructPasswd getpwnam(String name) throws ErrnoException { return Libcore.os.getpwnam(name); } 221 getpwuid(int uid)222 /** @hide */ public static StructPasswd getpwuid(int uid) throws ErrnoException { return Libcore.os.getpwuid(uid); } 223 getrlimit(int resource)224 /** @hide */ public static StructRlimit getrlimit(int resource) throws ErrnoException { return Libcore.os.getrlimit(resource); } 225 226 /** 227 * See <a href="http://man7.org/linux/man-pages/man2/getsockname.2.html">getsockname(2)</a>. 228 */ getsockname(FileDescriptor fd)229 public static SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return Libcore.os.getsockname(fd); } 230 getsockoptByte(FileDescriptor fd, int level, int option)231 /** @hide */ public static int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptByte(fd, level, option); } getsockoptInAddr(FileDescriptor fd, int level, int option)232 /** @hide */ public static InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInAddr(fd, level, option); } getsockoptInt(FileDescriptor fd, int level, int option)233 /** @hide */ public static int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInt(fd, level, option); } getsockoptLinger(FileDescriptor fd, int level, int option)234 /** @hide */ public static StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptLinger(fd, level, option); } getsockoptTimeval(FileDescriptor fd, int level, int option)235 /** @hide */ public static StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptTimeval(fd, level, option); } getsockoptUcred(FileDescriptor fd, int level, int option)236 /** @hide */ public static StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptUcred(fd, level, option); } 237 238 /** 239 * See <a href="http://man7.org/linux/man-pages/man2/gettid.2.html">gettid(2)</a>. 240 */ gettid()241 public static int gettid() { return Libcore.os.gettid(); } 242 243 /** 244 * See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html">getuid(2)</a>. 245 */ getuid()246 public static int getuid() { return Libcore.os.getuid(); } 247 248 /** 249 * See <a href="http://man7.org/linux/man-pages/man2/getxattr.2.html">getxattr(2)</a> 250 */ getxattr(String path, String name)251 public static byte[] getxattr(String path, String name) throws ErrnoException { return Libcore.os.getxattr(path, name); } 252 253 /** 254 * See <a href="http://man7.org/linux/man-pages/man3/if_indextoname.3.html">if_indextoname(3)</a>. 255 */ if_indextoname(int index)256 public static String if_indextoname(int index) { return Libcore.os.if_indextoname(index); } 257 258 /** 259 * See <a href="http://man7.org/linux/man-pages/man3/if_nametoindex.3.html">if_nametoindex(3)</a>. 260 */ if_nametoindex(String name)261 public static int if_nametoindex(String name) { return Libcore.os.if_nametoindex(name); } 262 263 /** 264 * See <a href="http://man7.org/linux/man-pages/man3/inet_pton.3.html">inet_pton(3)</a>. 265 */ inet_pton(int family, String address)266 public static InetAddress inet_pton(int family, String address) { return Libcore.os.inet_pton(family, address); } 267 ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName)268 /** @hide */ public static InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return Libcore.os.ioctlInetAddress(fd, cmd, interfaceName); } 269 270 ioctlInt(FileDescriptor fd, int cmd, Int32Ref arg)271 /** @hide */ public static int ioctlInt(FileDescriptor fd, int cmd, Int32Ref arg) throws ErrnoException { 272 return Libcore.os.ioctlInt(fd, cmd, arg); 273 } 274 275 /** 276 * See <a href="http://man7.org/linux/man-pages/man3/isatty.3.html">isatty(3)</a>. 277 */ isatty(FileDescriptor fd)278 public static boolean isatty(FileDescriptor fd) { return Libcore.os.isatty(fd); } 279 280 /** 281 * See <a href="http://man7.org/linux/man-pages/man2/kill.2.html">kill(2)</a>. 282 */ kill(int pid, int signal)283 public static void kill(int pid, int signal) throws ErrnoException { Libcore.os.kill(pid, signal); } 284 285 /** 286 * See <a href="http://man7.org/linux/man-pages/man2/lchown.2.html">lchown(2)</a>. 287 */ lchown(String path, int uid, int gid)288 public static void lchown(String path, int uid, int gid) throws ErrnoException { Libcore.os.lchown(path, uid, gid); } 289 290 /** 291 * See <a href="http://man7.org/linux/man-pages/man2/link.2.html">link(2)</a>. 292 */ link(String oldPath, String newPath)293 public static void link(String oldPath, String newPath) throws ErrnoException { Libcore.os.link(oldPath, newPath); } 294 295 /** 296 * See <a href="http://man7.org/linux/man-pages/man2/listen.2.html">listen(2)</a>. 297 */ listen(FileDescriptor fd, int backlog)298 public static void listen(FileDescriptor fd, int backlog) throws ErrnoException { Libcore.os.listen(fd, backlog); } 299 300 /** 301 * See <a href="http://man7.org/linux/man-pages/man2/listxattr.2.html">listxattr(2)</a> 302 */ listxattr(String path)303 public static String[] listxattr(String path) throws ErrnoException { return Libcore.os.listxattr(path); } 304 305 /** 306 * See <a href="http://man7.org/linux/man-pages/man2/lseek.2.html">lseek(2)</a>. 307 */ lseek(FileDescriptor fd, long offset, int whence)308 public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return Libcore.os.lseek(fd, offset, whence); } 309 310 /** 311 * See <a href="http://man7.org/linux/man-pages/man2/lstat.2.html">lstat(2)</a>. 312 */ lstat(String path)313 public static StructStat lstat(String path) throws ErrnoException { return Libcore.os.lstat(path); } 314 315 /** 316 * See <a href="http://man7.org/linux/man-pages/man2/mincore.2.html">mincore(2)</a>. 317 */ mincore(long address, long byteCount, byte[] vector)318 public static void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { Libcore.os.mincore(address, byteCount, vector); } 319 320 /** 321 * See <a href="http://man7.org/linux/man-pages/man2/mkdir.2.html">mkdir(2)</a>. 322 */ mkdir(String path, int mode)323 public static void mkdir(String path, int mode) throws ErrnoException { Libcore.os.mkdir(path, mode); } 324 325 /** 326 * See <a href="http://man7.org/linux/man-pages/man3/mkfifo.3.html">mkfifo(3)</a>. 327 */ mkfifo(String path, int mode)328 public static void mkfifo(String path, int mode) throws ErrnoException { Libcore.os.mkfifo(path, mode); } 329 330 /** 331 * See <a href="http://man7.org/linux/man-pages/man2/mlock.2.html">mlock(2)</a>. 332 */ mlock(long address, long byteCount)333 public static void mlock(long address, long byteCount) throws ErrnoException { Libcore.os.mlock(address, byteCount); } 334 335 /** 336 * See <a href="http://man7.org/linux/man-pages/man2/mmap.2.html">mmap(2)</a>. 337 */ mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset)338 public static long mmap(long address, long byteCount, int prot, int flags, FileDescriptor fd, long offset) throws ErrnoException { return Libcore.os.mmap(address, byteCount, prot, flags, fd, offset); } 339 340 /** 341 * See <a href="http://man7.org/linux/man-pages/man2/msync.2.html">msync(2)</a>. 342 */ msync(long address, long byteCount, int flags)343 public static void msync(long address, long byteCount, int flags) throws ErrnoException { Libcore.os.msync(address, byteCount, flags); } 344 345 /** 346 * See <a href="http://man7.org/linux/man-pages/man2/munlock.2.html">munlock(2)</a>. 347 */ munlock(long address, long byteCount)348 public static void munlock(long address, long byteCount) throws ErrnoException { Libcore.os.munlock(address, byteCount); } 349 350 /** 351 * See <a href="http://man7.org/linux/man-pages/man2/munmap.2.html">munmap(2)</a>. 352 */ munmap(long address, long byteCount)353 public static void munmap(long address, long byteCount) throws ErrnoException { Libcore.os.munmap(address, byteCount); } 354 355 /** 356 * See <a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>. 357 */ open(String path, int flags, int mode)358 public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return Libcore.os.open(path, flags, mode); } 359 360 /** 361 * See <a href="http://man7.org/linux/man-pages/man2/pipe.2.html">pipe(2)</a>. 362 */ pipe()363 public static FileDescriptor[] pipe() throws ErrnoException { return Libcore.os.pipe2(0); } 364 pipe2(int flags)365 /** @hide */ public static FileDescriptor[] pipe2(int flags) throws ErrnoException { return Libcore.os.pipe2(flags); } 366 367 /** 368 * See <a href="http://man7.org/linux/man-pages/man2/poll.2.html">poll(2)</a>. 369 * 370 * <p>Note that in Lollipop this could throw an {@code ErrnoException} with {@code EINTR}. 371 * In later releases, the implementation will automatically just restart the system call with 372 * an appropriately reduced timeout. 373 */ poll(StructPollfd[] fds, int timeoutMs)374 public static int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return Libcore.os.poll(fds, timeoutMs); } 375 376 /** 377 * See <a href="http://man7.org/linux/man-pages/man3/posix_fallocate.3.html">posix_fallocate(3)</a>. 378 */ posix_fallocate(FileDescriptor fd, long offset, long length)379 public static void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { Libcore.os.posix_fallocate(fd, offset, length); } 380 381 /** 382 * See <a href="http://man7.org/linux/man-pages/man2/prctl.2.html">prctl(2)</a>. 383 */ prctl(int option, long arg2, long arg3, long arg4, long arg5)384 public static int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return Libcore.os.prctl(option, arg2, arg3, arg4, arg5); }; 385 386 /** 387 * See <a href="http://man7.org/linux/man-pages/man2/pread.2.html">pread(2)</a>. 388 */ pread(FileDescriptor fd, ByteBuffer buffer, long offset)389 public static int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, buffer, offset); } 390 391 /** 392 * See <a href="http://man7.org/linux/man-pages/man2/pread.2.html">pread(2)</a>. 393 */ pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)394 public static int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, bytes, byteOffset, byteCount, offset); } 395 396 /** 397 * See <a href="http://man7.org/linux/man-pages/man2/pwrite.2.html">pwrite(2)</a>. 398 */ pwrite(FileDescriptor fd, ByteBuffer buffer, long offset)399 public static int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, buffer, offset); } 400 401 /** 402 * See <a href="http://man7.org/linux/man-pages/man2/pwrite.2.html">pwrite(2)</a>. 403 */ pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset)404 public static int pwrite(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, bytes, byteOffset, byteCount, offset); } 405 406 /** 407 * See <a href="http://man7.org/linux/man-pages/man2/read.2.html">read(2)</a>. 408 */ read(FileDescriptor fd, ByteBuffer buffer)409 public static int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, buffer); } 410 411 /** 412 * See <a href="http://man7.org/linux/man-pages/man2/read.2.html">read(2)</a>. 413 */ read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)414 public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, bytes, byteOffset, byteCount); } 415 416 /** 417 * See <a href="http://man7.org/linux/man-pages/man2/readlink.2.html">readlink(2)</a>. 418 */ readlink(String path)419 public static String readlink(String path) throws ErrnoException { return Libcore.os.readlink(path); } 420 421 /** 422 * See <a href="http://man7.org/linux/man-pages/man3/realpath.3.html">realpath(3)</a>. 423 */ realpath(String path)424 /** @hide */ public static String realpath(String path) throws ErrnoException { return Libcore.os.realpath(path); } 425 426 /** 427 * See <a href="http://man7.org/linux/man-pages/man2/readv.2.html">readv(2)</a>. 428 */ readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)429 public static int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.readv(fd, buffers, offsets, byteCounts); } 430 431 /** 432 * See <a href="http://man7.org/linux/man-pages/man2/recvfrom.2.html">recvfrom(2)</a>. 433 */ recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress)434 public static int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, buffer, flags, srcAddress); } 435 436 /** 437 * See <a href="http://man7.org/linux/man-pages/man2/recvfrom.2.html">recvfrom(2)</a>. 438 */ recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress)439 public static int recvfrom(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress); } 440 441 /** 442 * See <a href="http://man7.org/linux/man-pages/man3/remove.3.html">remove(3)</a>. 443 */ remove(String path)444 public static void remove(String path) throws ErrnoException { Libcore.os.remove(path); } 445 446 /** 447 * See <a href="http://man7.org/linux/man-pages/man2/removexattr.2.html">removexattr(2)</a>. 448 */ removexattr(String path, String name)449 public static void removexattr(String path, String name) throws ErrnoException { Libcore.os.removexattr(path, name); } 450 451 /** 452 * See <a href="http://man7.org/linux/man-pages/man2/rename.2.html">rename(2)</a>. 453 */ rename(String oldPath, String newPath)454 public static void rename(String oldPath, String newPath) throws ErrnoException { Libcore.os.rename(oldPath, newPath); } 455 456 /** 457 * See <a href="http://man7.org/linux/man-pages/man2/sendfile.2.html">sendfile(2)</a>. 458 */ sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount)459 public static long sendfile(FileDescriptor outFd, FileDescriptor inFd, Int64Ref offset, long byteCount) throws ErrnoException { 460 return Libcore.os.sendfile(outFd, inFd, offset, byteCount); 461 } 462 463 /** 464 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>. 465 */ sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port)466 public static int sendto(FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, buffer, flags, inetAddress, port); } 467 468 /** 469 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>. 470 */ sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port)471 public static int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, InetAddress inetAddress, int port) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port); } 472 473 /** 474 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>. 475 */ sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, SocketAddress address)476 /** @hide */ public static int sendto(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, int flags, SocketAddress address) throws ErrnoException, SocketException { return Libcore.os.sendto(fd, bytes, byteOffset, byteCount, flags, address); } 477 478 /** 479 * See <a href="http://man7.org/linux/man-pages/man2/setegid.2.html">setegid(2)</a>. 480 */ setegid(int egid)481 public static void setegid(int egid) throws ErrnoException { Libcore.os.setegid(egid); } 482 483 /** 484 * See <a href="http://man7.org/linux/man-pages/man3/setenv.3.html">setenv(3)</a>. 485 */ setenv(String name, String value, boolean overwrite)486 public static void setenv(String name, String value, boolean overwrite) throws ErrnoException { Libcore.os.setenv(name, value, overwrite); } 487 488 /** 489 * See <a href="http://man7.org/linux/man-pages/man2/seteuid.2.html">seteuid(2)</a>. 490 */ seteuid(int euid)491 public static void seteuid(int euid) throws ErrnoException { Libcore.os.seteuid(euid); } 492 493 /** 494 * See <a href="http://man7.org/linux/man-pages/man2/setgid.2.html">setgid(2)</a>. 495 */ setgid(int gid)496 public static void setgid(int gid) throws ErrnoException { Libcore.os.setgid(gid); } 497 498 /** 499 * See <a href="http://man7.org/linux/man-pages/man2/setpgid.2.html">setpgid(2)</a>. 500 */ setpgid(int pid, int pgid)501 /** @hide */ public static void setpgid(int pid, int pgid) throws ErrnoException { Libcore.os.setpgid(pid, pgid); } 502 503 /** 504 * See <a href="http://man7.org/linux/man-pages/man2/setregid.2.html">setregid(2)</a>. 505 */ setregid(int rgid, int egid)506 /** @hide */ public static void setregid(int rgid, int egid) throws ErrnoException { Libcore.os.setregid(rgid, egid); } 507 508 /** 509 * See <a href="http://man7.org/linux/man-pages/man2/setreuid.2.html">setreuid(2)</a>. 510 */ setreuid(int ruid, int euid)511 /** @hide */ public static void setreuid(int ruid, int euid) throws ErrnoException { Libcore.os.setreuid(ruid, euid); } 512 513 /** 514 * See <a href="http://man7.org/linux/man-pages/man2/setsid.2.html">setsid(2)</a>. 515 */ setsid()516 public static int setsid() throws ErrnoException { return Libcore.os.setsid(); } 517 setsockoptByte(FileDescriptor fd, int level, int option, int value)518 /** @hide */ public static void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptByte(fd, level, option, value); } setsockoptIfreq(FileDescriptor fd, int level, int option, String value)519 /** @hide */ public static void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { Libcore.os.setsockoptIfreq(fd, level, option, value); } 520 521 /** 522 * See <a href="http://man7.org/linux/man-pages/man2/setsockopt.2.html">setsockopt(2)</a>. 523 */ setsockoptInt(FileDescriptor fd, int level, int option, int value)524 public static void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptInt(fd, level, option, value); } 525 setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value)526 /** @hide */ public static void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptIpMreqn(fd, level, option, value); } setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value)527 /** @hide */ public static void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { Libcore.os.setsockoptGroupReq(fd, level, option, value); } setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value)528 /** @hide */ public static void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException { Libcore.os.setsockoptLinger(fd, level, option, value); } setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value)529 /** @hide */ public static void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException { Libcore.os.setsockoptTimeval(fd, level, option, value); } 530 531 /** 532 * See <a href="http://man7.org/linux/man-pages/man2/setuid.2.html">setuid(2)</a>. 533 */ setuid(int uid)534 public static void setuid(int uid) throws ErrnoException { Libcore.os.setuid(uid); } 535 536 /** 537 * See <a href="http://man7.org/linux/man-pages/man2/setxattr.2.html">setxattr(2)</a> 538 */ setxattr(String path, String name, byte[] value, int flags)539 public static void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException { Libcore.os.setxattr(path, name, value, flags); }; 540 541 /** 542 * See <a href="http://man7.org/linux/man-pages/man2/shutdown.2.html">shutdown(2)</a>. 543 */ shutdown(FileDescriptor fd, int how)544 public static void shutdown(FileDescriptor fd, int how) throws ErrnoException { Libcore.os.shutdown(fd, how); } 545 546 /** 547 * See <a href="http://man7.org/linux/man-pages/man2/socket.2.html">socket(2)</a>. 548 */ socket(int domain, int type, int protocol)549 public static FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return Libcore.os.socket(domain, type, protocol); } 550 551 /** 552 * See <a href="http://man7.org/linux/man-pages/man2/socketpair.2.html">socketpair(2)</a>. 553 */ socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2)554 public static void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { Libcore.os.socketpair(domain, type, protocol, fd1, fd2); } 555 556 /** 557 * See <a href="http://man7.org/linux/man-pages/man2/splice.2.html">splice(2)</a>. 558 * @hide 559 */ splice(FileDescriptor fdIn, Int64Ref offIn, FileDescriptor fdOut, Int64Ref offOut, long len, int flags)560 public static long splice(FileDescriptor fdIn, Int64Ref offIn, FileDescriptor fdOut, Int64Ref offOut, long len, int flags) throws ErrnoException { return Libcore.os.splice(fdIn, offIn, fdOut, offOut, len, flags); } 561 562 /** 563 * See <a href="http://man7.org/linux/man-pages/man2/stat.2.html">stat(2)</a>. 564 */ stat(String path)565 public static StructStat stat(String path) throws ErrnoException { return Libcore.os.stat(path); } 566 567 /** 568 * See <a href="http://man7.org/linux/man-pages/man2/statvfs.2.html">statvfs(2)</a>. 569 */ statvfs(String path)570 public static StructStatVfs statvfs(String path) throws ErrnoException { return Libcore.os.statvfs(path); } 571 572 /** 573 * See <a href="http://man7.org/linux/man-pages/man3/strerror.3.html">strerror(2)</a>. 574 */ strerror(int errno)575 public static String strerror(int errno) { return Libcore.os.strerror(errno); } 576 577 /** 578 * See <a href="http://man7.org/linux/man-pages/man3/strsignal.3.html">strsignal(3)</a>. 579 */ strsignal(int signal)580 public static String strsignal(int signal) { return Libcore.os.strsignal(signal); } 581 582 /** 583 * See <a href="http://man7.org/linux/man-pages/man2/symlink.2.html">symlink(2)</a>. 584 */ symlink(String oldPath, String newPath)585 public static void symlink(String oldPath, String newPath) throws ErrnoException { Libcore.os.symlink(oldPath, newPath); } 586 587 /** 588 * See <a href="http://man7.org/linux/man-pages/man3/sysconf.3.html">sysconf(3)</a>. 589 */ sysconf(int name)590 public static long sysconf(int name) { return Libcore.os.sysconf(name); } 591 592 /** 593 * See <a href="http://man7.org/linux/man-pages/man3/tcdrain.3.html">tcdrain(3)</a>. 594 */ tcdrain(FileDescriptor fd)595 public static void tcdrain(FileDescriptor fd) throws ErrnoException { Libcore.os.tcdrain(fd); } 596 597 /** 598 * See <a href="http://man7.org/linux/man-pages/man3/tcsendbreak.3.html">tcsendbreak(3)</a>. 599 */ tcsendbreak(FileDescriptor fd, int duration)600 public static void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException { Libcore.os.tcsendbreak(fd, duration); } 601 602 /** 603 * See <a href="http://man7.org/linux/man-pages/man2/umask.2.html">umask(2)</a>. 604 */ umask(int mask)605 public static int umask(int mask) { return Libcore.os.umask(mask); } 606 607 /** 608 * See <a href="http://man7.org/linux/man-pages/man2/uname.2.html">uname(2)</a>. 609 */ uname()610 public static StructUtsname uname() { return Libcore.os.uname(); } 611 612 /** 613 * @hide See <a href="http://man7.org/linux/man-pages/man2/unlink.2.html">unlink(2)</a>. 614 */ unlink(String pathname)615 public static void unlink(String pathname) throws ErrnoException { Libcore.os.unlink(pathname); } 616 617 /** 618 * See <a href="http://man7.org/linux/man-pages/man3/unsetenv.3.html">unsetenv(3)</a>. 619 */ unsetenv(String name)620 public static void unsetenv(String name) throws ErrnoException { Libcore.os.unsetenv(name); } 621 622 /** 623 * @hide See <a href="http://man7.org/linux/man-pages/man2/waitpid.2.html">waitpid(2)</a>. 624 * 625 * @throws IllegalArgumentException if {@code status != null && status.length != 1} 626 */ waitpid(int pid, Int32Ref status, int options)627 public static int waitpid(int pid, Int32Ref status, int options) throws ErrnoException { 628 return Libcore.os.waitpid(pid, status, options); 629 } 630 631 /** 632 * See <a href="http://man7.org/linux/man-pages/man2/write.2.html">write(2)</a>. 633 */ write(FileDescriptor fd, ByteBuffer buffer)634 public static int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, buffer); } 635 636 /** 637 * See <a href="http://man7.org/linux/man-pages/man2/write.2.html">write(2)</a>. 638 */ write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)639 public static int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, bytes, byteOffset, byteCount); } 640 641 /** 642 * See <a href="http://man7.org/linux/man-pages/man2/writev.2.html">writev(2)</a>. 643 */ writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)644 public static int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.writev(fd, buffers, offsets, byteCounts); } 645 } 646