Home | History | Annotate | Line # | Download | only in lib
      1 /*	$NetBSD: system.h,v 1.3 2025/05/23 09:34:12 bad 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.  */
     37 extern 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
     67 extern 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
     91 char *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
    102 extern int errno;
    103 #endif
    104 #ifdef VMS
    105 #include <perror.h>
    106 #endif
    107 
    108 #ifndef HAVE_DECL_STRERROR
    109 extern 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 /*
    123  * configure never checks for the declarations of strcasecmp and strncasecmp.
    124  * Hence the HAVE_DECL_*s for them are never defined in config.
    125  * GCC 15.1 make conflicting prototypes an error.
    126  * Therefore disable the following two conditions to appease GCC 15.1.
    127  */
    128 #if 0 /* GCC 15.1 conflicting prototypes */
    129 #ifndef HAVE_DECL_STRCASECMP
    130 extern int strcasecmp ();
    131 #endif
    132 
    133 #ifndef HAVE_DECL_STRNCASECMP
    134 extern int strncasecmp ();
    135 #endif
    136 #endif /* GCC 15.1 conflicting prototypes */
    137 
    138 #ifndef HAVE_DECL_STRCOLL
    139 extern int strcoll ();
    140 #endif
    141 
    142 #include <sys/stat.h>
    143 #if STAT_MACROS_BROKEN
    144 # undef S_ISDIR
    145 #endif
    146 #if !defined(S_ISDIR) && defined(S_IFDIR)
    147 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
    148 #endif
    149 
    150 #ifdef HAVE_SYS_FILE_H
    151 #include <sys/file.h>
    152 #endif /* HAVE_SYS_FILE_H */
    153 
    154 #ifndef O_RDONLY
    155 /* Since <fcntl.h> is POSIX, prefer that to <sys/fcntl.h>.
    156    This also avoids some useless warnings on (at least) Linux.  */
    157 #ifdef HAVE_FCNTL_H
    158 #include <fcntl.h>
    159 #else /* not HAVE_FCNTL_H */
    160 #ifdef HAVE_SYS_FCNTL_H
    161 #include <sys/fcntl.h>
    162 #endif /* not HAVE_SYS_FCNTL_H */
    163 #endif /* not HAVE_FCNTL_H */
    164 #endif /* not O_RDONLY */
    165 
    166 /* MS-DOS and similar non-Posix systems have some peculiarities:
    167     - they distinguish between binary and text files;
    168     - they use both `/' and `\\' as directory separator in file names;
    169     - they can have a drive letter X: prepended to a file name;
    170     - they have a separate root directory on each drive;
    171     - their filesystems are case-insensitive;
    172     - directories in environment variables (like INFOPATH) are separated
    173         by `;' rather than `:';
    174     - text files can have their lines ended either with \n or with \r\n pairs;
    175    These are all parameterized here except the last, which is
    176    handled by the source code as appropriate (mostly, in info/).  */
    177 #ifndef O_BINARY
    178 # ifdef _O_BINARY
    179 #  define O_BINARY _O_BINARY
    180 # else
    181 #  define O_BINARY 0
    182 # endif
    183 #endif /* O_BINARY */
    184 
    185 /* We'd like to take advantage of _doprnt if it's around, a la error.c,
    186    but then we'd have no VA_SPRINTF.  */
    187 #if HAVE_VPRINTF
    188 # if __STDC__
    189 #  include <stdarg.h>
    190 #  define VA_START(args, lastarg) va_start(args, lastarg)
    191 # else
    192 #  include <varargs.h>
    193 #  define VA_START(args, lastarg) va_start(args)
    194 # endif
    195 # define VA_FPRINTF(file, fmt, ap) vfprintf (file, fmt, ap)
    196 # define VA_SPRINTF(str, fmt, ap) vsprintf (str, fmt, ap)
    197 #else /* not HAVE_VPRINTF */
    198 # define VA_START(args, lastarg)
    199 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
    200 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
    201 # define va_end(args)
    202 #endif
    203 
    204 #if O_BINARY
    205 # ifdef HAVE_IO_H
    206 #  include <io.h>
    207 # endif
    208 # ifdef __MSDOS__
    209 #  include <limits.h>
    210 #  ifdef __DJGPP__
    211 #   define HAVE_LONG_FILENAMES(dir)  (pathconf (dir, _PC_NAME_MAX) > 12)
    212 #   define NULL_DEVICE	"/dev/null"
    213 #   define DEFAULT_INFOPATH "c:/djgpp/info;/usr/local/info;/usr/info;."
    214     /* DJGPP supports /dev/null, which is okay for Unix aficionados,
    215        shell scripts and Makefiles, but interactive DOS die-hards
    216        would probably want to have NUL as well.  */
    217 #   define ALSO_NULL_DEVICE  "NUL"
    218 #  else  /* O_BINARY && !__DJGPP__ */
    219 #   define HAVE_LONG_FILENAMES(dir)  (0)
    220 #   define NULL_DEVICE	"NUL"
    221 #  endif /* O_BINARY && !__DJGPP__ */
    222 #  define SET_SCREEN_SIZE_HELPER terminal_prep_terminal()
    223 #  define DEFAULT_INFO_PRINT_COMMAND ">PRN"
    224 # else   /* O_BINARY && !__MSDOS__ */
    225 #  define setmode(f,m)  _setmode(f,m)
    226 #  define HAVE_LONG_FILENAMES(dir)   (1)
    227 #  define NULL_DEVICE	"NUL"
    228 # endif  /* O_BINARY && !__MSDOS__ */
    229 # ifdef __CYGWIN__
    230 #  define DEFAULT_TMPDIR	"/tmp/"
    231 #  define PATH_SEP	":"
    232 # else  /* O_BINARY && !__CYGWIN__ */
    233 #  define DEFAULT_TMPDIR	"c:/"
    234 #  define PATH_SEP	";"
    235 # endif /* O_BINARY && !__CYGWIN__ */
    236   /* Back to any O_BINARY system.  */
    237 # define FILENAME_CMP	strcasecmp
    238 # define FILENAME_CMPN	strncasecmp
    239 # define FOPEN_RBIN	"rb"
    240 # define FOPEN_WBIN	"wb"
    241 # define HAVE_DRIVE(n)	((n)[0] && (n)[1] == ':')
    242 # define IS_SLASH(c)	((c) == '/' || (c) == '\\')
    243 # define IS_ABSOLUTE(n)	(IS_SLASH((n)[0]) || ((n)[0] && (n)[1] == ':'))
    244 # define PIPE_USE_FORK	0
    245 # define SET_BINARY(f)  do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
    246 # define STRIP_DOT_EXE	1
    247 
    248 #else  /* not O_BINARY, i.e., Unix */
    249 # define SET_BINARY(f)	(void)0
    250 # define FOPEN_RBIN	"r"
    251 # define FOPEN_WBIN	"w"
    252 # define IS_SLASH(c)	((c) == '/')
    253 # define HAVE_DRIVE(n)	(0)
    254 # define IS_ABSOLUTE(n)	((n)[0] == '/')
    255 # define FILENAME_CMP	strcmp
    256 # define FILENAME_CMPN	strncmp
    257 # define HAVE_LONG_FILENAMES(dir)   (1)
    258 # define PATH_SEP	":"
    259 # define STRIP_DOT_EXE	0
    260 # ifdef VMS
    261 #  define DEFAULT_TMPDIR "sys$scratch:"
    262 # else
    263 #  define DEFAULT_TMPDIR "/tmp/"
    264 # endif
    265 # define NULL_DEVICE	"/dev/null"
    266 # define PIPE_USE_FORK	1
    267 #endif /* not O_BINARY */
    268 
    269 /* Everything but DJGPP.  */
    270 #ifndef ALSO_NULL_DEVICE
    271 # define ALSO_NULL_DEVICE  ""
    272 #endif
    273 
    274 #ifdef HAVE_PWD_H
    275 #include <pwd.h>
    276 #endif
    277 /* Some systems don't declare this function in pwd.h. */
    278 struct passwd *getpwnam (const char *name);
    279 
    280 #ifdef HAVE_STDINT_H
    281 #include <stdint.h>
    282 #endif
    283 
    284 /* Our library routines not included in any system library.  */
    285 extern void *xmalloc (size_t), *xrealloc (void *, size_t);
    286 extern char *xstrdup (const char *);
    287 extern void xexit (int);
    288 
    289 /* For convenience.  */
    290 #define STREQ(s1,s2) (strcmp (s1, s2) == 0)
    291 #define STRCASEEQ(s1,s2) (strcasecmp (s1, s2) == 0)
    292 #define STRNCASEEQ(s1,s2,n) (strncasecmp (s1, s2, n) == 0)
    293 
    294 /* We don't need anything fancy.  If we did need something fancy, gnulib
    295    has it.  */
    296 #ifdef MIN
    297 #undef MIN
    298 #endif
    299 #define MIN(a,b) ((a) < (b) ? (a) : (b))
    300 #ifdef MAX
    301 #undef MAX
    302 #endif
    303 #define MAX(a,b) ((a) > (b) ? (a) : (b))
    304 
    305 #endif /* TEXINFO_SYSTEM_H */
    306