New module 'sleep'.
[gnulib.git] / lib / unistd_.h
1 /* Substitute for and wrapper around <unistd.h>.
2    Copyright (C) 2004-2007 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 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 General Public License for more details.
13
14    You should have received a copy of the GNU 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 #define _GL_UNISTD_H
20
21 #if @HAVE_UNISTD_H@
22 # include @ABSOLUTE_UNISTD_H@
23 #endif
24
25 /* mingw doesn't define the SEEK_* macros in <unistd.h>.  */
26 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
27 # include <stdio.h>
28 #endif
29
30 /* mingw fails to declare _exit in <unistd.h>.  */
31 #include <stdlib.h>
32
33 /* The definition of GL_LINK_WARNING is copied here.  */
34
35
36 /* Declare overridden functions.  */
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42
43 #if @GNULIB_CHOWN@
44 # if @REPLACE_CHOWN@
45 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
46    to GID (if GID is not -1).
47    Return 0 if successful, otherwise -1 and errno set.
48    See the POSIX:2001 specification
49    <http://www.opengroup.org/susv3xsh/chown.html>.  */
50 #  define chown rpl_chown
51 extern int chown (const char *file, uid_t uid, gid_t gid);
52 # endif
53 #elif defined GNULIB_POSIXCHECK
54 # undef chown
55 # define chown(f,u,g) \
56     (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
57                       "doesn't treat a uid or gid of -1 on some systems - " \
58                       "use gnulib module chown for portability"), \
59      chown (f, u, g))
60 #endif
61
62
63 #if @GNULIB_DUP2@
64 # if !@HAVE_DUP2@
65 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
66    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
67    Return 0 if successful, otherwise -1 and errno set.
68    See the POSIX:2001 specification
69    <http://www.opengroup.org/susv3xsh/dup2.html>.  */
70 extern int dup2 (int oldfd, int newfd);
71 # endif
72 #elif defined GNULIB_POSIXCHECK
73 # undef dup2
74 # define dup2(o,n) \
75     (GL_LINK_WARNING ("dup2 is unportable - " \
76                       "use gnulib module dup2 for portability"), \
77      dup2 (o, n))
78 #endif
79
80
81 #if @GNULIB_FCHDIR@
82 # if @REPLACE_FCHDIR@
83
84 /* Change the process' current working directory to the directory on which
85    the given file descriptor is open.
86    Return 0 if successful, otherwise -1 and errno set.
87    See the POSIX:2001 specification
88    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
89 extern int fchdir (int /*fd*/);
90
91 #  define close rpl_close
92 extern int close (int);
93 #  define dup rpl_dup
94 extern int dup (int);
95 #  define dup2 rpl_dup2
96 extern int dup2 (int, int);
97
98 # endif
99 #elif defined GNULIB_POSIXCHECK
100 # undef fchdir
101 # define fchdir(f) \
102     (GL_LINK_WARNING ("fchdir is unportable - " \
103                       "use gnulib module fchdir for portability"), \
104      fchdir (f))
105 #endif
106
107
108 #if @GNULIB_FTRUNCATE@
109 # if !@HAVE_FTRUNCATE@
110 /* Change the size of the file to which FD is opened to become equal to LENGTH.
111    Return 0 if successful, otherwise -1 and errno set.
112    See the POSIX:2001 specification
113    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
114 extern int ftruncate (int fd, off_t length);
115 # endif
116 #elif defined GNULIB_POSIXCHECK
117 # undef ftruncate
118 # define ftruncate(f,l) \
119     (GL_LINK_WARNING ("ftruncate is unportable - " \
120                       "use gnulib module ftruncate for portability"), \
121      ftruncate (f, l))
122 #endif
123
124
125 #if @GNULIB_GETCWD@
126 /* Include the headers that might declare getcwd so that they will not
127    cause confusion if included after this file.  */
128 # include <stdlib.h>
129 # if @REPLACE_GETCWD@
130 /* Get the name of the current working directory, and put it in SIZE bytes
131    of BUF.
132    Return BUF if successful, or NULL if the directory couldn't be determined
133    or SIZE was too small.
134    See the POSIX:2001 specification
135    <http://www.opengroup.org/susv3xsh/getcwd.html>.
136    Additionally, the gnulib module 'getcwd' guarantees the following GNU
137    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
138    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
139    necessary.  */
140 #  define getcwd rpl_getcwd
141 extern char * getcwd (char *buf, size_t size);
142 # endif
143 #elif defined GNULIB_POSIXCHECK
144 # undef getcwd
145 # define getcwd(b,s) \
146     (GL_LINK_WARNING ("getcwd is unportable - " \
147                       "use gnulib module getcwd for portability"), \
148      getcwd (b, s))
149 #endif
150
151
152 #if @GNULIB_GETLOGIN_R@
153 /* Copies the user's login name to NAME.
154    The array pointed to by NAME has room for SIZE bytes.
155
156    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
157    the case that the login name cannot be found but no specific error is
158    provided (this case is hopefully rare but is left open by the POSIX spec).
159
160    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
161  */
162 # if !@HAVE_DECL_GETLOGIN_R@
163 #  include <stddef.h>
164 extern int getlogin_r (char *name, size_t size);
165 # endif
166 #elif defined GNULIB_POSIXCHECK
167 # undef getlogin_r
168 # define getlogin_r(n,s) \
169     (GL_LINK_WARNING ("getlogin_r is unportable - " \
170                       "use gnulib module getlogin_r for portability"), \
171      getlogin_r (n, s))
172 #endif
173
174
175 #if @GNULIB_READLINK@
176 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
177    bytes of it into BUF.  Return the number of bytes placed into BUF if
178    successful, otherwise -1 and errno set.
179    See the POSIX:2001 specification
180    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
181 # if !@HAVE_READLINK@
182 #  include <stddef.h>
183 extern int readlink (const char *file, char *buf, size_t bufsize);
184 # endif
185 #elif defined GNULIB_POSIXCHECK
186 # undef readlink
187 # define readlink(f,b,s) \
188     (GL_LINK_WARNING ("readlink is unportable - " \
189                       "use gnulib module readlink for portability"), \
190      readlink (f, b, s))
191 #endif
192
193
194 #if @GNULIB_SLEEP@
195 /* Pause the execution of the current thread for N seconds.
196    Returns the number of seconds left to sleep.
197    See the POSIX:2001 specification
198    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
199 # if !@HAVE_SLEEP@
200 extern unsigned int sleep (unsigned int n);
201 # endif
202 #elif defined GNULIB_POSIXCHECK
203 # undef sleep
204 # define sleep(n) \
205     (GL_LINK_WARNING ("sleep is unportable - " \
206                       "use gnulib module sleep for portability"), \
207      sleep (n))
208 #endif
209
210
211 #ifdef __cplusplus
212 }
213 #endif
214
215
216 #endif /* _GL_UNISTD_H */