system.h revision 53469
1/* Portability cruft.  Include after config.h and sys/types.h.
2   Copyright (C) 1996, 1998 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
16   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17   02111-1307, USA.  */
18
19#undef PARAMS
20#if defined (__STDC__) && __STDC__
21# ifndef _PTR_T
22# define _PTR_T
23  typedef void * ptr_t;
24# endif
25# define PARAMS(x) x
26#else
27# ifndef _PTR_T
28# define _PTR_T
29  typedef char * ptr_t;
30# endif
31# define PARAMS(x) ()
32#endif
33
34#ifdef HAVE_UNISTD_H
35# include <fcntl.h>
36# include <unistd.h>
37#else
38# define O_RDONLY 0
39int open(), read(), close();
40#endif
41
42#include <errno.h>
43#ifndef errno
44extern int errno;
45#endif
46
47#ifndef HAVE_STRERROR
48extern int sys_nerr;
49extern char *sys_errlist[];
50# define strerror(E) (0 <= (E) && (E) < sys_nerr ? _(sys_errlist[E]) : _("Unknown system error"))
51#endif
52
53/* Some operating systems treat text and binary files differently.  */
54#if O_BINARY
55# include <io.h>
56# ifdef HAVE_SETMODE
57#  define SET_BINARY(fd)  setmode (fd, O_BINARY)
58# else
59#  define SET_BINARY(fd)  _setmode (fd, O_BINARY)
60# endif
61#else
62# ifndef O_BINARY
63#  define O_BINARY 0
64#  define SET_BINARY(fd)   (void)0
65# endif
66#endif
67
68#ifdef HAVE_DOS_FILE_NAMES
69# define IS_SLASH(c) ((c) == '/' || (c) == '\\')
70# define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0)
71#endif
72
73#ifndef IS_SLASH
74# define IS_SLASH(c) ((c) == '/')
75#endif
76
77#ifndef FILESYSTEM_PREFIX_LEN
78# define FILESYSTEM_PREFIX_LEN(f) 0
79#endif
80
81/* This assumes _WIN32, like DJGPP, has D_OK.  Does it?  In what header?  */
82#ifdef D_OK
83# ifdef EISDIR
84#  define is_EISDIR(e, f) \
85     ((e) == EISDIR \
86      || ((e) == EACCES && access (f, D_OK) == 0 && ((e) = EISDIR, 1)))
87# else
88#  define is_EISDIR(e, f) ((e) == EACCES && access (f, D_OK) == 0)
89# endif
90#endif
91
92#ifndef is_EISDIR
93# ifdef EISDIR
94#  define is_EISDIR(e, f) ((e) == EISDIR)
95# else
96#  define is_EISDIR(e, f) 0
97# endif
98#endif
99
100#if STAT_MACROS_BROKEN
101# undef S_ISDIR
102#endif
103#if !defined(S_ISDIR) && defined(S_IFDIR)
104# define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
105#endif
106
107#ifdef STDC_HEADERS
108# include <stdlib.h>
109#else
110ptr_t malloc(), realloc(), calloc();
111void free();
112#endif
113
114#if __STDC__
115# include <stddef.h>
116#endif
117#ifdef STDC_HEADERS
118# include <limits.h>
119#endif
120#ifndef CHAR_BIT
121# define CHAR_BIT 8
122#endif
123#ifndef INT_MAX
124# define INT_MAX 2147483647
125#endif
126#ifndef UCHAR_MAX
127# define UCHAR_MAX 255
128#endif
129
130#if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H)
131# include <memory.h>
132#endif
133#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
134# include <string.h>
135#else
136# include <strings.h>
137# undef strchr
138# define strchr index
139# undef strrchr
140# define strrchr rindex
141# undef memcpy
142# define memcpy(d, s, n) bcopy((s), (d), (n))
143#endif
144#ifndef HAVE_MEMCHR
145ptr_t memchr();
146#endif
147
148#include <ctype.h>
149
150#ifndef isgraph
151# define isgraph(C) (isprint(C) && !isspace(C))
152#endif
153
154#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
155# define IN_CTYPE_DOMAIN(c) 1
156#else
157# define IN_CTYPE_DOMAIN(c) isascii(c)
158#endif
159
160#define ISALPHA(C)	(IN_CTYPE_DOMAIN (C) && isalpha (C))
161#define ISUPPER(C)	(IN_CTYPE_DOMAIN (C) && isupper (C))
162#define ISLOWER(C)	(IN_CTYPE_DOMAIN (C) && islower (C))
163#define ISDIGIT(C)	(IN_CTYPE_DOMAIN (C) && isdigit (C))
164#define ISXDIGIT(C)	(IN_CTYPE_DOMAIN (C) && isxdigit (C))
165#define ISSPACE(C)	(IN_CTYPE_DOMAIN (C) && isspace (C))
166#define ISPUNCT(C)	(IN_CTYPE_DOMAIN (C) && ispunct (C))
167#define ISALNUM(C)	(IN_CTYPE_DOMAIN (C) && isalnum (C))
168#define ISPRINT(C)	(IN_CTYPE_DOMAIN (C) && isprint (C))
169#define ISGRAPH(C)	(IN_CTYPE_DOMAIN (C) && isgraph (C))
170#define ISCNTRL(C)	(IN_CTYPE_DOMAIN (C) && iscntrl (C))
171
172#define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C))
173
174#if ENABLE_NLS
175# include <libintl.h>
176# define _(String) gettext (String)
177#else
178# define _(String) String
179#endif
180#define N_(String) String
181
182#if HAVE_SETLOCALE
183# include <locale.h>
184#endif
185
186#ifndef initialize_main
187#define initialize_main(argcp, argvp)
188#endif
189