1
/* Substitute for and wrapper around <unistd.h>.
2
Copyright (C) 2003-2008 Free Software Foundation, Inc.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU Lesser General Public License as published by
6
the Free Software Foundation; either version 2, or (at your option)
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this program; if not, write to the Free Software Foundation,
16
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
21
@PRAGMA_SYSTEM_HEADER@
24
/* The include_next requires a split double-inclusion guard. */
26
# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
32
/* mingw doesn't define the SEEK_* macros in <unistd.h>. */
33
#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
37
/* mingw fails to declare _exit in <unistd.h>. */
38
/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
41
#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
43
# include <sys/types.h>
46
#if @GNULIB_GETHOSTNAME@
47
/* Get all possible declarations of gethostname(). */
48
# if @UNISTD_H_HAVE_WINSOCK2_H@
49
# include <winsock2.h>
50
# if !defined _GL_SYS_SOCKET_H
52
# define socket socket_used_without_including_sys_socket_h
54
# define connect connect_used_without_including_sys_socket_h
56
# define accept accept_used_without_including_sys_socket_h
58
# define bind bind_used_without_including_sys_socket_h
60
# define getpeername getpeername_used_without_including_sys_socket_h
62
# define getsockname getsockname_used_without_including_sys_socket_h
64
# define getsockopt getsockopt_used_without_including_sys_socket_h
66
# define listen listen_used_without_including_sys_socket_h
68
# define recv recv_used_without_including_sys_socket_h
70
# define send send_used_without_including_sys_socket_h
72
# define recvfrom recvfrom_used_without_including_sys_socket_h
74
# define sendto sendto_used_without_including_sys_socket_h
76
# define setsockopt setsockopt_used_without_including_sys_socket_h
78
# define shutdown shutdown_used_without_including_sys_socket_h
80
# if !defined _GL_SYS_SELECT_H
82
# define select select_used_without_including_sys_select_h
87
/* The definition of GL_LINK_WARNING is copied here. */
90
/* Declare overridden functions. */
99
# ifndef REPLACE_CHOWN
100
# define REPLACE_CHOWN 1
103
/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
104
to GID (if GID is not -1). Follow symbolic links.
105
Return 0 if successful, otherwise -1 and errno set.
106
See the POSIX:2001 specification
107
<http://www.opengroup.org/susv3xsh/chown.html>. */
108
# define chown rpl_chown
109
extern int chown (const char *file, uid_t uid, gid_t gid);
112
#elif defined GNULIB_POSIXCHECK
114
# define chown(f,u,g) \
115
(GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
116
"doesn't treat a uid or gid of -1 on some systems - " \
117
"use gnulib module chown for portability"), \
123
# if @UNISTD_H_HAVE_WINSOCK2_H@
124
/* Need a gnulib internal function. */
125
# define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
128
/* Automatically included by modules that need a replacement for close. */
130
# define close rpl_close
131
extern int close (int);
133
#elif @UNISTD_H_HAVE_WINSOCK2_H@
135
# define close close_used_without_requesting_gnulib_module_close
136
#elif defined GNULIB_POSIXCHECK
139
(GL_LINK_WARNING ("close does not portably work on sockets - " \
140
"use gnulib module close for portability"), \
147
/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
148
NEWFD = OLDFD, otherwise close NEWFD first if it is open.
149
Return 0 if successful, otherwise -1 and errno set.
150
See the POSIX:2001 specification
151
<http://www.opengroup.org/susv3xsh/dup2.html>. */
152
extern int dup2 (int oldfd, int newfd);
154
#elif defined GNULIB_POSIXCHECK
157
(GL_LINK_WARNING ("dup2 is unportable - " \
158
"use gnulib module dup2 for portability"), \
164
# if !@HAVE_DECL_ENVIRON@
165
/* Set of environment variables and values. An array of strings of the form
166
"VARIABLE=VALUE", terminated with a NULL. */
167
# if defined __APPLE__ && defined __MACH__
168
# include <crt_externs.h>
169
# define environ (*_NSGetEnviron ())
171
extern char **environ;
174
#elif defined GNULIB_POSIXCHECK
177
(GL_LINK_WARNING ("environ is unportable - " \
178
"use gnulib module environ for portability"), \
183
#if @GNULIB_EUIDACCESS@
184
# if !@HAVE_EUIDACCESS@
185
/* Like access(), except that is uses the effective user id and group id of
186
the current process. */
187
extern int euidaccess (const char *filename, int mode);
189
#elif defined GNULIB_POSIXCHECK
191
# define euidaccess(f,m) \
192
(GL_LINK_WARNING ("euidaccess is unportable - " \
193
"use gnulib module euidaccess for portability"), \
199
# if @REPLACE_FCHDIR@
201
/* Change the process' current working directory to the directory on which
202
the given file descriptor is open.
203
Return 0 if successful, otherwise -1 and errno set.
204
See the POSIX:2001 specification
205
<http://www.opengroup.org/susv3xsh/fchdir.html>. */
206
extern int fchdir (int /*fd*/);
209
extern int dup (int);
210
# define dup2 rpl_dup2
211
extern int dup2 (int, int);
214
#elif defined GNULIB_POSIXCHECK
217
(GL_LINK_WARNING ("fchdir is unportable - " \
218
"use gnulib module fchdir for portability"), \
224
/* Synchronize changes to a file.
225
Return 0 if successful, otherwise -1 and errno set.
226
See POSIX:2001 specification
227
<http://www.opengroup.org/susv3xsh/fsync.html>. */
229
extern int fsync (int fd);
231
#elif defined GNULIB_POSIXCHECK
234
(GL_LINK_WARNING ("fsync is unportable - " \
235
"use gnulib module fsync for portability"), \
240
#if @GNULIB_FTRUNCATE@
241
# if !@HAVE_FTRUNCATE@
242
/* Change the size of the file to which FD is opened to become equal to LENGTH.
243
Return 0 if successful, otherwise -1 and errno set.
244
See the POSIX:2001 specification
245
<http://www.opengroup.org/susv3xsh/ftruncate.html>. */
246
extern int ftruncate (int fd, off_t length);
248
#elif defined GNULIB_POSIXCHECK
250
# define ftruncate(f,l) \
251
(GL_LINK_WARNING ("ftruncate is unportable - " \
252
"use gnulib module ftruncate for portability"), \
258
/* Include the headers that might declare getcwd so that they will not
259
cause confusion if included after this file. */
261
# if @REPLACE_GETCWD@
262
/* Get the name of the current working directory, and put it in SIZE bytes
264
Return BUF if successful, or NULL if the directory couldn't be determined
265
or SIZE was too small.
266
See the POSIX:2001 specification
267
<http://www.opengroup.org/susv3xsh/getcwd.html>.
268
Additionally, the gnulib module 'getcwd' guarantees the following GNU
269
extension: If BUF is NULL, an array is allocated with 'malloc'; the array
270
is SIZE bytes long, unless SIZE == 0, in which case it is as big as
272
# define getcwd rpl_getcwd
273
extern char * getcwd (char *buf, size_t size);
275
#elif defined GNULIB_POSIXCHECK
277
# define getcwd(b,s) \
278
(GL_LINK_WARNING ("getcwd is unportable - " \
279
"use gnulib module getcwd for portability"), \
284
#if @GNULIB_GETDOMAINNAME@
285
/* Return the NIS domain name of the machine.
286
WARNING! The NIS domain name is unrelated to the fully qualified host name
287
of the machine. It is also unrelated to email addresses.
288
WARNING! The NIS domain name is usually the empty string or "(none)" when
291
Put up to LEN bytes of the NIS domain name into NAME.
292
Null terminate it if the name is shorter than LEN.
293
If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
294
Return 0 if successful, otherwise set errno and return -1. */
295
# if !@HAVE_GETDOMAINNAME@
296
extern int getdomainname(char *name, size_t len);
298
#elif defined GNULIB_POSIXCHECK
299
# undef getdomainname
300
# define getdomainname(n,l) \
301
(GL_LINK_WARNING ("getdomainname is unportable - " \
302
"use gnulib module getdomainname for portability"), \
303
getdomainname (n, l))
307
#if @GNULIB_GETDTABLESIZE@
308
# if !@HAVE_GETDTABLESIZE@
309
/* Return the maximum number of file descriptors in the current process. */
310
extern int getdtablesize (void);
312
#elif defined GNULIB_POSIXCHECK
313
# undef getdtablesize
314
# define getdtablesize() \
315
(GL_LINK_WARNING ("getdtablesize is unportable - " \
316
"use gnulib module getdtablesize for portability"), \
321
#if @GNULIB_GETHOSTNAME@
322
/* Return the standard host name of the machine.
323
WARNING! The host name may or may not be fully qualified.
325
Put up to LEN bytes of the host name into NAME.
326
Null terminate it if the name is shorter than LEN.
327
If the host name is longer than LEN, set errno = EINVAL and return -1.
328
Return 0 if successful, otherwise set errno and return -1. */
329
# if @UNISTD_H_HAVE_WINSOCK2_H@
331
# define gethostname rpl_gethostname
333
# if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
334
extern int gethostname(char *name, size_t len);
336
#elif @UNISTD_H_HAVE_WINSOCK2_H@
338
# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
339
#elif defined GNULIB_POSIXCHECK
341
# define gethostname(n,l) \
342
(GL_LINK_WARNING ("gethostname is unportable - " \
343
"use gnulib module gethostname for portability"), \
348
#if @GNULIB_GETLOGIN_R@
349
/* Copies the user's login name to NAME.
350
The array pointed to by NAME has room for SIZE bytes.
352
Returns 0 if successful. Upon error, an error number is returned, or -1 in
353
the case that the login name cannot be found but no specific error is
354
provided (this case is hopefully rare but is left open by the POSIX spec).
356
See <http://www.opengroup.org/susv3xsh/getlogin.html>.
358
# if !@HAVE_DECL_GETLOGIN_R@
360
extern int getlogin_r (char *name, size_t size);
362
#elif defined GNULIB_POSIXCHECK
364
# define getlogin_r(n,s) \
365
(GL_LINK_WARNING ("getlogin_r is unportable - " \
366
"use gnulib module getlogin_r for portability"), \
371
#if @GNULIB_GETPAGESIZE@
372
# if @REPLACE_GETPAGESIZE@
373
# define getpagesize rpl_getpagesize
374
extern int getpagesize (void);
375
# elif !@HAVE_GETPAGESIZE@
376
/* This is for POSIX systems. */
377
# if !defined getpagesize && defined _SC_PAGESIZE
378
# if ! (defined __VMS && __VMS_VER < 70000000)
379
# define getpagesize() sysconf (_SC_PAGESIZE)
382
/* This is for older VMS. */
383
# if !defined getpagesize && defined __VMS
385
# define getpagesize() 8192
387
# define getpagesize() 512
390
/* This is for BeOS. */
391
# if !defined getpagesize && @HAVE_OS_H@
393
# if defined B_PAGE_SIZE
394
# define getpagesize() B_PAGE_SIZE
397
/* This is for AmigaOS4.0. */
398
# if !defined getpagesize && defined __amigaos4__
399
# define getpagesize() 2048
401
/* This is for older Unix systems. */
402
# if !defined getpagesize && @HAVE_SYS_PARAM_H@
403
# include <sys/param.h>
404
# ifdef EXEC_PAGESIZE
405
# define getpagesize() EXEC_PAGESIZE
411
# define getpagesize() (NBPG * CLSIZE)
414
# define getpagesize() NBPC
420
#elif defined GNULIB_POSIXCHECK
422
# define getpagesize() \
423
(GL_LINK_WARNING ("getpagesize is unportable - " \
424
"use gnulib module getpagesize for portability"), \
429
#if @GNULIB_GETUSERSHELL@
430
# if !@HAVE_GETUSERSHELL@
431
/* Return the next valid login shell on the system, or NULL when the end of
432
the list has been reached. */
433
extern char *getusershell (void);
434
/* Rewind to pointer that is advanced at each getusershell() call. */
435
extern void setusershell (void);
436
/* Free the pointer that is advanced at each getusershell() call and
437
associated resources. */
438
extern void endusershell (void);
440
#elif defined GNULIB_POSIXCHECK
442
# define getusershell() \
443
(GL_LINK_WARNING ("getusershell is unportable - " \
444
"use gnulib module getusershell for portability"), \
447
# define setusershell() \
448
(GL_LINK_WARNING ("setusershell is unportable - " \
449
"use gnulib module getusershell for portability"), \
452
# define endusershell() \
453
(GL_LINK_WARNING ("endusershell is unportable - " \
454
"use gnulib module getusershell for portability"), \
460
# if @REPLACE_LCHOWN@
461
/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
462
to GID (if GID is not -1). Do not follow symbolic links.
463
Return 0 if successful, otherwise -1 and errno set.
464
See the POSIX:2001 specification
465
<http://www.opengroup.org/susv3xsh/lchown.html>. */
466
# define lchown rpl_lchown
467
extern int lchown (char const *file, uid_t owner, gid_t group);
469
#elif defined GNULIB_POSIXCHECK
471
# define lchown(f,u,g) \
472
(GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
473
"systems - use gnulib module lchown for portability"), \
480
/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
481
Return the new offset if successful, otherwise -1 and errno set.
482
See the POSIX:2001 specification
483
<http://www.opengroup.org/susv3xsh/lseek.html>. */
484
# define lseek rpl_lseek
485
extern off_t lseek (int fd, off_t offset, int whence);
487
#elif defined GNULIB_POSIXCHECK
489
# define lseek(f,o,w) \
490
(GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
491
"systems - use gnulib module lseek for portability"), \
496
#if @GNULIB_READLINK@
497
/* Read the contents of the symbolic link FILE and place the first BUFSIZE
498
bytes of it into BUF. Return the number of bytes placed into BUF if
499
successful, otherwise -1 and errno set.
500
See the POSIX:2001 specification
501
<http://www.opengroup.org/susv3xsh/readlink.html>. */
502
# if !@HAVE_READLINK@
504
extern int readlink (const char *file, char *buf, size_t bufsize);
506
#elif defined GNULIB_POSIXCHECK
508
# define readlink(f,b,s) \
509
(GL_LINK_WARNING ("readlink is unportable - " \
510
"use gnulib module readlink for portability"), \
516
/* Pause the execution of the current thread for N seconds.
517
Returns the number of seconds left to sleep.
518
See the POSIX:2001 specification
519
<http://www.opengroup.org/susv3xsh/sleep.html>. */
521
extern unsigned int sleep (unsigned int n);
523
#elif defined GNULIB_POSIXCHECK
526
(GL_LINK_WARNING ("sleep is unportable - " \
527
"use gnulib module sleep for portability"), \
532
#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
533
/* Write up to COUNT bytes starting at BUF to file descriptor FD.
534
See the POSIX:2001 specification
535
<http://www.opengroup.org/susv3xsh/write.html>. */
537
# define write rpl_write
538
extern ssize_t write (int fd, const void *buf, size_t count);
542
#ifdef FCHDIR_REPLACEMENT
543
/* gnulib internal function. */
544
extern void _gl_unregister_fd (int fd);
553
#endif /* _GL_UNISTD_H */
554
#endif /* _GL_UNISTD_H */