1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Public Domain
5  * License:   Public Domain
6  * Authors:   Sean Kelly
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 module tango.stdc.posix.unistd;
10 
11 private import tango.stdc.posix.config;
12 private import tango.stdc.stddef;
13 public import tango.stdc.posix.inttypes;  // for intptr_t
14 public import tango.stdc.posix.sys.types; // for size_t, ssize_t, uid_t, gid_t, off_t, pid_t, useconds_t
15 public import tango.sys.consts.unistd;
16 extern (C):
17 
18 const STDIN_FILENO  = 0;
19 const STDOUT_FILENO = 1;
20 const STDERR_FILENO = 2;
21 
22 __gshared char*   optarg;
23 __gshared int     optind;
24 __gshared int     opterr;
25 __gshared int     optopt;
26 
27 int     access(in char*, int);
28 uint    alarm(uint);
29 int     chdir(in char*);
30 int     chroot(in char*);
31 int     chown(in char*, uid_t, gid_t);
32 int     close(int);
33 size_t  confstr(int, char*, size_t);
34 int     dup(int);
35 int     dup2(int, int);
36 int     execl(in char*, in char*, ...);
37 int     execle(in char*, in char*, ...);
38 int     execlp(in char*, in char*, ...);
39 int     execv(in char*, in char**);
40 int     execve(in char*, in char**, in char**);
41 int     execvp(in char*, in char**);
42 void    _exit(int);
43 int     fchown(int, uid_t, gid_t);
44 pid_t   fork();
45 c_long  fpathconf(int, int);
46 //int     ftruncate(int, off_t);
47 char*   getcwd(char*, size_t);
48 gid_t   getegid();
49 uid_t   geteuid();
50 gid_t   getgid();
51 int     getgroups(int, gid_t *);
52 int     gethostname(char*, size_t);
53 char*   getlogin();
54 int     getlogin_r(char*, size_t);
55 int     getopt(int, in char**, in char*);
56 pid_t   getpgrp();
57 pid_t   getpid();
58 pid_t   getppid();
59 uid_t   getuid();
60 int     isatty(int);
61 int     link(in char*, in char*);
62 //off_t   lseek(int, off_t, int);
63 c_long  pathconf(in char*, int);
64 int     pause();
65 int     pipe(int*);
66 ssize_t read(int, void*, size_t);
67 ssize_t readlink(in char*, char*, size_t);
68 int     rmdir(in char*);
69 int     setegid(gid_t);
70 int     seteuid(uid_t);
71 int     setgid(gid_t);
72 int     setpgid(pid_t, pid_t);
73 pid_t   setsid();
74 int     setuid(uid_t);
75 uint    sleep(uint);
76 int     symlink(in char*, in char*);
77 c_long  sysconf(int);
78 pid_t   tcgetpgrp(int);
79 int     tcsetpgrp(int, pid_t);
80 char*   ttyname(int);
81 int     ttyname_r(int, char*, size_t);
82 int     unlink(in char*);
83 ssize_t write(int, in void*, size_t);
84 
85 version( linux )
86 {
87   static if( __USE_LARGEFILE64 )
88   {
89     off_t lseek64(int, off_t, int);
90     alias lseek64 lseek;
91   }
92   else
93   {
94     off_t lseek(int, off_t, int);
95   }
96   static if( __USE_LARGEFILE64 )
97   {
98     int   ftruncate64(int, off_t);
99     alias ftruncate64 ftruncate;
100   }
101   else
102   {
103     int   ftruncate(int, off_t);
104   }
105 }
106 else version( FreeBSD )
107 {
108     off_t lseek(int, off_t, int);
109     int   ftruncate(int, off_t);
110 }
111 else version( solaris )
112 {
113   static if( __USE_LARGEFILE64 )
114   {
115     off_t lseek64(int, off_t, int);
116     alias lseek64 lseek;
117   }
118   else
119   {
120     off_t lseek(int, off_t, int);
121   }
122   static if( __USE_LARGEFILE64 )
123   {
124     int   ftruncate64(int, off_t);
125     alias ftruncate64 ftruncate;
126   }
127   else
128   {
129     int   ftruncate(int, off_t);
130   }
131 }
132 else
133 {
134     off_t lseek(int, off_t, int);
135     int   ftruncate(int, off_t);
136 }
137 
138 //
139 // File Synchronization (FSC)
140 //
141 int fsync(int);
142 
143 //
144 // Synchronized I/O (SIO)
145 //
146 int fdatasync(int);
147 
148 //
149 // XOpen (XSI)
150 //
151 /*
152 char*      crypt(in char*, in char*);
153 char*      ctermid(char*);
154 void       encrypt(char[64], int);
155 int        fchdir(int);
156 c_long     gethostid();
157 pid_t      getpgid(pid_t);
158 pid_t      getsid(pid_t);
159 char*      getwd(char*); // LEGACY
160 int        lchown(in char*, uid_t, gid_t);
161 int        lockf(int, int, off_t);
162 int        nice(int);
163 ssize_t    pread(int, void*, size_t, off_t);
164 ssize_t    pwrite(int, in void*, size_t, off_t);
165 pid_t      setpgrp();
166 int        setregid(gid_t, gid_t);
167 int        setreuid(uid_t, uid_t);
168 void       swab(in void*, void*, ssize_t);
169 void       sync();
170 int        truncate(in char*, off_t);
171 useconds_t ualarm(useconds_t, useconds_t);
172 int        usleep(useconds_t);
173 pid_t      vfork();
174 */
175 
176 version( linux )
177 {
178     char*      crypt(in char*, in char*);
179     char*      ctermid(char*);
180     void       encrypt(char[64], int);
181     int        fchdir(int);
182     c_long     gethostid();
183     pid_t      getpgid(pid_t);
184     pid_t      getsid(pid_t);
185     char*      getwd(char*); // LEGACY
186     int        lchown(in char*, uid_t, gid_t);
187     //int        lockf(int, int, off_t);
188     int        nice(int);
189     //ssize_t    pread(int, void*, size_t, off_t);
190     //ssize_t    pwrite(int, in void*, size_t, off_t);
191     pid_t      setpgrp();
192     int        setregid(gid_t, gid_t);
193     int        setreuid(uid_t, uid_t);
194     void       swab(in void*, void*, ssize_t);
195     void       sync();
196     //int        truncate(in char*, off_t);
197     useconds_t ualarm(useconds_t, useconds_t);
198     int        usleep(useconds_t);
199     pid_t      vfork();
200 
201   static if( __USE_LARGEFILE64 )
202   {
203     int        lockf64(int, int, off_t);
204     alias      lockf64 lockf;
205 
206     ssize_t    pread64(int, void*, size_t, off_t);
207     alias      pread64 pread;
208 
209     ssize_t    pwrite64(int, in void*, size_t, off_t);
210     alias      pwrite64 pwrite;
211 
212     int        truncate64(in char*, off_t);
213     alias      truncate64 truncate;
214   }
215   else
216   {
217     int        lockf(int, int, off_t);
218     ssize_t    pread(int, void*, size_t, off_t);
219     ssize_t    pwrite(int, in void*, size_t, off_t);
220     int        truncate(in char*, off_t);
221   }
222 }
223 else version (darwin)
224 {
225     char*      crypt(in char*, in char*);
226     char*      ctermid(char*);
227     void       encrypt(char[64], int);
228     int        fchdir(int);
229     c_long     gethostid();
230     pid_t      getpgid(pid_t);
231     pid_t      getsid(pid_t);
232     char*      getwd(char*); // LEGACY
233     int        lchown(in char*, uid_t, gid_t);
234     int        lockf(int, int, off_t);
235     int        nice(int);
236     ssize_t    pread(int, void*, size_t, off_t);
237     ssize_t    pwrite(int, in void*, size_t, off_t);
238     pid_t      setpgrp();
239     int        setregid(gid_t, gid_t);
240     int        setreuid(uid_t, uid_t);
241     void       swab(in void*, void*, ssize_t);
242     void       sync();
243     int        truncate(in char*, off_t);
244     useconds_t ualarm(useconds_t, useconds_t);
245     int        usleep(useconds_t);
246     pid_t      vfork();
247 }
248 else version (FreeBSD)
249 {
250     char*      crypt(in char*, in char*);
251     //char*      ctermid(char*);
252     void       encrypt(char*, int);
253     int        fchdir(int);
254     c_long     gethostid();
255     int        getpgid(pid_t);
256     int        getsid(pid_t);
257     char*      getwd(char*); // LEGACY
258     int        lchown(in char*, uid_t, gid_t);
259     int        lockf(int, int, off_t);
260     int        nice(int);
261     ssize_t    pread(int, void*, size_t, off_t);
262     ssize_t    pwrite(int, in void*, size_t, off_t);
263     int        setpgrp(pid_t, pid_t);
264     int        setregid(gid_t, gid_t);
265     int        setreuid(uid_t, uid_t);
266     void       swab(in void*, void*, ssize_t);
267     void       sync();
268     int        truncate(in char*, off_t);
269     useconds_t ualarm(useconds_t, useconds_t);
270     int        usleep(useconds_t);
271     pid_t      vfork();
272 }
273 else version (solaris)
274 {
275 	char*      crypt(in char*, in char*);
276 	//char*      ctermid(char*);
277 	void       encrypt(char*, int);
278 	int        fchdir(int);
279 	c_long     gethostid();
280 	int        getpgid(pid_t);
281 	int        getsid(pid_t);
282 	char*      getwd(char*); // LEGACY
283 	int        lchown(in char*, uid_t, gid_t);
284 	int        nice(int);
285 	int        setpgrp(pid_t, pid_t);
286 	int        setregid(gid_t, gid_t);
287 	int        setreuid(uid_t, uid_t);
288 	void       swab(in void*, void*, ssize_t);
289 	void       sync();
290 	useconds_t ualarm(useconds_t, useconds_t);
291 	int        usleep(useconds_t);
292 	pid_t      vfork();
293 
294   static if( __USE_LARGEFILE64 )
295   {
296     int        lockf64(int, int, off_t);
297     alias      lockf64 lockf;
298 
299     ssize_t    pread64(int, void*, size_t, off_t);
300     alias      pread64 pread;
301 
302     ssize_t    pwrite64(int, in void*, size_t, off_t);
303     alias      pwrite64 pwrite;
304 
305     int        truncate64(in char*, off_t);
306     alias      truncate64 truncate;
307   }
308   else
309   {
310     int        lockf(int, int, off_t);
311     ssize_t    pread(int, void*, size_t, off_t);
312     ssize_t    pwrite(int, in void*, size_t, off_t);
313     int        truncate(in char*, off_t);
314   }
315 }
316