xref: /haiku/headers/posix/unistd.h (revision cfc3fa87da824bdf593eb8b817a83b6376e77935)
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)
32 
33 /* pathconf() constants */
34 #define _PC_CHOWN_RESTRICTED	1
35 #define _PC_MAX_CANON			2
36 #define _PC_MAX_INPUT			3
37 #define _PC_NAME_MAX			4
38 #define _PC_NO_TRUNC			5
39 #define _PC_PATH_MAX			6
40 #define _PC_PIPE_BUF			7
41 #define _PC_VDISABLE			8
42 #define _PC_LINK_MAX			25
43 #define _POSIX_CHOWN_RESTRICTED	9
44 #define _POSIX_JOB_CONTROL		10
45 #define _POSIX_NO_TRUNC			11
46 #define _POSIX_SAVED_IDS		12
47 #define _POSIX_VDISABLE			((cc_t) - 2)
48 
49 /* sysconf() constants */
50 #define _SC_ARG_MAX				15
51 #define _SC_CHILD_MAX			16
52 #define _SC_CLK_TCK				17
53 #define _SC_JOB_CONTROL			18
54 #define _SC_NGROUPS_MAX			19
55 #define _SC_OPEN_MAX			20
56 #define _SC_SAVED_IDS			21
57 #define _SC_STREAM_MAX			22
58 #define _SC_TZNAME_MAX			23
59 #define _SC_VERSION				24
60 #define _SC_GETGR_R_SIZE_MAX	25
61 #define _SC_GETPW_R_SIZE_MAX	26
62 #define _SC_PAGE_SIZE			27
63 #define _SC_PAGESIZE			_SC_PAGE_SIZE
64 
65 /* lseek() constants */
66 #ifndef SEEK_SET
67 #	define SEEK_SET 0
68 #endif
69 #ifndef SEEK_CUR
70 #	define SEEK_CUR 1
71 #endif
72 #ifndef SEEK_END
73 #	define SEEK_END 2
74 #endif
75 
76 
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80 
81 /* file functions */
82 extern int		access(const char *path, int accessMode);
83 
84 extern int		chdir(const char *path);
85 extern int		fchdir(int fd);
86 extern char		*getcwd(char *buffer, size_t size);
87 
88 extern int		pipe(int fildes[2]);
89 extern int		dup(int fd);
90 extern int		dup2(int fd1, int fd2);
91 extern int		close(int fd);
92 extern int		link(const char *name, const char *new_name);
93 extern int		unlink(const char *name);
94 extern int		rmdir(const char *path);
95 
96 extern ssize_t  readlink(const char *path, char *buffer, size_t bufferSize);
97 extern int      symlink(const char *from, const char *to);
98 
99 extern int      ftruncate(int fd, off_t newSize);
100 extern int      truncate(const char *path, off_t newSize);
101 extern int		ioctl(int fd, unsigned long op, ...);
102 
103 extern ssize_t	read(int fd, void *buffer, size_t count);
104 extern ssize_t  read_pos(int fd, off_t pos, void *buffer, size_t count);
105 extern ssize_t	pread(int fd, void *buffer, size_t count, off_t pos);
106 extern ssize_t	write(int fd, const void *buffer, size_t count);
107 extern ssize_t  write_pos(int fd, off_t pos, const void *buffer,size_t count);
108 extern ssize_t	pwrite(int fd, const void *buffer, size_t count, off_t pos);
109 extern off_t	lseek(int fd, off_t offset, int whence);
110 
111 extern int		sync(void);
112 extern int		fsync(int fd);
113 
114 extern int		chown(const char *path, uid_t owner, gid_t group);
115 extern int		fchown(int fd, uid_t owner, gid_t group);
116 extern int		lchown(const char *path, uid_t owner, gid_t group);
117 
118 extern int		mknod(const char *name, mode_t mode, dev_t dev);
119 
120 extern int		getpagesize(void);
121 extern int      getdtablesize(void);
122 extern long		sysconf(int name);
123 extern long		fpathconf(int fd, int name);
124 extern long		pathconf(const char *path, int name);
125 extern size_t	confstr(int name, char *buf, size_t len);
126 extern int		lockf(int fd, int function, off_t size);
127 
128 /* process functions */
129 extern pid_t	fork(void);
130 extern pid_t	vfork(void);
131 extern int		execve(const char *path, char * const argv[], char * const envp[]);
132 extern int		execl(const char *path, const char *arg, ...);
133 extern int		execv(const char *path, char *const *argv);
134 extern int		execlp(const char *file, const char *arg, ...);
135 extern int		execle(const char *path, const char *arg , ... /*, char **envp */);
136 extern int		exect(const char *path, char *const *argv);
137 extern int		execvp(const char *file, char *const *argv);
138 
139 extern void		_exit(int status);
140 
141 extern pid_t	tcgetpgrp(int fd);
142 extern int		tcsetpgrp(int fd, pid_t pgrpid);
143 extern void		*sbrk(long incr);
144 
145 extern unsigned	int	alarm(unsigned int seconds);
146 extern useconds_t	ualarm(useconds_t microSeconds, useconds_t interval);
147 extern unsigned int	sleep(unsigned int seconds);
148 extern int			usleep(unsigned int microSeconds);
149 extern clock_t		clock(void);
150 extern int 			pause(void);
151 
152 /* process */
153 extern pid_t	getpid(void);
154 extern pid_t	getpgrp(void);
155 extern pid_t	getppid(void);
156 extern pid_t	getsid(pid_t pid);
157 extern pid_t	getpgid(pid_t pid);
158 
159 extern pid_t	setsid(void);
160 extern int		setpgid(pid_t pid, pid_t pgid);
161 extern pid_t	setpgrp(void);
162 
163 extern int		chroot(const char *path);
164 
165 /* access permissions */
166 extern gid_t	getegid(void);
167 extern uid_t	geteuid(void);
168 extern gid_t	getgid(void);
169 extern uid_t	getuid(void);
170 
171 extern int		setgid(gid_t gid);
172 extern int		setuid(uid_t uid);
173 extern int		setegid(gid_t gid);
174 extern int		seteuid(uid_t uid);
175 extern int		setregid(gid_t rgid, gid_t egid);
176 extern int		setreuid(uid_t ruid, uid_t euid);
177 
178 extern int		getgrouplist(const char* user, gid_t baseGroup,
179 					gid_t* groupList, int* groupCount);
180 extern int		getgroups(int groupCount, gid_t groupList[]);
181 extern int		initgroups(const char* user, gid_t baseGroup);
182 extern int		setgroups(int groupCount, const gid_t* groupList);
183 
184 extern char		*getlogin(void);
185 extern int		getlogin_r(char *name, size_t nameSize);
186 
187 /* host name */
188 extern int		sethostname(const char *hostName, size_t nameSize);
189 extern int		gethostname(char *hostName, size_t nameSize);
190 
191 /* tty */
192 extern int		isatty(int fd);
193 extern char		*ttyname(int fd);
194 extern int		ttyname_r(int fd, char *buffer, size_t bufferSize);
195 
196 /* misc */
197 extern char 	*crypt(const char *key, const char *salt);
198 extern void 	encrypt(char block[64], int edflag);
199 extern int		getopt(int argc, char *const *argv, const char *shortOpts);
200 extern void 	swab(const void *src, void *dest, ssize_t nbytes);
201 
202 /* getopt() related external variables */
203 extern char *optarg;
204 extern int optind, opterr, optopt;
205 
206 // ToDo: should be moved to stdlib.h
207 extern char **environ;
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 
213 #endif  /* _UNISTD_H_ */
214