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