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