~drizzle-trunk/drizzle/development

815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
1
/* Substitute for and wrapper around <unistd.h>.
994.2.8 by Monty Taylor
Updated gnulib files.
2
   Copyright (C) 2003-2008 Free Software Foundation, Inc.
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
3
4
   This program is free software; you can redistribute it and/or modify
5
   it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
13
14
   You should have received a copy of the GNU Lesser 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
994.2.8 by Monty Taylor
Updated gnulib files.
20
#if __GNUC__ >= 3
21
@PRAGMA_SYSTEM_HEADER@
22
#endif
23
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
24
/* The include_next requires a split double-inclusion guard.  */
25
#if @HAVE_UNISTD_H@
26
# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
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>.  */
994.2.8 by Monty Taylor
Updated gnulib files.
38
/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
39
#include <stdlib.h>
40
994.2.8 by Monty Taylor
Updated gnulib files.
41
#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
42
/* Get ssize_t.  */
43
# include <sys/types.h>
44
#endif
45
46
#if @GNULIB_GETHOSTNAME@
47
/* Get all possible declarations of gethostname().  */
48
# if @UNISTD_H_HAVE_WINSOCK2_H@
49
#  include <winsock2.h>
50
#  if !defined _GL_SYS_SOCKET_H
51
#   undef socket
52
#   define socket		socket_used_without_including_sys_socket_h
53
#   undef connect
54
#   define connect		connect_used_without_including_sys_socket_h
55
#   undef accept
56
#   define accept		accept_used_without_including_sys_socket_h
57
#   undef bind
58
#   define bind			bind_used_without_including_sys_socket_h
59
#   undef getpeername
60
#   define getpeername		getpeername_used_without_including_sys_socket_h
61
#   undef getsockname
62
#   define getsockname		getsockname_used_without_including_sys_socket_h
63
#   undef getsockopt
64
#   define getsockopt		getsockopt_used_without_including_sys_socket_h
65
#   undef listen
66
#   define listen		listen_used_without_including_sys_socket_h
67
#   undef recv
68
#   define recv			recv_used_without_including_sys_socket_h
69
#   undef send
70
#   define send			send_used_without_including_sys_socket_h
71
#   undef recvfrom
72
#   define recvfrom		recvfrom_used_without_including_sys_socket_h
73
#   undef sendto
74
#   define sendto		sendto_used_without_including_sys_socket_h
75
#   undef setsockopt
76
#   define setsockopt		setsockopt_used_without_including_sys_socket_h
77
#   undef shutdown
78
#   define shutdown		shutdown_used_without_including_sys_socket_h
79
#  endif
80
#  if !defined _GL_SYS_SELECT_H
81
#   undef select
82
#   define select		select_used_without_including_sys_select_h
83
#  endif
84
# endif
85
#endif
86
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
87
/* The definition of GL_LINK_WARNING is copied here.  */
88
89
90
/* Declare overridden functions.  */
91
92
#ifdef __cplusplus
93
extern "C" {
94
#endif
95
96
97
#if @GNULIB_CHOWN@
98
# if @REPLACE_CHOWN@
99
#  ifndef REPLACE_CHOWN
100
#   define REPLACE_CHOWN 1
101
#  endif
102
#  if REPLACE_CHOWN
103
/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
104
   to GID (if GID is not -1).  Follow symbolic links.
105
   Return 0 if successful, otherwise -1 and errno set.
106
   See the POSIX:2001 specification
107
   <http://www.opengroup.org/susv3xsh/chown.html>.  */
108
#   define chown rpl_chown
109
extern int chown (const char *file, uid_t uid, gid_t gid);
110
#  endif
111
# endif
112
#elif defined GNULIB_POSIXCHECK
113
# undef chown
114
# define chown(f,u,g) \
115
    (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
116
                      "doesn't treat a uid or gid of -1 on some systems - " \
117
                      "use gnulib module chown for portability"), \
118
     chown (f, u, g))
119
#endif
120
121
994.2.8 by Monty Taylor
Updated gnulib files.
122
#if @GNULIB_CLOSE@
123
# if @UNISTD_H_HAVE_WINSOCK2_H@
124
/* Need a gnulib internal function.  */
125
#  define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
126
# endif
127
# if @REPLACE_CLOSE@
128
/* Automatically included by modules that need a replacement for close.  */
129
#  undef close
130
#  define close rpl_close
131
extern int close (int);
132
# endif
133
#elif @UNISTD_H_HAVE_WINSOCK2_H@
134
# undef close
135
# define close close_used_without_requesting_gnulib_module_close
136
#elif defined GNULIB_POSIXCHECK
137
# undef close
138
# define close(f) \
139
    (GL_LINK_WARNING ("close does not portably work on sockets - " \
140
                      "use gnulib module close for portability"), \
141
     close (f))
142
#endif
143
144
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
145
#if @GNULIB_DUP2@
146
# if !@HAVE_DUP2@
147
/* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
148
   NEWFD = OLDFD, otherwise close NEWFD first if it is open.
149
   Return 0 if successful, otherwise -1 and errno set.
150
   See the POSIX:2001 specification
151
   <http://www.opengroup.org/susv3xsh/dup2.html>.  */
152
extern int dup2 (int oldfd, int newfd);
153
# endif
154
#elif defined GNULIB_POSIXCHECK
155
# undef dup2
156
# define dup2(o,n) \
157
    (GL_LINK_WARNING ("dup2 is unportable - " \
158
                      "use gnulib module dup2 for portability"), \
159
     dup2 (o, n))
160
#endif
161
162
163
#if @GNULIB_ENVIRON@
164
# if !@HAVE_DECL_ENVIRON@
165
/* Set of environment variables and values.  An array of strings of the form
166
   "VARIABLE=VALUE", terminated with a NULL.  */
167
#  if defined __APPLE__ && defined __MACH__
168
#   include <crt_externs.h>
169
#   define environ (*_NSGetEnviron ())
170
#  else
171
extern char **environ;
172
#  endif
173
# endif
174
#elif defined GNULIB_POSIXCHECK
175
# undef environ
176
# define environ \
177
    (GL_LINK_WARNING ("environ is unportable - " \
178
                      "use gnulib module environ for portability"), \
179
     environ)
180
#endif
181
182
994.2.8 by Monty Taylor
Updated gnulib files.
183
#if @GNULIB_EUIDACCESS@
184
# if !@HAVE_EUIDACCESS@
185
/* Like access(), except that is uses the effective user id and group id of
186
   the current process.  */
187
extern int euidaccess (const char *filename, int mode);
188
# endif
189
#elif defined GNULIB_POSIXCHECK
190
# undef euidaccess
191
# define euidaccess(f,m) \
192
    (GL_LINK_WARNING ("euidaccess is unportable - " \
193
                      "use gnulib module euidaccess for portability"), \
194
     euidaccess (f, m))
195
#endif
196
197
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
198
#if @GNULIB_FCHDIR@
199
# if @REPLACE_FCHDIR@
200
201
/* Change the process' current working directory to the directory on which
202
   the given file descriptor is open.
203
   Return 0 if successful, otherwise -1 and errno set.
204
   See the POSIX:2001 specification
205
   <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
206
extern int fchdir (int /*fd*/);
207
208
#  define dup rpl_dup
209
extern int dup (int);
210
#  define dup2 rpl_dup2
211
extern int dup2 (int, int);
212
213
# endif
214
#elif defined GNULIB_POSIXCHECK
215
# undef fchdir
216
# define fchdir(f) \
217
    (GL_LINK_WARNING ("fchdir is unportable - " \
218
                      "use gnulib module fchdir for portability"), \
219
     fchdir (f))
220
#endif
221
222
994.2.8 by Monty Taylor
Updated gnulib files.
223
#if @GNULIB_FSYNC@
224
/* Synchronize changes to a file.
225
   Return 0 if successful, otherwise -1 and errno set.
226
   See POSIX:2001 specification
227
   <http://www.opengroup.org/susv3xsh/fsync.html>.  */
228
# if !@HAVE_FSYNC@
229
extern int fsync (int fd);
230
# endif
231
#elif defined GNULIB_POSIXCHECK
232
# undef fsync
233
# define fsync(fd) \
234
    (GL_LINK_WARNING ("fsync is unportable - " \
235
                      "use gnulib module fsync for portability"), \
236
     fsync (fd))
237
#endif
238
239
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
240
#if @GNULIB_FTRUNCATE@
241
# if !@HAVE_FTRUNCATE@
242
/* Change the size of the file to which FD is opened to become equal to LENGTH.
243
   Return 0 if successful, otherwise -1 and errno set.
244
   See the POSIX:2001 specification
245
   <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
246
extern int ftruncate (int fd, off_t length);
247
# endif
248
#elif defined GNULIB_POSIXCHECK
249
# undef ftruncate
250
# define ftruncate(f,l) \
251
    (GL_LINK_WARNING ("ftruncate is unportable - " \
252
                      "use gnulib module ftruncate for portability"), \
253
     ftruncate (f, l))
254
#endif
255
256
257
#if @GNULIB_GETCWD@
258
/* Include the headers that might declare getcwd so that they will not
259
   cause confusion if included after this file.  */
260
# include <stdlib.h>
261
# if @REPLACE_GETCWD@
262
/* Get the name of the current working directory, and put it in SIZE bytes
263
   of BUF.
264
   Return BUF if successful, or NULL if the directory couldn't be determined
265
   or SIZE was too small.
266
   See the POSIX:2001 specification
267
   <http://www.opengroup.org/susv3xsh/getcwd.html>.
268
   Additionally, the gnulib module 'getcwd' guarantees the following GNU
269
   extension: If BUF is NULL, an array is allocated with 'malloc'; the array
270
   is SIZE bytes long, unless SIZE == 0, in which case it is as big as
271
   necessary.  */
272
#  define getcwd rpl_getcwd
273
extern char * getcwd (char *buf, size_t size);
274
# endif
275
#elif defined GNULIB_POSIXCHECK
276
# undef getcwd
277
# define getcwd(b,s) \
278
    (GL_LINK_WARNING ("getcwd is unportable - " \
279
                      "use gnulib module getcwd for portability"), \
280
     getcwd (b, s))
281
#endif
282
283
994.2.8 by Monty Taylor
Updated gnulib files.
284
#if @GNULIB_GETDOMAINNAME@
285
/* Return the NIS domain name of the machine.
286
   WARNING! The NIS domain name is unrelated to the fully qualified host name
287
            of the machine.  It is also unrelated to email addresses.
288
   WARNING! The NIS domain name is usually the empty string or "(none)" when
289
            not using NIS.
290
291
   Put up to LEN bytes of the NIS domain name into NAME.
292
   Null terminate it if the name is shorter than LEN.
293
   If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
294
   Return 0 if successful, otherwise set errno and return -1.  */
295
# if !@HAVE_GETDOMAINNAME@
296
extern int getdomainname(char *name, size_t len);
297
# endif
298
#elif defined GNULIB_POSIXCHECK
299
# undef getdomainname
300
# define getdomainname(n,l) \
301
    (GL_LINK_WARNING ("getdomainname is unportable - " \
302
                      "use gnulib module getdomainname for portability"), \
303
     getdomainname (n, l))
304
#endif
305
306
307
#if @GNULIB_GETDTABLESIZE@
308
# if !@HAVE_GETDTABLESIZE@
309
/* Return the maximum number of file descriptors in the current process.  */
310
extern int getdtablesize (void);
311
# endif
312
#elif defined GNULIB_POSIXCHECK
313
# undef getdtablesize
314
# define getdtablesize() \
315
    (GL_LINK_WARNING ("getdtablesize is unportable - " \
316
                      "use gnulib module getdtablesize for portability"), \
317
     getdtablesize ())
318
#endif
319
320
321
#if @GNULIB_GETHOSTNAME@
322
/* Return the standard host name of the machine.
323
   WARNING! The host name may or may not be fully qualified.
324
325
   Put up to LEN bytes of the host name into NAME.
326
   Null terminate it if the name is shorter than LEN.
327
   If the host name is longer than LEN, set errno = EINVAL and return -1.
328
   Return 0 if successful, otherwise set errno and return -1.  */
329
# if @UNISTD_H_HAVE_WINSOCK2_H@
330
#  undef gethostname
331
#  define gethostname rpl_gethostname
332
# endif
333
# if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
334
extern int gethostname(char *name, size_t len);
335
# endif
336
#elif @UNISTD_H_HAVE_WINSOCK2_H@
337
# undef gethostname
338
# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
339
#elif defined GNULIB_POSIXCHECK
340
# undef gethostname
341
# define gethostname(n,l) \
342
    (GL_LINK_WARNING ("gethostname is unportable - " \
343
                      "use gnulib module gethostname for portability"), \
344
     gethostname (n, l))
345
#endif
346
347
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
348
#if @GNULIB_GETLOGIN_R@
349
/* Copies the user's login name to NAME.
350
   The array pointed to by NAME has room for SIZE bytes.
351
352
   Returns 0 if successful.  Upon error, an error number is returned, or -1 in
353
   the case that the login name cannot be found but no specific error is
354
   provided (this case is hopefully rare but is left open by the POSIX spec).
355
356
   See <http://www.opengroup.org/susv3xsh/getlogin.html>.
357
 */
358
# if !@HAVE_DECL_GETLOGIN_R@
359
#  include <stddef.h>
360
extern int getlogin_r (char *name, size_t size);
361
# endif
362
#elif defined GNULIB_POSIXCHECK
363
# undef getlogin_r
364
# define getlogin_r(n,s) \
365
    (GL_LINK_WARNING ("getlogin_r is unportable - " \
366
                      "use gnulib module getlogin_r for portability"), \
367
     getlogin_r (n, s))
368
#endif
369
370
371
#if @GNULIB_GETPAGESIZE@
372
# if @REPLACE_GETPAGESIZE@
373
#  define getpagesize rpl_getpagesize
374
extern int getpagesize (void);
375
# elif !@HAVE_GETPAGESIZE@
376
/* This is for POSIX systems.  */
377
#  if !defined getpagesize && defined _SC_PAGESIZE
378
#   if ! (defined __VMS && __VMS_VER < 70000000)
379
#    define getpagesize() sysconf (_SC_PAGESIZE)
380
#   endif
381
#  endif
382
/* This is for older VMS.  */
383
#  if !defined getpagesize && defined __VMS
384
#   ifdef __ALPHA
385
#    define getpagesize() 8192
386
#   else
387
#    define getpagesize() 512
388
#   endif
389
#  endif
390
/* This is for BeOS.  */
391
#  if !defined getpagesize && @HAVE_OS_H@
392
#   include <OS.h>
393
#   if defined B_PAGE_SIZE
394
#    define getpagesize() B_PAGE_SIZE
395
#   endif
396
#  endif
397
/* This is for AmigaOS4.0.  */
398
#  if !defined getpagesize && defined __amigaos4__
399
#   define getpagesize() 2048
400
#  endif
401
/* This is for older Unix systems.  */
402
#  if !defined getpagesize && @HAVE_SYS_PARAM_H@
403
#   include <sys/param.h>
404
#   ifdef EXEC_PAGESIZE
405
#    define getpagesize() EXEC_PAGESIZE
406
#   else
407
#    ifdef NBPG
408
#     ifndef CLSIZE
409
#      define CLSIZE 1
410
#     endif
411
#     define getpagesize() (NBPG * CLSIZE)
412
#    else
413
#     ifdef NBPC
414
#      define getpagesize() NBPC
415
#     endif
416
#    endif
417
#   endif
418
#  endif
419
# endif
420
#elif defined GNULIB_POSIXCHECK
421
# undef getpagesize
422
# define getpagesize() \
423
    (GL_LINK_WARNING ("getpagesize is unportable - " \
424
                      "use gnulib module getpagesize for portability"), \
425
     getpagesize ())
426
#endif
427
428
994.2.8 by Monty Taylor
Updated gnulib files.
429
#if @GNULIB_GETUSERSHELL@
430
# if !@HAVE_GETUSERSHELL@
431
/* Return the next valid login shell on the system, or NULL when the end of
432
   the list has been reached.  */
433
extern char *getusershell (void);
434
/* Rewind to pointer that is advanced at each getusershell() call.  */
435
extern void setusershell (void);
436
/* Free the pointer that is advanced at each getusershell() call and
437
   associated resources.  */
438
extern void endusershell (void);
439
# endif
440
#elif defined GNULIB_POSIXCHECK
441
# undef getusershell
442
# define getusershell() \
443
    (GL_LINK_WARNING ("getusershell is unportable - " \
444
                      "use gnulib module getusershell for portability"), \
445
     getusershell ())
446
# undef setusershell
447
# define setusershell() \
448
    (GL_LINK_WARNING ("setusershell is unportable - " \
449
                      "use gnulib module getusershell for portability"), \
450
     setusershell ())
451
# undef endusershell
452
# define endusershell() \
453
    (GL_LINK_WARNING ("endusershell is unportable - " \
454
                      "use gnulib module getusershell for portability"), \
455
     endusershell ())
456
#endif
457
458
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
459
#if @GNULIB_LCHOWN@
460
# if @REPLACE_LCHOWN@
461
/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
462
   to GID (if GID is not -1).  Do not follow symbolic links.
463
   Return 0 if successful, otherwise -1 and errno set.
464
   See the POSIX:2001 specification
465
   <http://www.opengroup.org/susv3xsh/lchown.html>.  */
466
#  define lchown rpl_lchown
467
extern int lchown (char const *file, uid_t owner, gid_t group);
468
# endif
469
#elif defined GNULIB_POSIXCHECK
470
# undef lchown
471
# define lchown(f,u,g) \
472
    (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
473
                      "systems - use gnulib module lchown for portability"), \
474
     lchown (f, u, g))
475
#endif
476
477
478
#if @GNULIB_LSEEK@
479
# if @REPLACE_LSEEK@
480
/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
481
   Return the new offset if successful, otherwise -1 and errno set.
482
   See the POSIX:2001 specification
483
   <http://www.opengroup.org/susv3xsh/lseek.html>.  */
484
#  define lseek rpl_lseek
485
   extern off_t lseek (int fd, off_t offset, int whence);
486
# endif
487
#elif defined GNULIB_POSIXCHECK
488
# undef lseek
489
# define lseek(f,o,w) \
490
    (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
491
                      "systems - use gnulib module lseek for portability"), \
492
     lseek (f, o, w))
493
#endif
494
495
496
#if @GNULIB_READLINK@
497
/* Read the contents of the symbolic link FILE and place the first BUFSIZE
498
   bytes of it into BUF.  Return the number of bytes placed into BUF if
499
   successful, otherwise -1 and errno set.
500
   See the POSIX:2001 specification
501
   <http://www.opengroup.org/susv3xsh/readlink.html>.  */
502
# if !@HAVE_READLINK@
503
#  include <stddef.h>
504
extern int readlink (const char *file, char *buf, size_t bufsize);
505
# endif
506
#elif defined GNULIB_POSIXCHECK
507
# undef readlink
508
# define readlink(f,b,s) \
509
    (GL_LINK_WARNING ("readlink is unportable - " \
510
                      "use gnulib module readlink for portability"), \
511
     readlink (f, b, s))
512
#endif
513
514
515
#if @GNULIB_SLEEP@
516
/* Pause the execution of the current thread for N seconds.
517
   Returns the number of seconds left to sleep.
518
   See the POSIX:2001 specification
519
   <http://www.opengroup.org/susv3xsh/sleep.html>.  */
520
# if !@HAVE_SLEEP@
521
extern unsigned int sleep (unsigned int n);
522
# endif
523
#elif defined GNULIB_POSIXCHECK
524
# undef sleep
525
# define sleep(n) \
526
    (GL_LINK_WARNING ("sleep is unportable - " \
527
                      "use gnulib module sleep for portability"), \
528
     sleep (n))
529
#endif
530
531
994.2.8 by Monty Taylor
Updated gnulib files.
532
#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
533
/* Write up to COUNT bytes starting at BUF to file descriptor FD.
534
   See the POSIX:2001 specification
535
   <http://www.opengroup.org/susv3xsh/write.html>.  */
536
# undef write
537
# define write rpl_write
538
extern ssize_t write (int fd, const void *buf, size_t count);
539
#endif
540
541
542
#ifdef FCHDIR_REPLACEMENT
543
/* gnulib internal function.  */
544
extern void _gl_unregister_fd (int fd);
545
#endif
546
547
815.1.3 by Monty Taylor
Added getopt workaround for broken solaris getopt.
548
#ifdef __cplusplus
549
}
550
#endif
551
552
553
#endif /* _GL_UNISTD_H */
554
#endif /* _GL_UNISTD_H */