xref: /haiku/headers/posix/unistd.h (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
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 
115 /* process functions */
116 extern pid_t	fork(void);
117 extern pid_t	vfork(void);
118 extern int		execve(const char *path, char * const argv[], char * const envp[]);
119 extern int		execl(const char *path, const char *arg, ...);
120 extern int		execv(const char *path, char *const *argv);
121 extern int		execlp(const char *file, const char *arg, ...);
122 extern int		execle(const char *path, const char *arg , ... /*, char **envp */);
123 extern int		exect(const char *path, char *const *argv);
124 extern int		execvp(const char *file, char *const *argv);
125 
126 extern void		_exit(int status);
127 
128 extern pid_t	tcgetpgrp(int fd);
129 extern int		tcsetpgrp(int fd, pid_t pgrpid);
130 extern void		*sbrk(long incr);
131 
132 extern unsigned	int	alarm(unsigned int seconds);
133 extern useconds_t	ualarm(useconds_t microSeconds, useconds_t interval);
134 extern unsigned int	sleep(unsigned int seconds);
135 extern int			usleep(unsigned int microSeconds);
136 extern clock_t		clock(void);
137 extern int 			pause(void);
138 
139 /* process */
140 extern pid_t	getpid(void);
141 extern pid_t	getpgrp(void);
142 extern pid_t	getppid(void);
143 extern pid_t	getsid(pid_t pid);
144 extern pid_t	getpgid(pid_t pid);
145 
146 extern pid_t	setsid(void);
147 extern int		setpgid(pid_t pid, pid_t pgid);
148 extern pid_t	setpgrp(void);
149 
150 /* access permissions */
151 extern gid_t	getegid(void);
152 extern uid_t	geteuid(void);
153 extern gid_t	getgid(void);
154 extern int		getgroups(int groupSize, gid_t groupList[]);
155 extern uid_t	getuid(void);
156 
157 extern int		setgid(gid_t gid);
158 extern int		setuid(uid_t uid);
159 extern int		setegid(gid_t gid);
160 extern int		seteuid(uid_t uid);
161 
162 extern char		*getlogin(void);
163 extern int		getlogin_r(char *name, size_t nameSize);
164 
165 /* host name */
166 extern int		sethostname(const char *hostName, size_t nameSize);
167 extern int		gethostname(char *hostName, size_t nameSize);
168 
169 /* tty */
170 extern int		isatty(int fd);
171 extern char		*ttyname(int fd);
172 extern int		ttyname_r(int fd, char *buffer, size_t bufferSize);
173 
174 /* misc */
175 extern char 	*crypt(const char *key, const char *salt);
176 extern void 	encrypt(char block[64], int edflag);
177 extern int		getopt(int argc, char *const *argv, const char *shortOpts);
178 extern void 	swab(const void *src, void *dest, ssize_t nbytes);
179 
180 /* getopt() related external variables */
181 extern char *optarg;
182 extern int optind, opterr, optopt;
183 
184 // ToDo: should be moved to stdlib.h
185 extern char **environ;
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 
191 #endif  /* _UNISTD_H_ */
192