blob: d90e73717ac2daec539b0b757cdd4a1c4f034f19 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#ifndef _UNISTD_H_
29#define _UNISTD_H_
30
31#include <stddef.h>
32#include <sys/cdefs.h>
33#include <sys/types.h>
34#include <sys/select.h>
35#include <sys/sysconf.h>
36#include <linux/capability.h>
37#include <pathconf.h>
38
39__BEGIN_DECLS
40
41/* Standard file descriptor numbers. */
42#define STDIN_FILENO 0
43#define STDOUT_FILENO 1
44#define STDERR_FILENO 2
45
46/* Values for whence in fseek and lseek */
47#define SEEK_SET 0
48#define SEEK_CUR 1
49#define SEEK_END 2
50
51extern char **environ;
52extern __noreturn void _exit(int);
53
54extern pid_t fork(void);
55extern pid_t vfork(void);
56extern pid_t getpid(void);
57extern pid_t gettid(void);
58extern pid_t getpgid(pid_t);
59extern int setpgid(pid_t, pid_t);
60extern pid_t getppid(void);
61extern pid_t getpgrp(void);
62extern int setpgrp(void);
63extern pid_t setsid(void);
64extern pid_t getsid(pid_t);
65
66extern int execv(const char *, char * const *);
67extern int execvp(const char *, char * const *);
68extern int execve(const char *, char * const *, char * const *);
69extern int execvpe(const char *, char * const *, char * const *);
70extern int execl(const char *, const char *, ...);
71extern int execlp(const char *, const char *, ...);
72extern int execle(const char *, const char *, ...);
73extern int execlpe(const char *, const char *, ...);
74extern int capget(cap_user_header_t hdrp, cap_user_data_t datap);
75extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
76extern int prctl(int option, unsigned long arg2, unsigned long arg3,
77 unsigned long arg4, unsigned long arg5);
78
79extern int nice(int);
80
81extern int setuid(uid_t);
82extern uid_t getuid(void);
83extern int seteuid(uid_t);
84extern uid_t geteuid(void);
85extern int setgid(gid_t);
86extern gid_t getgid(void);
87extern int setegid(gid_t);
88extern gid_t getegid(void);
89extern int getgroups(int, gid_t *);
90extern int setgroups(size_t, const gid_t *);
91extern int setreuid(uid_t, uid_t);
92extern int setregid(gid_t, gid_t);
93extern int setresuid(uid_t, uid_t, uid_t);
94extern int setresgid(gid_t, gid_t, gid_t);
95extern int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
96extern int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);
97extern int getfsuid(uid_t);
98extern int setfsuid(uid_t);
99extern int issetugid(void);
100extern char* getlogin(void);
101extern int getlogin_r(char* name, size_t namesize);
Colin Crossfc10b242010-01-13 17:48:34 -0800102extern char* getusershell(void);
103extern void setusershell(void);
104extern void endusershell(void);
105
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800106
107
108/* Macros for access() */
109#define R_OK 4 /* Read */
110#define W_OK 2 /* Write */
111#define X_OK 1 /* Execute */
112#define F_OK 0 /* Existence */
113
114extern int access(const char *, int);
115extern int link(const char *, const char *);
116extern int unlink(const char *);
117extern int chdir(const char *);
118extern int fchdir(int);
119extern int rmdir(const char *);
120extern int pipe(int *);
121extern int chroot(const char *);
122extern int symlink(const char *, const char *);
123extern int readlink(const char *, char *, size_t);
124extern int chown(const char *, uid_t, gid_t);
125extern int fchown(int, uid_t, gid_t);
126extern int lchown(const char *, uid_t, gid_t);
David 'Digit' Turnerda3019b2010-06-11 14:37:34 -0700127extern int truncate(const char *, off_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800128extern char *getcwd(char *, size_t);
129
130extern int sync(void);
131
132extern int close(int);
133extern off_t lseek(int, off_t, int);
Dima Zavin63673642010-08-06 11:45:43 -0700134extern off64_t lseek64(int, off64_t, int);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800135
136extern ssize_t read(int, void *, size_t);
137extern ssize_t write(int, const void *, size_t);
138extern ssize_t pread(int, void *, size_t, off_t);
139extern ssize_t pwrite(int, void *, size_t, off_t);
140
141extern int dup(int);
142extern int dup2(int, int);
143extern int fcntl(int, int, ...);
144extern int ioctl(int, int, ...);
145extern int flock(int, int);
146extern int fsync(int);
147extern int fdatasync(int);
148extern int ftruncate(int, off_t);
149
150extern int pause(void);
151extern unsigned int alarm(unsigned int);
152extern unsigned int sleep(unsigned int);
Elliott Hughes99d79072009-12-14 17:07:19 -0800153extern int usleep(unsigned long);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800154
155extern int gethostname(char *, size_t);
156extern int sethostname(const char *, size_t);
157extern int getdomainname(char *, size_t);
158extern int setdomainname(const char *, size_t);
159
160extern int getdtablesize(void);
161
162extern void *__brk(void *);
163extern int brk(void *);
164extern void *sbrk(ptrdiff_t);
165
166extern int getopt(int, char * const *, const char *);
167extern char *optarg;
168extern int optind, opterr, optopt;
169
170extern int isatty(int);
Colin Crossfc10b242010-01-13 17:48:34 -0800171extern char* ttyname(int);
172extern int ttyname_r(int, char*, size_t);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800173
174extern int acct(const char* filepath);
175
176static __inline__ int getpagesize(void) {
177 extern unsigned int __page_size;
178 return __page_size;
179}
180static __inline__ int __getpageshift(void) {
181 extern unsigned int __page_shift;
182 return __page_shift;
183}
184
185extern int sysconf(int name);
186
187extern int daemon(int, int);
188
189/* A special syscall that is only available on the ARM, not x86 function. */
190extern int cacheflush(long start, long end, long flags);
191
192extern pid_t tcgetpgrp(int fd);
193extern int tcsetpgrp(int fd, pid_t _pid);
194
Elliott Hughescf399f72009-10-05 13:19:05 -0700195/* Used to retry syscalls that can return EINTR. */
196#define TEMP_FAILURE_RETRY(exp) ({ \
197 typeof (exp) _rc; \
198 do { \
199 _rc = (exp); \
200 } while (_rc == -1 && errno == EINTR); \
201 _rc; })
202
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800203__END_DECLS
204
205#endif /* _UNISTD_H_ */