Use Gnulib's `full-write' and `full-read' modules.
[bpt/guile.git] / lib / unistd.in.h
CommitLineData
9b36a80c
LC
1/* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2003-2008 Free Software Foundation, Inc.
3
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)
7 any later version.
8
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.
13
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. */
17
18#ifndef _GL_UNISTD_H
19
20#if __GNUC__ >= 3
21@PRAGMA_SYSTEM_HEADER@
22#endif
23
24/* The include_next requires a split double-inclusion guard. */
25#if @HAVE_UNISTD_H@
26# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
27#endif
28
29#ifndef _GL_UNISTD_H
30#define _GL_UNISTD_H
31
32/* mingw doesn't define the SEEK_* macros in <unistd.h>. */
33#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
34# include <stdio.h>
35#endif
36
37/* mingw fails to declare _exit in <unistd.h>. */
38#include <stdlib.h>
39
40#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
41/* Get ssize_t. */
42# include <sys/types.h>
43#endif
44
45#if @GNULIB_GETHOSTNAME@
46/* Get all possible declarations of gethostname(). */
47# if @UNISTD_H_HAVE_WINSOCK2_H@
48# include <winsock2.h>
49# if !defined _GL_SYS_SOCKET_H
50# undef socket
51# define socket socket_used_without_including_sys_socket_h
52# undef connect
53# define connect connect_used_without_including_sys_socket_h
54# undef accept
55# define accept accept_used_without_including_sys_socket_h
56# undef bind
57# define bind bind_used_without_including_sys_socket_h
58# undef getpeername
59# define getpeername getpeername_used_without_including_sys_socket_h
60# undef getsockname
61# define getsockname getsockname_used_without_including_sys_socket_h
62# undef getsockopt
63# define getsockopt getsockopt_used_without_including_sys_socket_h
64# undef listen
65# define listen listen_used_without_including_sys_socket_h
66# undef recv
67# define recv recv_used_without_including_sys_socket_h
68# undef send
69# define send send_used_without_including_sys_socket_h
70# undef recvfrom
71# define recvfrom recvfrom_used_without_including_sys_socket_h
72# undef sendto
73# define sendto sendto_used_without_including_sys_socket_h
74# undef setsockopt
75# define setsockopt setsockopt_used_without_including_sys_socket_h
76# undef shutdown
77# define shutdown shutdown_used_without_including_sys_socket_h
78# endif
79# if !defined _GL_SYS_SELECT_H
80# undef select
81# define select select_used_without_including_sys_select_h
82# endif
83# endif
84#endif
85
86/* The definition of GL_LINK_WARNING is copied here. */
87
88
89/* Declare overridden functions. */
90
91#ifdef __cplusplus
92extern "C" {
93#endif
94
95
96#if @GNULIB_CHOWN@
97# if @REPLACE_CHOWN@
98# ifndef REPLACE_CHOWN
99# define REPLACE_CHOWN 1
100# endif
101# if REPLACE_CHOWN
102/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
103 to GID (if GID is not -1). Follow symbolic links.
104 Return 0 if successful, otherwise -1 and errno set.
105 See the POSIX:2001 specification
106 <http://www.opengroup.org/susv3xsh/chown.html>. */
107# define chown rpl_chown
108extern int chown (const char *file, uid_t uid, gid_t gid);
109# endif
110# endif
111#elif defined GNULIB_POSIXCHECK
112# undef chown
113# define chown(f,u,g) \
114 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
115 "doesn't treat a uid or gid of -1 on some systems - " \
116 "use gnulib module chown for portability"), \
117 chown (f, u, g))
118#endif
119
120
121#if @GNULIB_CLOSE@
122# if @UNISTD_H_HAVE_WINSOCK2_H@
123/* Need a gnulib internal function. */
124# define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
125# endif
126# if @REPLACE_CLOSE@
127/* Automatically included by modules that need a replacement for close. */
128# undef close
129# define close rpl_close
130extern int close (int);
131# endif
132#elif @UNISTD_H_HAVE_WINSOCK2_H@
133# undef close
134# define close close_used_without_requesting_gnulib_module_close
135#elif defined GNULIB_POSIXCHECK
136# undef close
137# define close(f) \
138 (GL_LINK_WARNING ("close does not portably work on sockets - " \
139 "use gnulib module close for portability"), \
140 close (f))
141#endif
142
143
144#if @GNULIB_DUP2@
145# if !@HAVE_DUP2@
146/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
147 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
148 Return 0 if successful, otherwise -1 and errno set.
149 See the POSIX:2001 specification
150 <http://www.opengroup.org/susv3xsh/dup2.html>. */
151extern int dup2 (int oldfd, int newfd);
152# endif
153#elif defined GNULIB_POSIXCHECK
154# undef dup2
155# define dup2(o,n) \
156 (GL_LINK_WARNING ("dup2 is unportable - " \
157 "use gnulib module dup2 for portability"), \
158 dup2 (o, n))
159#endif
160
161
162#if @GNULIB_ENVIRON@
163# if !@HAVE_DECL_ENVIRON@
164/* Set of environment variables and values. An array of strings of the form
165 "VARIABLE=VALUE", terminated with a NULL. */
166# if defined __APPLE__ && defined __MACH__
167# include <crt_externs.h>
168# define environ (*_NSGetEnviron ())
169# else
170extern char **environ;
171# endif
172# endif
173#elif defined GNULIB_POSIXCHECK
174# undef environ
175# define environ \
176 (GL_LINK_WARNING ("environ is unportable - " \
177 "use gnulib module environ for portability"), \
178 environ)
179#endif
180
181
182#if @GNULIB_EUIDACCESS@
183# if !@HAVE_EUIDACCESS@
184/* Like access(), except that is uses the effective user id and group id of
185 the current process. */
186extern int euidaccess (const char *filename, int mode);
187# endif
188#elif defined GNULIB_POSIXCHECK
189# undef euidaccess
190# define euidaccess(f,m) \
191 (GL_LINK_WARNING ("euidaccess is unportable - " \
192 "use gnulib module euidaccess for portability"), \
193 euidaccess (f, m))
194#endif
195
196
197#if @GNULIB_FCHDIR@
198# if @REPLACE_FCHDIR@
199
200/* Change the process' current working directory to the directory on which
201 the given file descriptor is open.
202 Return 0 if successful, otherwise -1 and errno set.
203 See the POSIX:2001 specification
204 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
205extern int fchdir (int /*fd*/);
206
207# define dup rpl_dup
208extern int dup (int);
209# define dup2 rpl_dup2
210extern int dup2 (int, int);
211
212# endif
213#elif defined GNULIB_POSIXCHECK
214# undef fchdir
215# define fchdir(f) \
216 (GL_LINK_WARNING ("fchdir is unportable - " \
217 "use gnulib module fchdir for portability"), \
218 fchdir (f))
219#endif
220
221
222#if @GNULIB_FSYNC@
223/* Synchronize changes to a file.
224 Return 0 if successful, otherwise -1 and errno set.
225 See POSIX:2001 specification
226 <http://www.opengroup.org/susv3xsh/fsync.html>. */
227# if !@HAVE_FSYNC@
228extern int fsync (int fd);
229# endif
230#elif defined GNULIB_POSIXCHECK
231# undef fsync
232# define fsync(fd) \
233 (GL_LINK_WARNING ("fsync is unportable - " \
234 "use gnulib module fsync for portability"), \
235 fsync (fd))
236#endif
237
238
239#if @GNULIB_FTRUNCATE@
240# if !@HAVE_FTRUNCATE@
241/* Change the size of the file to which FD is opened to become equal to LENGTH.
242 Return 0 if successful, otherwise -1 and errno set.
243 See the POSIX:2001 specification
244 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
245extern int ftruncate (int fd, off_t length);
246# endif
247#elif defined GNULIB_POSIXCHECK
248# undef ftruncate
249# define ftruncate(f,l) \
250 (GL_LINK_WARNING ("ftruncate is unportable - " \
251 "use gnulib module ftruncate for portability"), \
252 ftruncate (f, l))
253#endif
254
255
256#if @GNULIB_GETCWD@
257/* Include the headers that might declare getcwd so that they will not
258 cause confusion if included after this file. */
259# include <stdlib.h>
260# if @REPLACE_GETCWD@
261/* Get the name of the current working directory, and put it in SIZE bytes
262 of BUF.
263 Return BUF if successful, or NULL if the directory couldn't be determined
264 or SIZE was too small.
265 See the POSIX:2001 specification
266 <http://www.opengroup.org/susv3xsh/getcwd.html>.
267 Additionally, the gnulib module 'getcwd' guarantees the following GNU
268 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
269 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
270 necessary. */
271# define getcwd rpl_getcwd
272extern char * getcwd (char *buf, size_t size);
273# endif
274#elif defined GNULIB_POSIXCHECK
275# undef getcwd
276# define getcwd(b,s) \
277 (GL_LINK_WARNING ("getcwd is unportable - " \
278 "use gnulib module getcwd for portability"), \
279 getcwd (b, s))
280#endif
281
282
283#if @GNULIB_GETDOMAINNAME@
284/* Return the NIS domain name of the machine.
285 WARNING! The NIS domain name is unrelated to the fully qualified host name
286 of the machine. It is also unrelated to email addresses.
287 WARNING! The NIS domain name is usually the empty string or "(none)" when
288 not using NIS.
289
290 Put up to LEN bytes of the NIS domain name into NAME.
291 Null terminate it if the name is shorter than LEN.
292 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
293 Return 0 if successful, otherwise set errno and return -1. */
294# if !@HAVE_GETDOMAINNAME@
295extern int getdomainname(char *name, size_t len);
296# endif
297#elif defined GNULIB_POSIXCHECK
298# undef getdomainname
299# define getdomainname(n,l) \
300 (GL_LINK_WARNING ("getdomainname is unportable - " \
301 "use gnulib module getdomainname for portability"), \
302 getdomainname (n, l))
303#endif
304
305
306#if @GNULIB_GETDTABLESIZE@
307# if !@HAVE_GETDTABLESIZE@
308/* Return the maximum number of file descriptors in the current process. */
309extern int getdtablesize (void);
310# endif
311#elif defined GNULIB_POSIXCHECK
312# undef getdtablesize
313# define getdtablesize() \
314 (GL_LINK_WARNING ("getdtablesize is unportable - " \
315 "use gnulib module getdtablesize for portability"), \
316 getdtablesize ())
317#endif
318
319
320#if @GNULIB_GETHOSTNAME@
321/* Return the standard host name of the machine.
322 WARNING! The host name may or may not be fully qualified.
323
324 Put up to LEN bytes of the host name into NAME.
325 Null terminate it if the name is shorter than LEN.
326 If the host name is longer than LEN, set errno = EINVAL and return -1.
327 Return 0 if successful, otherwise set errno and return -1. */
328# if @UNISTD_H_HAVE_WINSOCK2_H@
329# undef gethostname
330# define gethostname rpl_gethostname
331# endif
332# if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
333extern int gethostname(char *name, size_t len);
334# endif
335#elif @UNISTD_H_HAVE_WINSOCK2_H@
336# undef gethostname
337# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
338#elif defined GNULIB_POSIXCHECK
339# undef gethostname
340# define gethostname(n,l) \
341 (GL_LINK_WARNING ("gethostname is unportable - " \
342 "use gnulib module gethostname for portability"), \
343 gethostname (n, l))
344#endif
345
346
347#if @GNULIB_GETLOGIN_R@
348/* Copies the user's login name to NAME.
349 The array pointed to by NAME has room for SIZE bytes.
350
351 Returns 0 if successful. Upon error, an error number is returned, or -1 in
352 the case that the login name cannot be found but no specific error is
353 provided (this case is hopefully rare but is left open by the POSIX spec).
354
355 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
356 */
357# if !@HAVE_DECL_GETLOGIN_R@
358# include <stddef.h>
359extern int getlogin_r (char *name, size_t size);
360# endif
361#elif defined GNULIB_POSIXCHECK
362# undef getlogin_r
363# define getlogin_r(n,s) \
364 (GL_LINK_WARNING ("getlogin_r is unportable - " \
365 "use gnulib module getlogin_r for portability"), \
366 getlogin_r (n, s))
367#endif
368
369
370#if @GNULIB_GETPAGESIZE@
371# if @REPLACE_GETPAGESIZE@
372# define getpagesize rpl_getpagesize
373extern int getpagesize (void);
374# elif !@HAVE_GETPAGESIZE@
375/* This is for POSIX systems. */
376# if !defined getpagesize && defined _SC_PAGESIZE
377# if ! (defined __VMS && __VMS_VER < 70000000)
378# define getpagesize() sysconf (_SC_PAGESIZE)
379# endif
380# endif
381/* This is for older VMS. */
382# if !defined getpagesize && defined __VMS
383# ifdef __ALPHA
384# define getpagesize() 8192
385# else
386# define getpagesize() 512
387# endif
388# endif
389/* This is for BeOS. */
390# if !defined getpagesize && @HAVE_OS_H@
391# include <OS.h>
392# if defined B_PAGE_SIZE
393# define getpagesize() B_PAGE_SIZE
394# endif
395# endif
396/* This is for AmigaOS4.0. */
397# if !defined getpagesize && defined __amigaos4__
398# define getpagesize() 2048
399# endif
400/* This is for older Unix systems. */
401# if !defined getpagesize && @HAVE_SYS_PARAM_H@
402# include <sys/param.h>
403# ifdef EXEC_PAGESIZE
404# define getpagesize() EXEC_PAGESIZE
405# else
406# ifdef NBPG
407# ifndef CLSIZE
408# define CLSIZE 1
409# endif
410# define getpagesize() (NBPG * CLSIZE)
411# else
412# ifdef NBPC
413# define getpagesize() NBPC
414# endif
415# endif
416# endif
417# endif
418# endif
419#elif defined GNULIB_POSIXCHECK
420# undef getpagesize
421# define getpagesize() \
422 (GL_LINK_WARNING ("getpagesize is unportable - " \
423 "use gnulib module getpagesize for portability"), \
424 getpagesize ())
425#endif
426
427
428#if @GNULIB_GETUSERSHELL@
429# if !@HAVE_GETUSERSHELL@
430/* Return the next valid login shell on the system, or NULL when the end of
431 the list has been reached. */
432extern char *getusershell (void);
433/* Rewind to pointer that is advanced at each getusershell() call. */
434extern void setusershell (void);
435/* Free the pointer that is advanced at each getusershell() call and
436 associated resources. */
437extern void endusershell (void);
438# endif
439#elif defined GNULIB_POSIXCHECK
440# undef getusershell
441# define getusershell() \
442 (GL_LINK_WARNING ("getusershell is unportable - " \
443 "use gnulib module getusershell for portability"), \
444 getusershell ())
445# undef setusershell
446# define setusershell() \
447 (GL_LINK_WARNING ("setusershell is unportable - " \
448 "use gnulib module getusershell for portability"), \
449 setusershell ())
450# undef endusershell
451# define endusershell() \
452 (GL_LINK_WARNING ("endusershell is unportable - " \
453 "use gnulib module getusershell for portability"), \
454 endusershell ())
455#endif
456
457
458#if @GNULIB_LCHOWN@
459# if @REPLACE_LCHOWN@
460/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
461 to GID (if GID is not -1). Do not follow symbolic links.
462 Return 0 if successful, otherwise -1 and errno set.
463 See the POSIX:2001 specification
464 <http://www.opengroup.org/susv3xsh/lchown.html>. */
465# define lchown rpl_lchown
466extern int lchown (char const *file, uid_t owner, gid_t group);
467# endif
468#elif defined GNULIB_POSIXCHECK
469# undef lchown
470# define lchown(f,u,g) \
471 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
472 "systems - use gnulib module lchown for portability"), \
473 lchown (f, u, g))
474#endif
475
476
477#if @GNULIB_LSEEK@
478# if @REPLACE_LSEEK@
479/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
480 Return the new offset if successful, otherwise -1 and errno set.
481 See the POSIX:2001 specification
482 <http://www.opengroup.org/susv3xsh/lseek.html>. */
483# define lseek rpl_lseek
484 extern off_t lseek (int fd, off_t offset, int whence);
485# endif
486#elif defined GNULIB_POSIXCHECK
487# undef lseek
488# define lseek(f,o,w) \
489 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
490 "systems - use gnulib module lseek for portability"), \
491 lseek (f, o, w))
492#endif
493
494
495#if @GNULIB_READLINK@
496/* Read the contents of the symbolic link FILE and place the first BUFSIZE
497 bytes of it into BUF. Return the number of bytes placed into BUF if
498 successful, otherwise -1 and errno set.
499 See the POSIX:2001 specification
500 <http://www.opengroup.org/susv3xsh/readlink.html>. */
501# if !@HAVE_READLINK@
502# include <stddef.h>
503extern int readlink (const char *file, char *buf, size_t bufsize);
504# endif
505#elif defined GNULIB_POSIXCHECK
506# undef readlink
507# define readlink(f,b,s) \
508 (GL_LINK_WARNING ("readlink is unportable - " \
509 "use gnulib module readlink for portability"), \
510 readlink (f, b, s))
511#endif
512
513
514#if @GNULIB_SLEEP@
515/* Pause the execution of the current thread for N seconds.
516 Returns the number of seconds left to sleep.
517 See the POSIX:2001 specification
518 <http://www.opengroup.org/susv3xsh/sleep.html>. */
519# if !@HAVE_SLEEP@
520extern unsigned int sleep (unsigned int n);
521# endif
522#elif defined GNULIB_POSIXCHECK
523# undef sleep
524# define sleep(n) \
525 (GL_LINK_WARNING ("sleep is unportable - " \
526 "use gnulib module sleep for portability"), \
527 sleep (n))
528#endif
529
530
531#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
532/* Write up to COUNT bytes starting at BUF to file descriptor FD.
533 See the POSIX:2001 specification
534 <http://www.opengroup.org/susv3xsh/write.html>. */
535# undef write
536# define write rpl_write
537extern ssize_t write (int fd, const void *buf, size_t count);
538#endif
539
540
541#ifdef FCHDIR_REPLACEMENT
542/* gnulib internal function. */
543extern void _gl_unregister_fd (int fd);
544#endif
545
546
547#ifdef __cplusplus
548}
549#endif
550
551
552#endif /* _GL_UNISTD_H */
553#endif /* _GL_UNISTD_H */