Add.
[libtasn1.git] / gl / unistd_.h
blob1fce5095e601012cc4dd7efae19443a42da16f77
1 /* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2004-2007 Free Software Foundation, Inc.
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.
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.
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. */
18 #ifndef _GL_UNISTD_H
19 #define _GL_UNISTD_H
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
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
34 /* mingw fails to declare _exit in <unistd.h>. */
35 #include <stdlib.h>
37 /* The definition of GL_LINK_WARNING is copied here. */
40 /* Declare overridden functions. */
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
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
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
85 #if @GNULIB_FCHDIR@
86 # if @REPLACE_FCHDIR@
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*/);
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);
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
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
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
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.
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).
164 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
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
179 #if @GNULIB_READLINK@
180 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
181 bytes of it into BUF. Return the number of bytes placed into BUF if
182 successful, otherwise -1 and errno set.
183 See the POSIX:2001 specification
184 <http://www.opengroup.org/susv3xsh/readlink.html>. */
185 # if !@HAVE_READLINK@
186 # include <stddef.h>
187 extern int readlink (const char *file, char *buf, size_t bufsize);
188 # endif
189 #elif defined GNULIB_POSIXCHECK
190 # undef readlink
191 # define readlink(f,b,s) \
192 (GL_LINK_WARNING ("readlink is unportable - " \
193 "use gnulib module readlink for portability"), \
194 readlink (f, b, s))
195 #endif
198 #if @GNULIB_SLEEP@
199 /* Pause the execution of the current thread for N seconds.
200 Returns the number of seconds left to sleep.
201 See the POSIX:2001 specification
202 <http://www.opengroup.org/susv3xsh/sleep.html>. */
203 # if !@HAVE_SLEEP@
204 extern unsigned int sleep (unsigned int n);
205 # endif
206 #elif defined GNULIB_POSIXCHECK
207 # undef sleep
208 # define sleep(n) \
209 (GL_LINK_WARNING ("sleep is unportable - " \
210 "use gnulib module sleep for portability"), \
211 sleep (n))
212 #endif
215 #ifdef __cplusplus
217 #endif
220 #endif /* _GL_UNISTD_H */