xref: /haiku/headers/posix/unistd.h (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
1 /*
2  * Copyright 2004-2008, 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			((char) - 2)	/* TODO: Check this! */
38 #define _POSIX_SEMAPHORES		(200112L)
39 #define _POSIX_THREADS			(200112L)
40 
41 /* pathconf() constants */
42 /* BeOS supported values, do not touch */
43 #define _PC_CHOWN_RESTRICTED	1
44 #define _PC_MAX_CANON			2
45 #define _PC_MAX_INPUT			3
46 #define _PC_NAME_MAX			4
47 #define _PC_NO_TRUNC			5
48 #define _PC_PATH_MAX			6
49 #define _PC_PIPE_BUF			7
50 #define _PC_VDISABLE			8
51 #define _PC_LINK_MAX			25
52 /* new values */
53 /* TODO: reorder */
54 #define _PC_SYNC_IO				26
55 #define _PC_ASYNC_IO			27
56 #define _PC_PRIO_IO				28
57 #define _PC_SOCK_MAXBUF			29
58 #define _PC_FILESIZEBITS		30
59 #define _PC_REC_INCR_XFER_SIZE	31
60 #define _PC_REC_MAX_XFER_SIZE	32
61 #define _PC_REC_MIN_XFER_SIZE	33
62 #define _PC_REC_XFER_ALIGN		34
63 #define _PC_ALLOC_SIZE_MIN		35
64 #define _PC_SYMLINK_MAX			36
65 #define _PC_2_SYMLINKS			37
66 #define _PC_XATTR_EXISTS		38
67 #define _PC_XATTR_ENABLED		39
68 
69 /* sysconf() constants */
70 /* BeOS supported values, do not touch */
71 #define _SC_ARG_MAX				15
72 #define _SC_CHILD_MAX			16
73 #define _SC_CLK_TCK				17
74 #define _SC_JOB_CONTROL			18
75 #define _SC_NGROUPS_MAX			19
76 #define _SC_OPEN_MAX			20
77 #define _SC_SAVED_IDS			21
78 #define _SC_STREAM_MAX			22
79 #define _SC_TZNAME_MAX			23
80 #define _SC_VERSION				24
81 #define _SC_GETGR_R_SIZE_MAX	25
82 #define _SC_GETPW_R_SIZE_MAX	26
83 #define _SC_PAGE_SIZE			27
84 #define _SC_PAGESIZE			_SC_PAGE_SIZE
85 #define _SC_SEM_NSEMS_MAX		28
86 #define _SC_SEM_VALUE_MAX		29
87 #define _SC_SEMAPHORES			30
88 #define _SC_THREADS				31
89 /* TODO: check and reorder */
90 #define _SC_IOV_MAX				32
91 #define _SC_UIO_MAXIOV			_SC_IOV_MAX
92 #define _SC_NPROCESSORS_MAX		33
93 #define _SC_NPROCESSORS_CONF	34
94 #define _SC_NPROCESSORS_ONLN	35
95 #define _SC_CPUID_MAX			36
96 #define _SC_ATEXIT_MAX			37
97 #define _SC_PASS_MAX			39
98 #define _SC_PHYS_PAGES			40
99 #define _SC_AVPHYS_PAGES		41
100 #define _SC_PIPE				42
101 #define _SC_SELECT				43
102 #define _SC_POLL				44
103 
104 
105 /* confstr() constants */
106 #define _CS_PATH				1
107 
108 /* lseek() constants */
109 #ifndef SEEK_SET
110 #	define SEEK_SET 0
111 #endif
112 #ifndef SEEK_CUR
113 #	define SEEK_CUR 1
114 #endif
115 #ifndef SEEK_END
116 #	define SEEK_END 2
117 #endif
118 
119 
120 #ifdef __cplusplus
121 extern "C" {
122 #endif
123 
124 /* file functions */
125 extern int		access(const char *path, int accessMode);
126 
127 extern int		chdir(const char *path);
128 extern int		fchdir(int fd);
129 extern char		*getcwd(char *buffer, size_t size);
130 
131 extern int		pipe(int fildes[2]);
132 extern int		dup(int fd);
133 extern int		dup2(int fd1, int fd2);
134 extern int		close(int fd);
135 extern int		link(const char *name, const char *new_name);
136 extern int		unlink(const char *name);
137 extern int		rmdir(const char *path);
138 
139 extern ssize_t  readlink(const char *path, char *buffer, size_t bufferSize);
140 extern int      symlink(const char *from, const char *to);
141 
142 extern int      ftruncate(int fd, off_t newSize);
143 extern int      truncate(const char *path, off_t newSize);
144 extern int		ioctl(int fd, unsigned long op, ...);
145 
146 extern ssize_t	read(int fd, void *buffer, size_t count);
147 extern ssize_t  read_pos(int fd, off_t pos, void *buffer, size_t count);
148 extern ssize_t	pread(int fd, void *buffer, size_t count, off_t pos);
149 extern ssize_t	write(int fd, const void *buffer, size_t count);
150 extern ssize_t  write_pos(int fd, off_t pos, const void *buffer,size_t count);
151 extern ssize_t	pwrite(int fd, const void *buffer, size_t count, off_t pos);
152 extern off_t	lseek(int fd, off_t offset, int whence);
153 
154 extern int		sync(void);
155 extern int		fsync(int fd);
156 
157 extern int		chown(const char *path, uid_t owner, gid_t group);
158 extern int		fchown(int fd, uid_t owner, gid_t group);
159 extern int		lchown(const char *path, uid_t owner, gid_t group);
160 
161 extern int		mknod(const char *name, mode_t mode, dev_t dev);
162 
163 extern int		getpagesize(void);
164 extern int      getdtablesize(void);
165 extern long		sysconf(int name);
166 extern long		fpathconf(int fd, int name);
167 extern long		pathconf(const char *path, int name);
168 extern size_t	confstr(int name, char *buf, size_t len);
169 extern int		lockf(int fd, int function, off_t size);
170 
171 /* process functions */
172 extern pid_t	fork(void);
173 extern pid_t	vfork(void);
174 extern int		execve(const char *path, char * const argv[], char * const envp[]);
175 extern int		execl(const char *path, const char *arg, ...);
176 extern int		execv(const char *path, char *const *argv);
177 extern int		execlp(const char *file, const char *arg, ...);
178 extern int		execle(const char *path, const char *arg , ... /*, char **envp */);
179 extern int		exect(const char *path, char *const *argv);
180 extern int		execvp(const char *file, char *const *argv);
181 
182 extern void		_exit(int status);
183 
184 extern pid_t	tcgetpgrp(int fd);
185 extern int		tcsetpgrp(int fd, pid_t pgrpid);
186 extern void		*sbrk(long incr);
187 
188 extern unsigned	int	alarm(unsigned int seconds);
189 extern useconds_t	ualarm(useconds_t microSeconds, useconds_t interval);
190 extern unsigned int	sleep(unsigned int seconds);
191 extern int			usleep(unsigned int microSeconds);
192 extern clock_t		clock(void);
193 extern int 			pause(void);
194 
195 /* process */
196 extern pid_t	getpid(void);
197 extern pid_t	getpgrp(void);
198 extern pid_t	getppid(void);
199 extern pid_t	getsid(pid_t pid);
200 extern pid_t	getpgid(pid_t pid);
201 
202 extern pid_t	setsid(void);
203 extern int		setpgid(pid_t pid, pid_t pgid);
204 extern pid_t	setpgrp(void);
205 
206 extern int		chroot(const char *path);
207 
208 /* access permissions */
209 extern gid_t	getegid(void);
210 extern uid_t	geteuid(void);
211 extern gid_t	getgid(void);
212 extern uid_t	getuid(void);
213 
214 extern int		setgid(gid_t gid);
215 extern int		setuid(uid_t uid);
216 extern int		setegid(gid_t gid);
217 extern int		seteuid(uid_t uid);
218 extern int		setregid(gid_t rgid, gid_t egid);
219 extern int		setreuid(uid_t ruid, uid_t euid);
220 
221 extern int		getgrouplist(const char* user, gid_t baseGroup,
222 					gid_t* groupList, int* groupCount);
223 extern int		getgroups(int groupCount, gid_t groupList[]);
224 extern int		initgroups(const char* user, gid_t baseGroup);
225 extern int		setgroups(int groupCount, const gid_t* groupList);
226 
227 extern char		*getlogin(void);
228 extern int		getlogin_r(char *name, size_t nameSize);
229 
230 /* host name */
231 extern int		sethostname(const char *hostName, size_t nameSize);
232 extern int		gethostname(char *hostName, size_t nameSize);
233 
234 /* tty */
235 extern int		isatty(int fd);
236 extern char		*ttyname(int fd);
237 extern int		ttyname_r(int fd, char *buffer, size_t bufferSize);
238 
239 /* misc */
240 extern char 	*crypt(const char *key, const char *salt);
241 extern void 	encrypt(char block[64], int edflag);
242 extern int		getopt(int argc, char *const *argv, const char *shortOpts);
243 extern void 	swab(const void *src, void *dest, ssize_t nbytes);
244 
245 /* getopt() related external variables */
246 extern char *optarg;
247 extern int optind, opterr, optopt;
248 
249 /* ToDo: should be moved to stdlib.h */
250 extern char **environ;
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif  /* _UNISTD_H_ */
257