blob: 2e8d37faea7bacafd99e08b67c3125033eade2a6 [file] [log] [blame]
Elliott Hughes5d930ca2014-04-23 17:53:37 -07001/*
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
17package android.system;
18
Elliott Hughes5d930ca2014-04-23 17:53:37 -070019import android.util.MutableInt;
20import android.util.MutableLong;
21import java.io.FileDescriptor;
22import java.io.InterruptedIOException;
23import java.net.InetAddress;
24import java.net.InetSocketAddress;
25import java.net.SocketAddress;
26import java.net.SocketException;
27import java.nio.ByteBuffer;
28import libcore.io.Libcore;
29
30/**
Elliott Hughes34721e82014-05-06 16:45:47 -070031 * Access to low-level system functionality. Most of these are system calls. Most users will want
32 * to use higher-level APIs where available, but this class provides access to the underlying
33 * primitives used to implement the higher-level APIs.
34 *
35 * <p>The corresponding constants can be found in {@link OsConstants}.
Elliott Hughes5d930ca2014-04-23 17:53:37 -070036 */
37public final class Os {
38 private Os() {}
39
Elliott Hughes34721e82014-05-06 16:45:47 -070040 /**
41 * See <a href="http://man7.org/linux/man-pages/man2/accept.2.html">accept(2)</a>.
42 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070043 public static FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress) throws ErrnoException, SocketException { return Libcore.os.accept(fd, peerAddress); }
Elliott Hughes34721e82014-05-06 16:45:47 -070044
45 /**
Neil Fuller0ab1a262015-07-07 17:03:25 +010046 * TODO Change the public API by removing the overload above and unhiding this version.
47 * @hide
48 */
49 public static FileDescriptor accept(FileDescriptor fd, SocketAddress peerAddress) throws ErrnoException, SocketException { return Libcore.os.accept(fd, peerAddress); }
50
51 /**
Elliott Hughes34721e82014-05-06 16:45:47 -070052 * See <a href="http://man7.org/linux/man-pages/man2/access.2.html">access(2)</a>.
53 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070054 public static boolean access(String path, int mode) throws ErrnoException { return Libcore.os.access(path, mode); }
Elliott Hughes34721e82014-05-06 16:45:47 -070055
Paul Jensen3e587342014-05-12 23:40:42 -040056 /** @hide */ public static InetAddress[] android_getaddrinfo(String node, StructAddrinfo hints, int netId) throws GaiException { return Libcore.os.android_getaddrinfo(node, hints, netId); }
57
Elliott Hughes34721e82014-05-06 16:45:47 -070058 /**
59 * See <a href="http://man7.org/linux/man-pages/man2/bind.2.html">bind(2)</a>.
60 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070061 public static void bind(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.bind(fd, address, port); }
Elliott Hughes34721e82014-05-06 16:45:47 -070062
Erik Kline8f5b46d2015-01-26 21:37:16 +090063 /** @hide */ public static void bind(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { Libcore.os.bind(fd, address); }
64
Elliott Hughes34721e82014-05-06 16:45:47 -070065 /**
66 * See <a href="http://man7.org/linux/man-pages/man2/chmod.2.html">chmod(2)</a>.
67 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070068 public static void chmod(String path, int mode) throws ErrnoException { Libcore.os.chmod(path, mode); }
Elliott Hughes34721e82014-05-06 16:45:47 -070069
70 /**
71 * See <a href="http://man7.org/linux/man-pages/man2/chown.2.html">chown(2)</a>.
72 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070073 public static void chown(String path, int uid, int gid) throws ErrnoException { Libcore.os.chown(path, uid, gid); }
Elliott Hughes34721e82014-05-06 16:45:47 -070074
75 /**
76 * See <a href="http://man7.org/linux/man-pages/man2/close.2.html">close(2)</a>.
77 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070078 public static void close(FileDescriptor fd) throws ErrnoException { Libcore.os.close(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -070079
80 /**
81 * See <a href="http://man7.org/linux/man-pages/man2/connect.2.html">connect(2)</a>.
82 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070083 public static void connect(FileDescriptor fd, InetAddress address, int port) throws ErrnoException, SocketException { Libcore.os.connect(fd, address, port); }
Elliott Hughes34721e82014-05-06 16:45:47 -070084
Erik Kline8f5b46d2015-01-26 21:37:16 +090085 /** @hide */ public static void connect(FileDescriptor fd, SocketAddress address) throws ErrnoException, SocketException { Libcore.os.connect(fd, address); }
86
Elliott Hughes34721e82014-05-06 16:45:47 -070087 /**
88 * See <a href="http://man7.org/linux/man-pages/man2/dup.2.html">dup(2)</a>.
89 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070090 public static FileDescriptor dup(FileDescriptor oldFd) throws ErrnoException { return Libcore.os.dup(oldFd); }
Elliott Hughes34721e82014-05-06 16:45:47 -070091
92 /**
93 * See <a href="http://man7.org/linux/man-pages/man2/dup2.2.html">dup2(2)</a>.
94 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -070095 public static FileDescriptor dup2(FileDescriptor oldFd, int newFd) throws ErrnoException { return Libcore.os.dup2(oldFd, newFd); }
Elliott Hughes34721e82014-05-06 16:45:47 -070096
97 /**
98 * See <a href="http://man7.org/linux/man-pages/man3/environ.3.html">environ(3)</a>.
99 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700100 public static String[] environ() { return Libcore.os.environ(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700101
102 /**
103 * See <a href="http://man7.org/linux/man-pages/man2/execv.2.html">execv(2)</a>.
104 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700105 public static void execv(String filename, String[] argv) throws ErrnoException { Libcore.os.execv(filename, argv); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700106
107 /**
108 * See <a href="http://man7.org/linux/man-pages/man2/execve.2.html">execve(2)</a>.
109 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700110 public static void execve(String filename, String[] argv, String[] envp) throws ErrnoException { Libcore.os.execve(filename, argv, envp); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700111
112 /**
113 * See <a href="http://man7.org/linux/man-pages/man2/fchmod.2.html">fchmod(2)</a>.
114 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700115 public static void fchmod(FileDescriptor fd, int mode) throws ErrnoException { Libcore.os.fchmod(fd, mode); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700116
117 /**
118 * See <a href="http://man7.org/linux/man-pages/man2/fchown.2.html">fchown(2)</a>.
119 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700120 public static void fchown(FileDescriptor fd, int uid, int gid) throws ErrnoException { Libcore.os.fchown(fd, uid, gid); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700121
Neil Fuller99a0c822014-11-27 17:10:45 +0000122 /** @hide */ public static int fcntlFlock(FileDescriptor fd, int cmd, StructFlock arg) throws ErrnoException, InterruptedIOException { return Libcore.os.fcntlFlock(fd, cmd, arg); }
Narayan Kamathc8d9ea62015-01-16 17:51:59 +0000123 /** @hide */ public static int fcntlInt(FileDescriptor fd, int cmd, int arg) throws ErrnoException { return Libcore.os.fcntlInt(fd, cmd, arg); }
Narayan Kamathc8d9ea62015-01-16 17:51:59 +0000124 /** @hide */ public static int fcntlVoid(FileDescriptor fd, int cmd) throws ErrnoException { return Libcore.os.fcntlVoid(fd, cmd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700125
126 /**
127 * See <a href="http://man7.org/linux/man-pages/man2/fdatasync.2.html">fdatasync(2)</a>.
128 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700129 public static void fdatasync(FileDescriptor fd) throws ErrnoException { Libcore.os.fdatasync(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700130
131 /**
132 * See <a href="http://man7.org/linux/man-pages/man2/fstat.2.html">fstat(2)</a>.
133 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700134 public static StructStat fstat(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstat(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700135
136 /**
137 * See <a href="http://man7.org/linux/man-pages/man2/fstatvfs.2.html">fstatvfs(2)</a>.
138 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700139 public static StructStatVfs fstatvfs(FileDescriptor fd) throws ErrnoException { return Libcore.os.fstatvfs(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700140
141 /**
142 * See <a href="http://man7.org/linux/man-pages/man2/fsync.2.html">fsync(2)</a>.
143 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700144 public static void fsync(FileDescriptor fd) throws ErrnoException { Libcore.os.fsync(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700145
146 /**
147 * See <a href="http://man7.org/linux/man-pages/man2/ftruncate.2.html">ftruncate(2)</a>.
148 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700149 public static void ftruncate(FileDescriptor fd, long length) throws ErrnoException { Libcore.os.ftruncate(fd, length); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700150
151 /**
152 * See <a href="http://man7.org/linux/man-pages/man3/gai_strerror.3.html">gai_strerror(3)</a>.
153 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700154 public static String gai_strerror(int error) { return Libcore.os.gai_strerror(error); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700155
Elliott Hughes34721e82014-05-06 16:45:47 -0700156 /**
157 * See <a href="http://man7.org/linux/man-pages/man2/getegid.2.html">getegid(2)</a>.
158 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700159 public static int getegid() { return Libcore.os.getegid(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700160
161 /**
162 * See <a href="http://man7.org/linux/man-pages/man2/geteuid.2.html">geteuid(2)</a>.
163 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700164 public static int geteuid() { return Libcore.os.geteuid(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700165
166 /**
167 * See <a href="http://man7.org/linux/man-pages/man2/getgid.2.html">getgid(2)</a>.
168 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700169 public static int getgid() { return Libcore.os.getgid(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700170
171 /**
172 * See <a href="http://man7.org/linux/man-pages/man3/getenv.3.html">getenv(3)</a>.
173 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700174 public static String getenv(String name) { return Libcore.os.getenv(name); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700175
176 /** @hide */ public static String getnameinfo(InetAddress address, int flags) throws GaiException { return Libcore.os.getnameinfo(address, flags); }
177
178 /**
179 * See <a href="http://man7.org/linux/man-pages/man2/getpeername.2.html">getpeername(2)</a>.
180 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700181 public static SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return Libcore.os.getpeername(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700182
183 /**
Elliott Hughes8f0f2ac2014-12-17 11:59:00 -0800184 * See <a href="http://man7.org/linux/man-pages/man2/getpgid.2.html">getpgid(2)</a>.
185 */
186 /** @hide */ public static int getpgid(int pid) throws ErrnoException { return Libcore.os.getpgid(pid); }
187
188 /**
Elliott Hughes34721e82014-05-06 16:45:47 -0700189 * See <a href="http://man7.org/linux/man-pages/man2/getpid.2.html">getpid(2)</a>.
190 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700191 public static int getpid() { return Libcore.os.getpid(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700192
193 /**
194 * See <a href="http://man7.org/linux/man-pages/man2/getppid.2.html">getppid(2)</a>.
195 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700196 public static int getppid() { return Libcore.os.getppid(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700197
198 /** @hide */ public static StructPasswd getpwnam(String name) throws ErrnoException { return Libcore.os.getpwnam(name); }
199
200 /** @hide */ public static StructPasswd getpwuid(int uid) throws ErrnoException { return Libcore.os.getpwuid(uid); }
201
202 /**
203 * See <a href="http://man7.org/linux/man-pages/man2/getsockname.2.html">getsockname(2)</a>.
204 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700205 public static SocketAddress getsockname(FileDescriptor fd) throws ErrnoException { return Libcore.os.getsockname(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700206
207 /** @hide */ public static int getsockoptByte(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptByte(fd, level, option); }
208 /** @hide */ public static InetAddress getsockoptInAddr(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInAddr(fd, level, option); }
209 /** @hide */ public static int getsockoptInt(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptInt(fd, level, option); }
210 /** @hide */ public static StructLinger getsockoptLinger(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptLinger(fd, level, option); }
211 /** @hide */ public static StructTimeval getsockoptTimeval(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptTimeval(fd, level, option); }
212 /** @hide */ public static StructUcred getsockoptUcred(FileDescriptor fd, int level, int option) throws ErrnoException { return Libcore.os.getsockoptUcred(fd, level, option); }
213
214 /**
215 * See <a href="http://man7.org/linux/man-pages/man2/gettid.2.html">gettid(2)</a>.
216 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700217 public static int gettid() { return Libcore.os.gettid(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700218
219 /**
220 * See <a href="http://man7.org/linux/man-pages/man2/getuid.2.html">getuid(2)</a>.
221 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700222 public static int getuid() { return Libcore.os.getuid(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700223
Jeff Sharkey90246a02015-07-02 12:04:00 -0700224 /** @hide */ public static int getxattr(String path, String name, byte[] outValue) throws ErrnoException { return Libcore.os.getxattr(path, name, outValue); }
225
Elliott Hughes34721e82014-05-06 16:45:47 -0700226 /**
227 * See <a href="http://man7.org/linux/man-pages/man3/if_indextoname.3.html">if_indextoname(3)</a>.
228 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700229 public static String if_indextoname(int index) { return Libcore.os.if_indextoname(index); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700230
231 /**
232 * See <a href="http://man7.org/linux/man-pages/man3/inet_pton.3.html">inet_pton(3)</a>.
233 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700234 public static InetAddress inet_pton(int family, String address) { return Libcore.os.inet_pton(family, address); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700235
236 /** @hide */ public static InetAddress ioctlInetAddress(FileDescriptor fd, int cmd, String interfaceName) throws ErrnoException { return Libcore.os.ioctlInetAddress(fd, cmd, interfaceName); }
237 /** @hide */ public static int ioctlInt(FileDescriptor fd, int cmd, MutableInt arg) throws ErrnoException { return Libcore.os.ioctlInt(fd, cmd, arg); }
238
239 /**
240 * See <a href="http://man7.org/linux/man-pages/man3/isatty.3.html">isatty(3)</a>.
241 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700242 public static boolean isatty(FileDescriptor fd) { return Libcore.os.isatty(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700243
244 /**
245 * See <a href="http://man7.org/linux/man-pages/man2/kill.2.html">kill(2)</a>.
246 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700247 public static void kill(int pid, int signal) throws ErrnoException { Libcore.os.kill(pid, signal); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700248
249 /**
250 * See <a href="http://man7.org/linux/man-pages/man2/lchown.2.html">lchown(2)</a>.
251 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700252 public static void lchown(String path, int uid, int gid) throws ErrnoException { Libcore.os.lchown(path, uid, gid); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700253
254 /**
Elliott Hughes04428d62014-05-09 17:42:11 -0700255 * See <a href="http://man7.org/linux/man-pages/man2/link.2.html">link(2)</a>.
256 */
257 public static void link(String oldPath, String newPath) throws ErrnoException { Libcore.os.link(oldPath, newPath); }
258
259 /**
Elliott Hughes34721e82014-05-06 16:45:47 -0700260 * See <a href="http://man7.org/linux/man-pages/man2/listen.2.html">listen(2)</a>.
261 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700262 public static void listen(FileDescriptor fd, int backlog) throws ErrnoException { Libcore.os.listen(fd, backlog); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700263
264 /**
265 * See <a href="http://man7.org/linux/man-pages/man2/lseek.2.html">lseek(2)</a>.
266 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700267 public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { return Libcore.os.lseek(fd, offset, whence); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700268
269 /**
270 * See <a href="http://man7.org/linux/man-pages/man2/lstat.2.html">lstat(2)</a>.
271 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700272 public static StructStat lstat(String path) throws ErrnoException { return Libcore.os.lstat(path); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700273
274 /**
275 * See <a href="http://man7.org/linux/man-pages/man2/mincore.2.html">mincore(2)</a>.
276 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700277 public static void mincore(long address, long byteCount, byte[] vector) throws ErrnoException { Libcore.os.mincore(address, byteCount, vector); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700278
279 /**
280 * See <a href="http://man7.org/linux/man-pages/man2/mkdir.2.html">mkdir(2)</a>.
281 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700282 public static void mkdir(String path, int mode) throws ErrnoException { Libcore.os.mkdir(path, mode); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700283
284 /**
285 * See <a href="http://man7.org/linux/man-pages/man3/mkfifo.3.html">mkfifo(3)</a>.
286 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700287 public static void mkfifo(String path, int mode) throws ErrnoException { Libcore.os.mkfifo(path, mode); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700288
289 /**
290 * See <a href="http://man7.org/linux/man-pages/man2/mlock.2.html">mlock(2)</a>.
291 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700292 public static void mlock(long address, long byteCount) throws ErrnoException { Libcore.os.mlock(address, byteCount); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700293
294 /**
295 * See <a href="http://man7.org/linux/man-pages/man2/mmap.2.html">mmap(2)</a>.
296 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700297 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); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700298
299 /**
300 * See <a href="http://man7.org/linux/man-pages/man2/msync.2.html">msync(2)</a>.
301 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700302 public static void msync(long address, long byteCount, int flags) throws ErrnoException { Libcore.os.msync(address, byteCount, flags); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700303
304 /**
305 * See <a href="http://man7.org/linux/man-pages/man2/munlock.2.html">munlock(2)</a>.
306 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700307 public static void munlock(long address, long byteCount) throws ErrnoException { Libcore.os.munlock(address, byteCount); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700308
309 /**
310 * See <a href="http://man7.org/linux/man-pages/man2/munmap.2.html">munmap(2)</a>.
311 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700312 public static void munmap(long address, long byteCount) throws ErrnoException { Libcore.os.munmap(address, byteCount); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700313
314 /**
315 * See <a href="http://man7.org/linux/man-pages/man2/open.2.html">open(2)</a>.
316 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700317 public static FileDescriptor open(String path, int flags, int mode) throws ErrnoException { return Libcore.os.open(path, flags, mode); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700318
319 /**
320 * See <a href="http://man7.org/linux/man-pages/man2/pipe.2.html">pipe(2)</a>.
321 */
Elliott Hughes0d8b5c32014-12-12 12:46:38 -0800322 public static FileDescriptor[] pipe() throws ErrnoException { return Libcore.os.pipe2(0); }
323
324 /** @hide */ public static FileDescriptor[] pipe2(int flags) throws ErrnoException { return Libcore.os.pipe2(flags); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700325
326 /**
327 * See <a href="http://man7.org/linux/man-pages/man2/poll.2.html">poll(2)</a>.
Elliott Hughesfa542092014-12-15 16:14:56 -0800328 *
329 * <p>Note that in Lollipop this could throw an {@code ErrnoException} with {@code EINTR}.
330 * In later releases, the implementation will automatically just restart the system call with
331 * an appropriately reduced timeout.
Elliott Hughes34721e82014-05-06 16:45:47 -0700332 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700333 public static int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return Libcore.os.poll(fds, timeoutMs); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700334
335 /**
336 * See <a href="http://man7.org/linux/man-pages/man2/posix_fallocate.2.html">posix_fallocate(2)</a>.
337 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700338 public static void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { Libcore.os.posix_fallocate(fd, offset, length); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700339
340 /**
341 * See <a href="http://man7.org/linux/man-pages/man2/prctl.2.html">prctl(2)</a>.
342 */
Nick Kralevich5215e4c2014-04-25 14:59:37 -0700343 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); };
Elliott Hughes34721e82014-05-06 16:45:47 -0700344
345 /**
346 * See <a href="http://man7.org/linux/man-pages/man2/pread.2.html">pread(2)</a>.
347 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700348 public static int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, buffer, offset); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700349
350 /**
351 * See <a href="http://man7.org/linux/man-pages/man2/pread.2.html">pread(2)</a>.
352 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700353 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); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700354
355 /**
356 * See <a href="http://man7.org/linux/man-pages/man2/pwrite.2.html">pwrite(2)</a>.
357 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700358 public static int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, buffer, offset); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700359
360 /**
361 * See <a href="http://man7.org/linux/man-pages/man2/pwrite.2.html">pwrite(2)</a>.
362 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700363 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); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700364
365 /**
366 * See <a href="http://man7.org/linux/man-pages/man2/read.2.html">read(2)</a>.
367 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700368 public static int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, buffer); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700369
370 /**
371 * See <a href="http://man7.org/linux/man-pages/man2/read.2.html">read(2)</a>.
372 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700373 public static int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.read(fd, bytes, byteOffset, byteCount); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700374
375 /**
376 * See <a href="http://man7.org/linux/man-pages/man2/readlink.2.html">readlink(2)</a>.
377 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700378 public static String readlink(String path) throws ErrnoException { return Libcore.os.readlink(path); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700379
380 /**
381 * See <a href="http://man7.org/linux/man-pages/man2/readv.2.html">readv(2)</a>.
382 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700383 public static int readv(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.readv(fd, buffers, offsets, byteCounts); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700384
385 /**
386 * See <a href="http://man7.org/linux/man-pages/man2/recvfrom.2.html">recvfrom(2)</a>.
387 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700388 public static int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress) throws ErrnoException, SocketException { return Libcore.os.recvfrom(fd, buffer, flags, srcAddress); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700389
390 /**
391 * See <a href="http://man7.org/linux/man-pages/man2/recvfrom.2.html">recvfrom(2)</a>.
392 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700393 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); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700394
395 /**
396 * See <a href="http://man7.org/linux/man-pages/man3/remove.3.html">remove(3)</a>.
397 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700398 public static void remove(String path) throws ErrnoException { Libcore.os.remove(path); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700399
Jeff Sharkey90246a02015-07-02 12:04:00 -0700400 /** @hide */ public static void removexattr(String path, String name) throws ErrnoException { Libcore.os.removexattr(path, name); }
401
Elliott Hughes34721e82014-05-06 16:45:47 -0700402 /**
403 * See <a href="http://man7.org/linux/man-pages/man2/rename.2.html">rename(2)</a>.
404 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700405 public static void rename(String oldPath, String newPath) throws ErrnoException { Libcore.os.rename(oldPath, newPath); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700406
407 /**
408 * See <a href="http://man7.org/linux/man-pages/man2/sendfile.2.html">sendfile(2)</a>.
409 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700410 public static long sendfile(FileDescriptor outFd, FileDescriptor inFd, MutableLong inOffset, long byteCount) throws ErrnoException { return Libcore.os.sendfile(outFd, inFd, inOffset, byteCount); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700411
412 /**
413 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>.
414 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700415 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); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700416
417 /**
418 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>.
419 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700420 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); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700421
422 /**
Lorenzo Colitti36f73b32015-03-16 21:02:52 +0900423 * See <a href="http://man7.org/linux/man-pages/man2/sendto.2.html">sendto(2)</a>.
424 */
425 /** @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); }
426
427 /**
Elliott Hughes34721e82014-05-06 16:45:47 -0700428 * See <a href="http://man7.org/linux/man-pages/man2/setegid.2.html">setegid(2)</a>.
429 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700430 public static void setegid(int egid) throws ErrnoException { Libcore.os.setegid(egid); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700431
432 /**
433 * See <a href="http://man7.org/linux/man-pages/man3/setenv.3.html">setenv(3)</a>.
434 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700435 public static void setenv(String name, String value, boolean overwrite) throws ErrnoException { Libcore.os.setenv(name, value, overwrite); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700436
437 /**
438 * See <a href="http://man7.org/linux/man-pages/man2/seteuid.2.html">seteuid(2)</a>.
439 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700440 public static void seteuid(int euid) throws ErrnoException { Libcore.os.seteuid(euid); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700441
442 /**
443 * See <a href="http://man7.org/linux/man-pages/man2/setgid.2.html">setgid(2)</a>.
444 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700445 public static void setgid(int gid) throws ErrnoException { Libcore.os.setgid(gid); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700446
447 /**
Elliott Hughes8f0f2ac2014-12-17 11:59:00 -0800448 * See <a href="http://man7.org/linux/man-pages/man2/setpgid.2.html">setpgid(2)</a>.
449 */
450 /** @hide */ public static void setpgid(int pid, int pgid) throws ErrnoException { Libcore.os.setpgid(pid, pgid); }
451
452 /**
453 * See <a href="http://man7.org/linux/man-pages/man2/setregid.2.html">setregid(2)</a>.
454 */
455 /** @hide */ public static void setregid(int rgid, int egid) throws ErrnoException { Libcore.os.setregid(rgid, egid); }
456
457 /**
458 * See <a href="http://man7.org/linux/man-pages/man2/setreuid.2.html">setreuid(2)</a>.
459 */
460 /** @hide */ public static void setreuid(int ruid, int euid) throws ErrnoException { Libcore.os.setreuid(ruid, euid); }
461
462 /**
Elliott Hughes34721e82014-05-06 16:45:47 -0700463 * See <a href="http://man7.org/linux/man-pages/man2/setsid.2.html">setsid(2)</a>.
464 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700465 public static int setsid() throws ErrnoException { return Libcore.os.setsid(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700466
467 /** @hide */ public static void setsockoptByte(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptByte(fd, level, option, value); }
468 /** @hide */ public static void setsockoptIfreq(FileDescriptor fd, int level, int option, String value) throws ErrnoException { Libcore.os.setsockoptIfreq(fd, level, option, value); }
469 /** @hide */ public static void setsockoptInt(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptInt(fd, level, option, value); }
470 /** @hide */ public static void setsockoptIpMreqn(FileDescriptor fd, int level, int option, int value) throws ErrnoException { Libcore.os.setsockoptIpMreqn(fd, level, option, value); }
471 /** @hide */ public static void setsockoptGroupReq(FileDescriptor fd, int level, int option, StructGroupReq value) throws ErrnoException { Libcore.os.setsockoptGroupReq(fd, level, option, value); }
472 /** @hide */ public static void setsockoptGroupSourceReq(FileDescriptor fd, int level, int option, StructGroupSourceReq value) throws ErrnoException { Libcore.os.setsockoptGroupSourceReq(fd, level, option, value); }
473 /** @hide */ public static void setsockoptLinger(FileDescriptor fd, int level, int option, StructLinger value) throws ErrnoException { Libcore.os.setsockoptLinger(fd, level, option, value); }
474 /** @hide */ public static void setsockoptTimeval(FileDescriptor fd, int level, int option, StructTimeval value) throws ErrnoException { Libcore.os.setsockoptTimeval(fd, level, option, value); }
475
476 /**
477 * See <a href="http://man7.org/linux/man-pages/man2/setuid.2.html">setuid(2)</a>.
478 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700479 public static void setuid(int uid) throws ErrnoException { Libcore.os.setuid(uid); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700480
Jeff Sharkey90246a02015-07-02 12:04:00 -0700481 /** @hide */ public static void setxattr(String path, String name, byte[] value, int flags) throws ErrnoException { Libcore.os.setxattr(path, name, value, flags); };
482
Elliott Hughes34721e82014-05-06 16:45:47 -0700483 /**
484 * See <a href="http://man7.org/linux/man-pages/man2/shutdown.2.html">shutdown(2)</a>.
485 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700486 public static void shutdown(FileDescriptor fd, int how) throws ErrnoException { Libcore.os.shutdown(fd, how); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700487
488 /**
489 * See <a href="http://man7.org/linux/man-pages/man2/socket.2.html">socket(2)</a>.
490 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700491 public static FileDescriptor socket(int domain, int type, int protocol) throws ErrnoException { return Libcore.os.socket(domain, type, protocol); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700492
493 /**
494 * See <a href="http://man7.org/linux/man-pages/man2/socketpair.2.html">socketpair(2)</a>.
495 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700496 public static void socketpair(int domain, int type, int protocol, FileDescriptor fd1, FileDescriptor fd2) throws ErrnoException { Libcore.os.socketpair(domain, type, protocol, fd1, fd2); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700497
498 /**
499 * See <a href="http://man7.org/linux/man-pages/man2/stat.2.html">stat(2)</a>.
500 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700501 public static StructStat stat(String path) throws ErrnoException { return Libcore.os.stat(path); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700502
503 /**
504 * See <a href="http://man7.org/linux/man-pages/man2/statvfs.2.html">statvfs(2)</a>.
505 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700506 public static StructStatVfs statvfs(String path) throws ErrnoException { return Libcore.os.statvfs(path); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700507
508 /**
509 * See <a href="http://man7.org/linux/man-pages/man3/strerror.3.html">strerror(2)</a>.
510 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700511 public static String strerror(int errno) { return Libcore.os.strerror(errno); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700512
513 /**
514 * See <a href="http://man7.org/linux/man-pages/man3/strsignal.3.html">strsignal(3)</a>.
515 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700516 public static String strsignal(int signal) { return Libcore.os.strsignal(signal); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700517
518 /**
519 * See <a href="http://man7.org/linux/man-pages/man2/symlink.2.html">symlink(2)</a>.
520 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700521 public static void symlink(String oldPath, String newPath) throws ErrnoException { Libcore.os.symlink(oldPath, newPath); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700522
523 /**
524 * See <a href="http://man7.org/linux/man-pages/man3/sysconf.3.html">sysconf(3)</a>.
525 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700526 public static long sysconf(int name) { return Libcore.os.sysconf(name); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700527
528 /**
529 * See <a href="http://man7.org/linux/man-pages/man3/tcdrain.3.html">tcdrain(3)</a>.
530 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700531 public static void tcdrain(FileDescriptor fd) throws ErrnoException { Libcore.os.tcdrain(fd); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700532
533 /**
534 * See <a href="http://man7.org/linux/man-pages/man3/tcsendbreak.3.html">tcsendbreak(3)</a>.
535 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700536 public static void tcsendbreak(FileDescriptor fd, int duration) throws ErrnoException { Libcore.os.tcsendbreak(fd, duration); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700537
538 /**
539 * See <a href="http://man7.org/linux/man-pages/man2/umask.2.html">umask(2)</a>.
540 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700541 public static int umask(int mask) { return Libcore.os.umask(mask); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700542
543 /**
544 * See <a href="http://man7.org/linux/man-pages/man2/uname.2.html">uname(2)</a>.
545 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700546 public static StructUtsname uname() { return Libcore.os.uname(); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700547
548 /**
549 * See <a href="http://man7.org/linux/man-pages/man3/unsetenv.3.html">unsetenv(3)</a>.
550 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700551 public static void unsetenv(String name) throws ErrnoException { Libcore.os.unsetenv(name); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700552
553 /**
554 * See <a href="http://man7.org/linux/man-pages/man2/waitpid.2.html">waitpid(2)</a>.
555 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700556 public static int waitpid(int pid, MutableInt status, int options) throws ErrnoException { return Libcore.os.waitpid(pid, status, options); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700557
558 /**
559 * See <a href="http://man7.org/linux/man-pages/man2/write.2.html">write(2)</a>.
560 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700561 public static int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, buffer); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700562
563 /**
564 * See <a href="http://man7.org/linux/man-pages/man2/write.2.html">write(2)</a>.
565 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700566 public static int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws ErrnoException, InterruptedIOException { return Libcore.os.write(fd, bytes, byteOffset, byteCount); }
Elliott Hughes34721e82014-05-06 16:45:47 -0700567
568 /**
569 * See <a href="http://man7.org/linux/man-pages/man2/writev.2.html">writev(2)</a>.
570 */
Elliott Hughes5d930ca2014-04-23 17:53:37 -0700571 public static int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts) throws ErrnoException, InterruptedIOException { return Libcore.os.writev(fd, buffers, offsets, byteCounts); }
572}