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