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