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