xref: /haiku/headers/posix/unistd.h (revision 508f54795f39c3e7552d87c95aae9dd8ec6f505b)
1 /*
2  * Copyright 2004-2009, Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _UNISTD_H_
6 #define _UNISTD_H_
7 
8 
9 #include <null.h>
10 #include <sys/types.h>
11 
12 
13 /* access modes */
14 #define R_OK	4
15 #define W_OK	2
16 #define X_OK	1
17 #define F_OK	0
18 
19 /* standard file descriptors */
20 #define STDIN_FILENO	0
21 #define STDOUT_FILENO	1
22 #define STDERR_FILENO	2
23 
24 /* function arguments needed by lockf() */
25 #define F_ULOCK		0	/* unlock locked sections */
26 #define F_LOCK		1	/* lock a section for exclusive use */
27 #define F_TLOCK		2	/* test and lock a section for exclusive use */
28 #define F_TEST		3	/* test a section for locks by other processes */
29 
30 /* POSIX version support */
31 #define _POSIX_VERSION			(199009L)	/* TODO: Update! */
32 
33 #define _POSIX_CHOWN_RESTRICTED	1
34 #define _POSIX_JOB_CONTROL		1
35 #define _POSIX_NO_TRUNC			0
36 #define _POSIX_SAVED_IDS		1
37 #define _POSIX_VDISABLE			((unsigned char)-2)
38 	/* TODO: Check this! */
39 /* TODO: Update these to the current POSIX version! Ideally after actually
40 	supporting the features. */
41 #define _POSIX_SEMAPHORES					(200112L)
42 #define _POSIX_THREADS						(200112L)
43 #define _POSIX_MAPPED_FILES					(200809L)
44 #define _POSIX_THREAD_PROCESS_SHARED		(200809L)
45 #define _POSIX_THREAD_ATTR_STACKADDR		(-1)	/* currently unsupported */
46 #define _POSIX_THREAD_ATTR_STACKSIZE		(200809L)
47 #define _POSIX_THREAD_PRIORITY_SCHEDULING	(-1)	/* currently unsupported */
48 #define _POSIX_REALTIME_SIGNALS				(-1)	/* currently unsupported */
49 #define _POSIX_MEMORY_PROTECTION			(200809L)
50 #define _POSIX_SEM_VALUE_MAX				INT_MAX
51 
52 /* pathconf() constants */
53 /* BeOS supported values, do not touch */
54 #define _PC_CHOWN_RESTRICTED	1
55 #define _PC_MAX_CANON			2
56 #define _PC_MAX_INPUT			3
57 #define _PC_NAME_MAX			4
58 #define _PC_NO_TRUNC			5
59 #define _PC_PATH_MAX			6
60 #define _PC_PIPE_BUF			7
61 #define _PC_VDISABLE			8
62 #define _PC_LINK_MAX			25
63 /* new values */
64 #define _PC_SYNC_IO				26
65 #define _PC_ASYNC_IO			27
66 #define _PC_PRIO_IO				28
67 #define _PC_SOCK_MAXBUF			29
68 #define _PC_FILESIZEBITS		30
69 #define _PC_REC_INCR_XFER_SIZE	31
70 #define _PC_REC_MAX_XFER_SIZE	32
71 #define _PC_REC_MIN_XFER_SIZE	33
72 #define _PC_REC_XFER_ALIGN		34
73 #define _PC_ALLOC_SIZE_MIN		35
74 #define _PC_SYMLINK_MAX			36
75 #define _PC_2_SYMLINKS			37
76 #define _PC_XATTR_EXISTS		38
77 #define _PC_XATTR_ENABLED		39
78 
79 /* sysconf() constants */
80 /* BeOS supported values, do not touch */
81 #define _SC_ARG_MAX				15
82 #define _SC_CHILD_MAX			16
83 #define _SC_CLK_TCK				17
84 #define _SC_JOB_CONTROL			18
85 #define _SC_NGROUPS_MAX			19
86 #define _SC_OPEN_MAX			20
87 #define _SC_SAVED_IDS			21
88 #define _SC_STREAM_MAX			22
89 #define _SC_TZNAME_MAX			23
90 #define _SC_VERSION				24
91 /* new values */
92 #define _SC_GETGR_R_SIZE_MAX	25
93 #define _SC_GETPW_R_SIZE_MAX	26
94 #define _SC_PAGE_SIZE			27
95 #define _SC_PAGESIZE			_SC_PAGE_SIZE
96 #define _SC_SEM_NSEMS_MAX		28
97 #define _SC_SEM_VALUE_MAX		29
98 #define _SC_SEMAPHORES			30
99 #define _SC_THREADS				31
100 /* TODO: check */
101 #define _SC_IOV_MAX						32
102 #define _SC_UIO_MAXIOV					_SC_IOV_MAX
103 #define _SC_NPROCESSORS_MAX				33
104 #define _SC_NPROCESSORS_CONF			34
105 #define _SC_NPROCESSORS_ONLN			35
106 #define _SC_CPUID_MAX					36
107 #define _SC_ATEXIT_MAX					37
108 #define _SC_PASS_MAX					39
109 #define _SC_PHYS_PAGES					40
110 #define _SC_AVPHYS_PAGES				41
111 #define _SC_PIPE						42
112 #define _SC_SELECT						43
113 #define _SC_POLL						44
114 #define _SC_MAPPED_FILES				45
115 #define _SC_THREAD_PROCESS_SHARED		46
116 #define _SC_THREAD_STACK_MIN			47
117 #define _SC_THREAD_ATTR_STACKADDR		48
118 #define _SC_THREAD_ATTR_STACKSIZE		49
119 #define _SC_THREAD_PRIORITY_SCHEDULING	50
120 #define _SC_REALTIME_SIGNALS			51
121 #define	_SC_MEMORY_PROTECTION			52
122 
123 
124 /* confstr() constants */
125 #define _CS_PATH				1
126 
127 /* lseek() constants */
128 #ifndef SEEK_SET
129 #	define SEEK_SET 0
130 #endif
131 #ifndef SEEK_CUR
132 #	define SEEK_CUR 1
133 #endif
134 #ifndef SEEK_END
135 #	define SEEK_END 2
136 #endif
137 
138 
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142 
143 /* file functions */
144 extern int		access(const char *path, int accessMode);
145 extern int		faccessat(int fd, const char *path, int accessMode, int flag);
146 
147 extern int		chdir(const char *path);
148 extern int		fchdir(int fd);
149 extern char		*getcwd(char *buffer, size_t size);
150 
151 extern int		pipe(int fildes[2]);
152 extern int		dup(int fd);
153 extern int		dup2(int fd1, int fd2);
154 extern int		close(int fd);
155 extern int		link(const char *toPath, const char *path);
156 extern int		linkat(int toFD, const char *toPath, int pathFD,
157 					const char *path, int flag);
158 extern int		unlink(const char *name);
159 extern int		unlinkat(int fd, const char *path, int flag);
160 extern int		rmdir(const char *path);
161 
162 extern ssize_t  readlink(const char *path, char *buffer, size_t bufferSize);
163 extern ssize_t	readlinkat(int fd, const char *path, char *buffer,
164 					size_t bufferSize);
165 extern int      symlink(const char *toPath, const char *symlinkPath);
166 extern int		symlinkat(const char *toPath, int fd, const char *symlinkPath);
167 
168 extern int      ftruncate(int fd, off_t newSize);
169 extern int      truncate(const char *path, off_t newSize);
170 extern int		ioctl(int fd, unsigned long op, ...);
171 
172 extern ssize_t	read(int fd, void *buffer, size_t count);
173 extern ssize_t  read_pos(int fd, off_t pos, void *buffer, size_t count);
174 extern ssize_t	pread(int fd, void *buffer, size_t count, off_t pos);
175 extern ssize_t	write(int fd, const void *buffer, size_t count);
176 extern ssize_t  write_pos(int fd, off_t pos, const void *buffer,size_t count);
177 extern ssize_t	pwrite(int fd, const void *buffer, size_t count, off_t pos);
178 extern off_t	lseek(int fd, off_t offset, int whence);
179 
180 extern int		sync(void);
181 extern int		fsync(int fd);
182 
183 extern int		chown(const char *path, uid_t owner, gid_t group);
184 extern int		fchown(int fd, uid_t owner, gid_t group);
185 extern int		lchown(const char *path, uid_t owner, gid_t group);
186 extern int		fchownat(int fd, const char *path, uid_t owner, gid_t group,
187 					int flag);
188 
189 extern int		mknod(const char *name, mode_t mode, dev_t dev);
190 extern int		mknodat(int fd, const char *name, mode_t mode, dev_t dev);
191 
192 extern int		getpagesize(void);
193 extern int      getdtablesize(void);
194 extern long		sysconf(int name);
195 extern long		fpathconf(int fd, int name);
196 extern long		pathconf(const char *path, int name);
197 extern size_t	confstr(int name, char *buf, size_t len);
198 extern int		lockf(int fd, int function, off_t size);
199 
200 /* process functions */
201 extern pid_t	fork(void);
202 extern pid_t	vfork(void);
203 extern int		execve(const char *path, char * const argv[], char * const envp[]);
204 extern int		execl(const char *path, const char *arg, ...);
205 extern int		execv(const char *path, char *const *argv);
206 extern int		execlp(const char *file, const char *arg, ...);
207 extern int		execle(const char *path, const char *arg , ... /*, char **envp */);
208 extern int		exect(const char *path, char *const *argv);
209 extern int		execvp(const char *file, char *const *argv);
210 
211 extern void		_exit(int status);
212 
213 extern pid_t	tcgetpgrp(int fd);
214 extern int		tcsetpgrp(int fd, pid_t pgrpid);
215 extern void		*sbrk(long incr);
216 
217 extern unsigned	int	alarm(unsigned int seconds);
218 extern useconds_t	ualarm(useconds_t microSeconds, useconds_t interval);
219 extern unsigned int	sleep(unsigned int seconds);
220 extern int			usleep(unsigned int microSeconds);
221 extern int 			pause(void);
222 
223 /* process */
224 extern pid_t	getpid(void);
225 extern pid_t	getpgrp(void);
226 extern pid_t	getppid(void);
227 extern pid_t	getsid(pid_t pid);
228 extern pid_t	getpgid(pid_t pid);
229 
230 extern pid_t	setsid(void);
231 extern int		setpgid(pid_t pid, pid_t pgid);
232 extern pid_t	setpgrp(void);
233 
234 extern int		chroot(const char *path);
235 
236 /* access permissions */
237 extern gid_t	getegid(void);
238 extern uid_t	geteuid(void);
239 extern gid_t	getgid(void);
240 extern uid_t	getuid(void);
241 
242 extern int		setgid(gid_t gid);
243 extern int		setuid(uid_t uid);
244 extern int		setegid(gid_t gid);
245 extern int		seteuid(uid_t uid);
246 extern int		setregid(gid_t rgid, gid_t egid);
247 extern int		setreuid(uid_t ruid, uid_t euid);
248 
249 extern int		getgrouplist(const char* user, gid_t baseGroup,
250 					gid_t* groupList, int* groupCount);
251 extern int		getgroups(int groupCount, gid_t groupList[]);
252 extern int		initgroups(const char* user, gid_t baseGroup);
253 extern int		setgroups(int groupCount, const gid_t* groupList);
254 
255 extern char		*getlogin(void);
256 extern int		getlogin_r(char *name, size_t nameSize);
257 
258 /* host name */
259 extern int		sethostname(const char *hostName, size_t nameSize);
260 extern int		gethostname(char *hostName, size_t nameSize);
261 
262 /* tty */
263 extern int		isatty(int fd);
264 extern char		*ttyname(int fd);
265 extern int		ttyname_r(int fd, char *buffer, size_t bufferSize);
266 
267 /* misc */
268 extern char 	*crypt(const char *key, const char *salt);
269 extern void 	encrypt(char block[64], int edflag);
270 extern int		getopt(int argc, char *const *argv, const char *shortOpts);
271 extern void 	swab(const void *src, void *dest, ssize_t nbytes);
272 
273 /* getopt() related external variables */
274 extern char *optarg;
275 extern int optind, opterr, optopt;
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif  /* _UNISTD_H_ */
282