1/*	$NetBSD: system.h,v 1.2 2016/01/14 00:34:53 christos Exp $	*/
2
3/* system.h: system-dependent declarations; include this first.
4   Id: system.h,v 1.12 2004/04/26 13:56:57 karl Exp
5
6   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
7   Foundation, Inc.
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2, or (at your option)
12   any later version.
13
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software Foundation,
21   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
22
23#ifndef TEXINFO_SYSTEM_H
24#define TEXINFO_SYSTEM_H
25
26#define _GNU_SOURCE
27
28#include <config.h>
29
30#ifdef MIKTEX
31#include <gnu-miktex.h>
32#define S_ISDIR(x) ((x)&_S_IFDIR)
33#else
34/* MiKTeX defines substring() in a separate DLL, where it has its
35   own __declspec declaration.  We don't want to try to duplicate
36   this Microsoft-ism here.  */
37extern char *substring (const char *, const char *);
38#endif
39
40/* We follow the order of header inclusion from Autoconf's
41   ac_includes_default, more or less.  */
42#include <stdio.h>
43#include <sys/types.h>
44#include <ctype.h>
45
46/* All systems nowadays probably have these functions, but ... */
47#ifdef HAVE_LOCALE_H
48#include <locale.h>
49#endif
50#ifndef HAVE_SETLOCALE
51#define setlocale(category,locale) /* empty */
52#endif
53
54/* For gettext (NLS).  */
55#define const
56#include "gettext.h"
57#undef const
58
59#define _(String) gettext (String)
60#define N_(String) (String)
61
62#ifdef STDC_HEADERS
63#define getopt system_getopt
64#include <stdlib.h>
65#undef getopt
66#else
67extern char *getenv ();
68#endif
69
70/* Don't use bcopy!  Use memmove if source and destination may overlap,
71   memcpy otherwise.  */
72#if HAVE_STRING_H
73# if !STDC_HEADERS && HAVE_MEMORY_H
74#  include <memory.h>
75# endif
76# include <string.h>
77#endif
78
79#if HAVE_STRINGS_H
80/* Always include <strings.h> if we have it.  This is because that's
81   what Autoconf's AC_CHECK_DECL does.  On IBM AIX 4.2, strncasecmp is
82   only declared in strings.h.  */
83# include <strings.h>
84#endif
85
86#if !HAVE_STRNCASECMP || !HAVE_STRCASECMP
87# include "strcase.h"
88#endif
89
90#if !HAVE_DECL_MEMCHR
91char *memchr ();
92#endif
93
94/* <unistd.h> defines _POSIX_VERSION, but Paul Eggert points out that is
95   only supposed to be used in user code, not other system headers.  */
96#ifdef HAVE_UNISTD_H
97#include <unistd.h>
98#endif /* HAVE_UNISTD_H */
99
100#include <errno.h>
101#ifndef errno
102extern int errno;
103#endif
104#ifdef VMS
105#include <perror.h>
106#endif
107
108#ifndef HAVE_DECL_STRERROR
109extern char *strerror ();
110#endif
111
112#ifdef HAVE_LIMITS_H
113#include <limits.h>
114#endif
115#ifndef PATH_MAX
116#ifndef _POSIX_PATH_MAX
117# define _POSIX_PATH_MAX 255
118#endif
119#define PATH_MAX _POSIX_PATH_MAX
120#endif
121
122#ifndef HAVE_DECL_STRCASECMP
123extern int strcasecmp ();
124#endif
125
126#ifndef HAVE_DECL_STRNCASECMP
127extern int strncasecmp ();
128#endif
129
130#ifndef HAVE_DECL_STRCOLL
131extern int strcoll ();
132#endif
133
134#include <sys/stat.h>
135#if STAT_MACROS_BROKEN
136# undef S_ISDIR
137#endif
138#if !defined(S_ISDIR) && defined(S_IFDIR)
139# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
140#endif
141
142#ifdef HAVE_SYS_FILE_H
143#include <sys/file.h>
144#endif /* HAVE_SYS_FILE_H */
145
146#ifndef O_RDONLY
147/* Since <fcntl.h> is POSIX, prefer that to <sys/fcntl.h>.
148   This also avoids some useless warnings on (at least) Linux.  */
149#ifdef HAVE_FCNTL_H
150#include <fcntl.h>
151#else /* not HAVE_FCNTL_H */
152#ifdef HAVE_SYS_FCNTL_H
153#include <sys/fcntl.h>
154#endif /* not HAVE_SYS_FCNTL_H */
155#endif /* not HAVE_FCNTL_H */
156#endif /* not O_RDONLY */
157
158/* MS-DOS and similar non-Posix systems have some peculiarities:
159    - they distinguish between binary and text files;
160    - they use both `/' and `\\' as directory separator in file names;
161    - they can have a drive letter X: prepended to a file name;
162    - they have a separate root directory on each drive;
163    - their filesystems are case-insensitive;
164    - directories in environment variables (like INFOPATH) are separated
165        by `;' rather than `:';
166    - text files can have their lines ended either with \n or with \r\n pairs;
167   These are all parameterized here except the last, which is
168   handled by the source code as appropriate (mostly, in info/).  */
169#ifndef O_BINARY
170# ifdef _O_BINARY
171#  define O_BINARY _O_BINARY
172# else
173#  define O_BINARY 0
174# endif
175#endif /* O_BINARY */
176
177/* We'd like to take advantage of _doprnt if it's around, a la error.c,
178   but then we'd have no VA_SPRINTF.  */
179#if HAVE_VPRINTF
180# if __STDC__
181#  include <stdarg.h>
182#  define VA_START(args, lastarg) va_start(args, lastarg)
183# else
184#  include <varargs.h>
185#  define VA_START(args, lastarg) va_start(args)
186# endif
187# define VA_FPRINTF(file, fmt, ap) vfprintf (file, fmt, ap)
188# define VA_SPRINTF(str, fmt, ap) vsprintf (str, fmt, ap)
189#else /* not HAVE_VPRINTF */
190# define VA_START(args, lastarg)
191# define va_alist a1, a2, a3, a4, a5, a6, a7, a8
192# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
193# define va_end(args)
194#endif
195
196#if O_BINARY
197# ifdef HAVE_IO_H
198#  include <io.h>
199# endif
200# ifdef __MSDOS__
201#  include <limits.h>
202#  ifdef __DJGPP__
203#   define HAVE_LONG_FILENAMES(dir)  (pathconf (dir, _PC_NAME_MAX) > 12)
204#   define NULL_DEVICE	"/dev/null"
205#   define DEFAULT_INFOPATH "c:/djgpp/info;/usr/local/info;/usr/info;."
206    /* DJGPP supports /dev/null, which is okay for Unix aficionados,
207       shell scripts and Makefiles, but interactive DOS die-hards
208       would probably want to have NUL as well.  */
209#   define ALSO_NULL_DEVICE  "NUL"
210#  else  /* O_BINARY && !__DJGPP__ */
211#   define HAVE_LONG_FILENAMES(dir)  (0)
212#   define NULL_DEVICE	"NUL"
213#  endif /* O_BINARY && !__DJGPP__ */
214#  define SET_SCREEN_SIZE_HELPER terminal_prep_terminal()
215#  define DEFAULT_INFO_PRINT_COMMAND ">PRN"
216# else   /* O_BINARY && !__MSDOS__ */
217#  define setmode(f,m)  _setmode(f,m)
218#  define HAVE_LONG_FILENAMES(dir)   (1)
219#  define NULL_DEVICE	"NUL"
220# endif  /* O_BINARY && !__MSDOS__ */
221# ifdef __CYGWIN__
222#  define DEFAULT_TMPDIR	"/tmp/"
223#  define PATH_SEP	":"
224# else  /* O_BINARY && !__CYGWIN__ */
225#  define DEFAULT_TMPDIR	"c:/"
226#  define PATH_SEP	";"
227# endif /* O_BINARY && !__CYGWIN__ */
228  /* Back to any O_BINARY system.  */
229# define FILENAME_CMP	strcasecmp
230# define FILENAME_CMPN	strncasecmp
231# define FOPEN_RBIN	"rb"
232# define FOPEN_WBIN	"wb"
233# define HAVE_DRIVE(n)	((n)[0] && (n)[1] == ':')
234# define IS_SLASH(c)	((c) == '/' || (c) == '\\')
235# define IS_ABSOLUTE(n)	(IS_SLASH((n)[0]) || ((n)[0] && (n)[1] == ':'))
236# define PIPE_USE_FORK	0
237# define SET_BINARY(f)  do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
238# define STRIP_DOT_EXE	1
239
240#else  /* not O_BINARY, i.e., Unix */
241# define SET_BINARY(f)	(void)0
242# define FOPEN_RBIN	"r"
243# define FOPEN_WBIN	"w"
244# define IS_SLASH(c)	((c) == '/')
245# define HAVE_DRIVE(n)	(0)
246# define IS_ABSOLUTE(n)	((n)[0] == '/')
247# define FILENAME_CMP	strcmp
248# define FILENAME_CMPN	strncmp
249# define HAVE_LONG_FILENAMES(dir)   (1)
250# define PATH_SEP	":"
251# define STRIP_DOT_EXE	0
252# ifdef VMS
253#  define DEFAULT_TMPDIR "sys$scratch:"
254# else
255#  define DEFAULT_TMPDIR "/tmp/"
256# endif
257# define NULL_DEVICE	"/dev/null"
258# define PIPE_USE_FORK	1
259#endif /* not O_BINARY */
260
261/* Everything but DJGPP.  */
262#ifndef ALSO_NULL_DEVICE
263# define ALSO_NULL_DEVICE  ""
264#endif
265
266#ifdef HAVE_PWD_H
267#include <pwd.h>
268#endif
269/* Some systems don't declare this function in pwd.h. */
270struct passwd *getpwnam (const char *name);
271
272#ifdef HAVE_STDINT_H
273#include <stdint.h>
274#endif
275
276/* Our library routines not included in any system library.  */
277extern void *xmalloc (size_t), *xrealloc (void *, size_t);
278extern char *xstrdup (const char *);
279extern void xexit (int);
280
281/* For convenience.  */
282#define STREQ(s1,s2) (strcmp (s1, s2) == 0)
283#define STRCASEEQ(s1,s2) (strcasecmp (s1, s2) == 0)
284#define STRNCASEEQ(s1,s2,n) (strncasecmp (s1, s2, n) == 0)
285
286/* We don't need anything fancy.  If we did need something fancy, gnulib
287   has it.  */
288#ifdef MIN
289#undef MIN
290#endif
291#define MIN(a,b) ((a) < (b) ? (a) : (b))
292#ifdef MAX
293#undef MAX
294#endif
295#define MAX(a,b) ((a) > (b) ? (a) : (b))
296
297#endif /* TEXINFO_SYSTEM_H */
298