1005b489obrien/* Portability cruft.  Include after config.h and sys/types.h.
2a28ccb3ache   Copyright 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
3005b489obrien
4005b489obrien   This program is free software; you can redistribute it and/or modify
5005b489obrien   it under the terms of the GNU General Public License as published by
6005b489obrien   the Free Software Foundation; either version 2, or (at your option)
7005b489obrien   any later version.
8005b489obrien
9005b489obrien   This program is distributed in the hope that it will be useful,
10005b489obrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
11005b489obrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12005b489obrien   GNU General Public License for more details.
13005b489obrien
14005b489obrien   You should have received a copy of the GNU General Public License
15005b489obrien   along with this program; if not, write to the Free Software
16005b489obrien   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17005b489obrien   02111-1307, USA.  */
18005b489obrien
19005b489obrien#undef PARAMS
20005b489obrien#if defined (__STDC__) && __STDC__
21005b489obrien# ifndef _PTR_T
22005b489obrien# define _PTR_T
23005b489obrien  typedef void * ptr_t;
24005b489obrien# endif
25005b489obrien# define PARAMS(x) x
26005b489obrien#else
27005b489obrien# ifndef _PTR_T
28005b489obrien# define _PTR_T
29005b489obrien  typedef char * ptr_t;
30005b489obrien# endif
31005b489obrien# define PARAMS(x) ()
32005b489obrien#endif
33005b489obrien
34005b489obrien#ifdef HAVE_UNISTD_H
35005b489obrien# include <fcntl.h>
36005b489obrien# include <unistd.h>
37005b489obrien#else
38005b489obrien# define O_RDONLY 0
39d8d7d22obrien# define SEEK_SET 0
40d8d7d22obrien# define SEEK_CUR 1
41005b489obrienint open(), read(), close();
42005b489obrien#endif
43005b489obrien
44005b489obrien#include <errno.h>
45005b489obrien#ifndef errno
46005b489obrienextern int errno;
47005b489obrien#endif
48005b489obrien
49005b489obrien#ifndef HAVE_STRERROR
50005b489obrienextern int sys_nerr;
51005b489obrienextern char *sys_errlist[];
52005b489obrien# define strerror(E) (0 <= (E) && (E) < sys_nerr ? _(sys_errlist[E]) : _("Unknown system error"))
53005b489obrien#endif
54005b489obrien
55005b489obrien/* Some operating systems treat text and binary files differently.  */
56d4c6119tjr#ifdef __BEOS__
57d4c6119tjr# undef O_BINARY /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
58d4c6119tjr#endif
59d4c6119tjr#ifdef HAVE_DOS_FILE_CONTENTS
60005b489obrien# include <io.h>
61005b489obrien# ifdef HAVE_SETMODE
62005b489obrien#  define SET_BINARY(fd)  setmode (fd, O_BINARY)
63005b489obrien# else
64005b489obrien#  define SET_BINARY(fd)  _setmode (fd, O_BINARY)
65005b489obrien# endif
66005b489obrien#endif
67005b489obrien
68005b489obrien#ifdef HAVE_DOS_FILE_NAMES
69005b489obrien# define IS_SLASH(c) ((c) == '/' || (c) == '\\')
70005b489obrien# define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0)
71005b489obrien#endif
72005b489obrien
73005b489obrien#ifndef IS_SLASH
74005b489obrien# define IS_SLASH(c) ((c) == '/')
75005b489obrien#endif
76005b489obrien
77005b489obrien#ifndef FILESYSTEM_PREFIX_LEN
78005b489obrien# define FILESYSTEM_PREFIX_LEN(f) 0
79005b489obrien#endif
80005b489obrien
81d4c6119tjrint isdir PARAMS ((char const *));
82d4c6119tjr
83d4c6119tjr#ifdef HAVE_DIR_EACCES_BUG
84005b489obrien# ifdef EISDIR
85005b489obrien#  define is_EISDIR(e, f) \
86005b489obrien     ((e) == EISDIR \
87d4c6119tjr      || ((e) == EACCES && isdir (f) && ((e) = EISDIR, 1)))
88005b489obrien# else
89d4c6119tjr#  define is_EISDIR(e, f) ((e) == EACCES && isdir (f))
90005b489obrien# endif
91005b489obrien#endif
92005b489obrien
93005b489obrien#ifndef is_EISDIR
94005b489obrien# ifdef EISDIR
95005b489obrien#  define is_EISDIR(e, f) ((e) == EISDIR)
96005b489obrien# else
97005b489obrien#  define is_EISDIR(e, f) 0
98005b489obrien# endif
99005b489obrien#endif
100005b489obrien
101005b489obrien#if STAT_MACROS_BROKEN
102005b489obrien# undef S_ISDIR
103d8d7d22obrien# undef S_ISREG
104005b489obrien#endif
105005b489obrien#if !defined(S_ISDIR) && defined(S_IFDIR)
106005b489obrien# define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
107005b489obrien#endif
108d8d7d22obrien#if !defined(S_ISREG) && defined(S_IFREG)
109d8d7d22obrien# define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
110d8d7d22obrien#endif
111005b489obrien
112005b489obrien#ifdef STDC_HEADERS
113005b489obrien# include <stdlib.h>
114005b489obrien#else
115d8d7d22obrienchar *getenv ();
116005b489obrienptr_t malloc(), realloc(), calloc();
117005b489obrienvoid free();
118005b489obrien#endif
119005b489obrien
120005b489obrien#if __STDC__
121005b489obrien# include <stddef.h>
122005b489obrien#endif
123005b489obrien#ifdef STDC_HEADERS
124005b489obrien# include <limits.h>
125005b489obrien#endif
126005b489obrien#ifndef CHAR_BIT
127005b489obrien# define CHAR_BIT 8
128005b489obrien#endif
1295b9b49cru/* The extra casts work around common compiler bugs.  */
1305b9b49cru#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
1315b9b49cru#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
1325b9b49cru			      ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
1335b9b49cru			      : (t) 0))
1345b9b49cru#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
1355b9b49cru#ifndef CHAR_MAX
1365b9b49cru# define CHAR_MAX TYPE_MAXIMUM (char)
1375b9b49cru#endif
138005b489obrien#ifndef INT_MAX
1395b9b49cru# define INT_MAX TYPE_MAXIMUM (int)
140005b489obrien#endif
141005b489obrien#ifndef UCHAR_MAX
1425b9b49cru# define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
143005b489obrien#endif
144005b489obrien
145005b489obrien#if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H)
146005b489obrien# include <memory.h>
147005b489obrien#endif
148005b489obrien#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
149005b489obrien# include <string.h>
150005b489obrien#else
151005b489obrien# include <strings.h>
152005b489obrien# undef strchr
153005b489obrien# define strchr index
154005b489obrien# undef strrchr
155005b489obrien# define strrchr rindex
156005b489obrien# undef memcpy
157d8d7d22obrien# define memcpy(d, s, n) bcopy (s, d, n)
158005b489obrien#endif
159005b489obrien#ifndef HAVE_MEMCHR
160005b489obrienptr_t memchr();
161005b489obrien#endif
162d8d7d22obrien#if ! defined HAVE_MEMMOVE && ! defined memmove
163d8d7d22obrien# define memmove(d, s, n) bcopy (s, d, n)
164d8d7d22obrien#endif
165005b489obrien
166005b489obrien#include <ctype.h>
167005b489obrien
168005b489obrien#ifndef isgraph
169005b489obrien# define isgraph(C) (isprint(C) && !isspace(C))
170005b489obrien#endif
171005b489obrien
172005b489obrien#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
173005b489obrien# define IN_CTYPE_DOMAIN(c) 1
174005b489obrien#else
175005b489obrien# define IN_CTYPE_DOMAIN(c) isascii(c)
176005b489obrien#endif
177005b489obrien
178005b489obrien#define ISALPHA(C)	(IN_CTYPE_DOMAIN (C) && isalpha (C))
179005b489obrien#define ISUPPER(C)	(IN_CTYPE_DOMAIN (C) && isupper (C))
180005b489obrien#define ISLOWER(C)	(IN_CTYPE_DOMAIN (C) && islower (C))
181005b489obrien#define ISDIGIT(C)	(IN_CTYPE_DOMAIN (C) && isdigit (C))
182005b489obrien#define ISXDIGIT(C)	(IN_CTYPE_DOMAIN (C) && isxdigit (C))
183005b489obrien#define ISSPACE(C)	(IN_CTYPE_DOMAIN (C) && isspace (C))
184005b489obrien#define ISPUNCT(C)	(IN_CTYPE_DOMAIN (C) && ispunct (C))
185005b489obrien#define ISALNUM(C)	(IN_CTYPE_DOMAIN (C) && isalnum (C))
186005b489obrien#define ISPRINT(C)	(IN_CTYPE_DOMAIN (C) && isprint (C))
187005b489obrien#define ISGRAPH(C)	(IN_CTYPE_DOMAIN (C) && isgraph (C))
188005b489obrien#define ISCNTRL(C)	(IN_CTYPE_DOMAIN (C) && iscntrl (C))
189005b489obrien
190005b489obrien#define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C))
191005b489obrien
192005b489obrien#if ENABLE_NLS
193005b489obrien# include <libintl.h>
194005b489obrien# define _(String) gettext (String)
195005b489obrien#else
196005b489obrien# define _(String) String
197005b489obrien#endif
198005b489obrien#define N_(String) String
199005b489obrien
200005b489obrien#if HAVE_SETLOCALE
201005b489obrien# include <locale.h>
202005b489obrien#endif
203005b489obrien
204005b489obrien#ifndef initialize_main
205005b489obrien#define initialize_main(argcp, argvp)
206005b489obrien#endif
207