2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef SERVICE_RUNTIME_INCLUDE_SYS_UNISTD_H_
35 #define SERVICE_RUNTIME_INCLUDE_SYS_UNISTD_H_
42 * We need this file in the service_runtime only to agree on enum values,
43 * therefore most of it should be compiled only for NaCl applications
45 #ifdef __native_client__
47 #include <sys/types.h>
48 #include <sys/_types.h>
50 #define __need_ptrdiff_t
53 extern char **environ
;
55 void _EXFUN(_exit
, (int __status
) _ATTRIBUTE ((noreturn
)));
57 int _EXFUN(access
,(const char *__path
, int __amode
));
58 unsigned _EXFUN(alarm
, (unsigned __secs
));
59 int _EXFUN(chdir
, (const char *__path
));
60 int _EXFUN(chmod
, (const char *__path
, mode_t __mode
));
61 #if !defined(__INSIDE_CYGWIN__)
62 int _EXFUN(chown
, (const char *__path
, uid_t __owner
, gid_t __group
));
64 #if defined(__CYGWIN__) || defined(__rtems__)
65 int _EXFUN(chroot
, (const char *__path
));
67 int _EXFUN(close
, (int __fildes
));
68 #if defined(__CYGWIN__)
69 size_t _EXFUN(confstr
, (int __name
, char *__buf
, size_t __len
));
71 char _EXFUN(*ctermid
, (char *__s
));
72 char _EXFUN(*cuserid
, (char *__s
));
73 #if defined(__CYGWIN__)
74 int _EXFUN(daemon
, (int nochdir
, int noclose
));
76 int _EXFUN(dup
, (int __fildes
));
77 int _EXFUN(dup2
, (int __fildes
, int __fildes2
));
78 #if defined(__CYGWIN__)
79 void _EXFUN(endusershell
, (void));
81 int _EXFUN(execl
, (const char *__path
, const char *, ... ));
82 int _EXFUN(execle
, (const char *__path
, const char *, ... ));
83 int _EXFUN(execlp
, (const char *__file
, const char *, ... ));
84 int _EXFUN(execv
, (const char *__path
, char * const __argv
[] ));
85 int _EXFUN(execve
, (const char *__path
, char * const __argv
[], char * const __envp
[] ));
86 int _EXFUN(execvp
, (const char *__file
, char * const __argv
[] ));
87 #if defined(__CYGWIN__) || defined(__rtems__) || defined(__SPU__)
88 int _EXFUN(fchdir
, (int __fildes
));
90 int _EXFUN(fchmod
, (int __fildes
, mode_t __mode
));
91 #if !defined(__INSIDE_CYGWIN__)
92 int _EXFUN(fchown
, (int __fildes
, uid_t __owner
, gid_t __group
));
94 pid_t
_EXFUN(fork
, (void ));
95 long _EXFUN(fpathconf
, (int __fd
, int __name
));
96 int _EXFUN(fsync
, (int __fd
));
97 int _EXFUN(fdatasync
, (int __fd
));
98 char _EXFUN(*getcwd
, (char *__buf
, size_t __size
));
99 #if defined(__CYGWIN__)
100 int _EXFUN(getdomainname
,(char *__name
, size_t __len
));
102 #if !defined(__INSIDE_CYGWIN__)
103 gid_t
_EXFUN(getegid
, (void ));
104 uid_t
_EXFUN(geteuid
, (void ));
105 gid_t
_EXFUN(getgid
, (void ));
107 int _EXFUN(getgroups
, (int __gidsetsize
, gid_t __grouplist
[] ));
108 #if defined(__CYGWIN__)
109 long _EXFUN(gethostid
, (void));
111 char _EXFUN(*getlogin
, (void ));
112 #if defined(_POSIX_THREAD_SAFE_FUNCTIONS)
113 int _EXFUN(getlogin_r
, (char *name
, size_t namesize
) );
115 char _EXFUN(*getpass
, (const char *__prompt
));
116 size_t _EXFUN(getpagesize
, (void));
117 #if defined(__CYGWIN__)
118 int _EXFUN(getpeereid
, (int, uid_t
*, gid_t
*));
120 pid_t
_EXFUN(getpgid
, (pid_t
));
121 pid_t
_EXFUN(getpgrp
, (void ));
122 pid_t
_EXFUN(getpid
, (void ));
123 pid_t
_EXFUN(getppid
, (void ));
125 pid_t
_EXFUN(getsid
, (pid_t
));
127 #if !defined(__INSIDE_CYGWIN__)
128 uid_t
_EXFUN(getuid
, (void ));
131 char * _EXFUN(getusershell
, (void));
132 char _EXFUN(*getwd
, (char *__buf
));
133 int _EXFUN(iruserok
, (unsigned long raddr
, int superuser
, const char *ruser
, const char *luser
));
135 int _EXFUN(isatty
, (int __fildes
));
136 #if !defined(__INSIDE_CYGWIN__)
137 int _EXFUN(lchown
, (const char *__path
, uid_t __owner
, gid_t __group
));
139 int _EXFUN(link
, (const char *__path1
, const char *__path2
));
140 int _EXFUN(nice
, (int __nice_value
));
141 #if !defined(__INSIDE_CYGWIN__)
142 off_t
_EXFUN(lseek
, (int __fildes
, off_t __offset
, int __whence
));
149 int _EXFUN(lockf
, (int __fd
, int __cmd
, off_t __len
));
151 long _EXFUN(pathconf
, (const char *__path
, int __name
));
152 int _EXFUN(pause
, (void ));
154 int _EXFUN(pthread_atfork
, (void (*)(void), void (*)(void), void (*)(void)));
156 int _EXFUN(pipe
, (int __fildes
[2] ));
157 ssize_t
_EXFUN(pread
, (int __fd
, void *__buf
, size_t __nbytes
, off_t __offset
));
158 ssize_t
_EXFUN(pwrite
, (int __fd
, const void *__buf
, size_t __nbytes
, off_t __offset
));
159 _READ_WRITE_RETURN_TYPE
_EXFUN(read
, (int __fd
, void *__buf
, size_t __nbyte
));
160 #if defined(__CYGWIN__)
161 int _EXFUN(rresvport
, (int *__alport
));
162 int _EXFUN(revoke
, (char *__path
));
164 int _EXFUN(rmdir
, (const char *__path
));
165 #if defined(__CYGWIN__)
166 int _EXFUN(ruserok
, (const char *rhost
, int superuser
, const char *ruser
, const char *luser
));
168 void * _EXFUN(sbrk
, (ptrdiff_t __incr
));
169 #if !defined(__INSIDE_CYGWIN__)
170 #if defined(__CYGWIN__)
171 int _EXFUN(setegid
, (gid_t __gid
));
172 int _EXFUN(seteuid
, (uid_t __uid
));
174 int _EXFUN(setgid
, (gid_t __gid
));
176 #if defined(__CYGWIN__)
177 int _EXFUN(setgroups
, (int ngroups
, const gid_t
*grouplist
));
179 int _EXFUN(setpgid
, (pid_t __pid
, pid_t __pgid
));
180 int _EXFUN(setpgrp
, (void ));
181 #if defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
182 int _EXFUN(setregid
, (gid_t __rgid
, gid_t __egid
));
183 int _EXFUN(setreuid
, (uid_t __ruid
, uid_t __euid
));
185 pid_t
_EXFUN(setsid
, (void ));
186 #if !defined(__INSIDE_CYGWIN__)
187 int _EXFUN(setuid
, (uid_t __uid
));
189 #if defined(__CYGWIN__)
190 void _EXFUN(setusershell
, (void));
192 unsigned _EXFUN(sleep
, (unsigned int __seconds
));
193 void _EXFUN(swab
, (const void *, void *, ssize_t
));
194 long _EXFUN(sysconf
, (int __name
));
195 pid_t
_EXFUN(tcgetpgrp
, (int __fildes
));
196 int _EXFUN(tcsetpgrp
, (int __fildes
, pid_t __pgrp_id
));
197 char _EXFUN(*ttyname
, (int __fildes
));
198 #if defined(__CYGWIN__)
199 int _EXFUN(ttyname_r
, (int, char *, size_t));
201 int _EXFUN(unlink
, (const char *__path
));
202 int _EXFUN(usleep
, (useconds_t __useconds
));
203 int _EXFUN(vhangup
, (void ));
204 _READ_WRITE_RETURN_TYPE
_EXFUN(write
, (int __fd
, const void *__buf
, size_t __nbyte
));
207 # define __UNISTD_GETOPT__
209 # undef __UNISTD_GETOPT__
211 extern char *optarg
; /* getopt(3) external variables */
212 extern int optind
, opterr
, optopt
;
213 int getopt(int, char * const [], const char *);
214 extern int optreset
; /* getopt(3) external variable */
217 #ifndef _POSIX_SOURCE
218 pid_t
_EXFUN(vfork
, (void ));
220 extern char *suboptarg
; /* getsubopt(3) external variable */
221 int getsubopt(char **, char * const *, char **);
222 #endif /* _POSIX_SOURCE */
224 #ifdef _COMPILING_NEWLIB
225 /* Provide prototypes for most of the _<systemcall> names that are
226 provided in newlib for some compilers. */
227 int _EXFUN(_close
, (int __fildes
));
228 pid_t
_EXFUN(_fork
, (void ));
229 pid_t
_EXFUN(_getpid
, (void ));
230 int _EXFUN(_link
, (const char *__path1
, const char *__path2
));
231 _off_t
_EXFUN(_lseek
, (int __fildes
, _off_t __offset
, int __whence
));
232 #ifdef __LARGE64_FILES
233 _off64_t
_EXFUN(_lseek64
, (int __filedes
, _off64_t __offset
, int __whence
));
235 _READ_WRITE_RETURN_TYPE
_EXFUN(_read
, (int __fd
, void *__buf
, size_t __nbyte
));
236 void * _EXFUN(_sbrk
, (ptrdiff_t __incr
));
237 int _EXFUN(_unlink
, (const char *__path
));
238 _READ_WRITE_RETURN_TYPE
_EXFUN(_write
, (int __fd
, const void *__buf
, size_t __nbyte
));
239 int _EXFUN(_execve
, (const char *__path
, char * const __argv
[], char * const __envp
[] ));
242 #if defined(__CYGWIN__) || defined(__rtems__) || defined(__sh__) || defined(__SPU__)
243 #if !defined(__INSIDE_CYGWIN__)
244 int _EXFUN(ftruncate
, (int __fd
, off_t __length
));
245 int _EXFUN(truncate
, (const char *, off_t __length
));
249 #if defined(__CYGWIN__) || defined(__rtems__)
250 int _EXFUN(getdtablesize
, (void));
251 int _EXFUN(setdtablesize
, (int));
252 useconds_t
_EXFUN(ualarm
, (useconds_t __useconds
, useconds_t __interval
));
253 #if !(defined (_WINSOCK_H) || defined (__USE_W32_SOCKETS))
254 /* winsock[2].h defines as __stdcall, and with int as 2nd arg */
255 int _EXFUN(gethostname
, (char *__name
, size_t __len
));
257 char * _EXFUN(mktemp
, (char *));
260 #if defined(__CYGWIN__) || defined(__SPU__)
261 void _EXFUN(sync
, (void));
262 #elif defined(__rtems__)
263 int _EXFUN(sync
, (void));
266 int _EXFUN(readlink
, (const char *__path
, char *__buf
, int __buflen
));
267 int _EXFUN(symlink
, (const char *__name1
, const char *__name2
));
278 #include <sys/features.h>
280 #define STDIN_FILENO 0 /* standard input file descriptor */
281 #define STDOUT_FILENO 1 /* standard output file descriptor */
282 #define STDERR_FILENO 2 /* standard error file descriptor */
284 #endif /* __native_client__ */
287 * sysconf values as supported by NativeClient
288 * TODO: this needs a few more comments
291 NACL_ABI__SC_NPROCESSORS_ONLN
,
292 #define NACL_ABI__SC_NPROCESSORS_ONLN NACL_ABI__SC_NPROCESSORS_ONLN
296 #ifdef __native_client__
298 * TODO pathconf and confstr are not supported on NaCl,
299 * consider removing the definitions below.
303 * pathconf values per IEEE Std 1003.1, 2004 Edition
306 #define _PC_LINK_MAX 0
307 #define _PC_MAX_CANON 1
308 #define _PC_MAX_INPUT 2
309 #define _PC_NAME_MAX 3
310 #define _PC_PATH_MAX 4
311 #define _PC_PIPE_BUF 5
312 #define _PC_CHOWN_RESTRICTED 6
313 #define _PC_NO_TRUNC 7
314 #define _PC_VDISABLE 8
315 #define _PC_ASYNC_IO 9
316 #define _PC_PRIO_IO 10
317 #define _PC_SYNC_IO 11
318 #define _PC_FILESIZEBITS 12
319 #define _PC_2_SYMLINKS 13
320 #define _PC_SYMLINK_MAX 14
322 /* Ask for POSIX permission bits support. */
323 #define _PC_POSIX_PERMISSIONS 90
324 /* Ask for full POSIX permission support including uid/gid settings. */
325 #define _PC_POSIX_SECURITY 91
329 * confstr values per IEEE Std 1003.1, 2004 Edition
332 #ifdef __CYGWIN__ /* Only defined on Cygwin for now. */
334 #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1
335 #define _CS_XBS5_ILP32_OFF32_CFLAGS _CS_POSIX_V6_ILP32_OFF32_CFLAGS
336 #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 2
337 #define _CS_XBS5_ILP32_OFF32_LDFLAGS _CS_POSIX_V6_ILP32_OFF32_LDFLAGS
338 #define _CS_POSIX_V6_ILP32_OFF32_LIBS 3
339 #define _CS_XBS5_ILP32_OFF32_LIBS _CS_POSIX_V6_ILP32_OFF32_LIBS
340 #define _CS_XBS5_ILP32_OFF32_LINTFLAGS 4
341 #define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 5
342 #define _CS_XBS5_ILP32_OFFBIG_CFLAGS _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
343 #define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 6
344 #define _CS_XBS5_ILP32_OFFBIG_LDFLAGS _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
345 #define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 7
346 #define _CS_XBS5_ILP32_OFFBIG_LIBS _CS_POSIX_V6_ILP32_OFFBIG_LIBS
347 #define _CS_XBS5_ILP32_OFFBIG_LINTFLAGS 8
348 #define _CS_POSIX_V6_LP64_OFF64_CFLAGS 9
349 #define _CS_XBS5_LP64_OFF64_CFLAGS _CS_POSIX_V6_LP64_OFF64_CFLAGS
350 #define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 10
351 #define _CS_XBS5_LP64_OFF64_LDFLAGS _CS_POSIX_V6_LP64_OFF64_LDFLAGS
352 #define _CS_POSIX_V6_LP64_OFF64_LIBS 11
353 #define _CS_XBS5_LP64_OFF64_LIBS _CS_POSIX_V6_LP64_OFF64_LIBS
354 #define _CS_XBS5_LP64_OFF64_LINTFLAGS 12
355 #define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 13
356 #define _CS_XBS5_LPBIG_OFFBIG_CFLAGS _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
357 #define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 14
358 #define _CS_XBS5_LPBIG_OFFBIG_LDFLAGS _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
359 #define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 15
360 #define _CS_XBS5_LPBIG_OFFBIG_LIBS _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
361 #define _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS 16
362 #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 17
365 #endif /* __native_client__ */
368 # define MAXPATHLEN 1024
374 #endif /* SERVICE_RUNTIME_INCLUDE_SYS_UNISTD_H_ */