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