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