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