(root)/
texinfo-7.1/
system.h
       1  /* system.h: system-dependent declarations; include this first.
       2  
       3     Copyright 1997-2023 Free Software Foundation, Inc.
       4  
       5     This program is free software: you can redistribute it and/or modify
       6     it under the terms of the GNU General Public License as published by
       7     the Free Software Foundation, either version 3 of the License, or
       8     (at your option) any later version.
       9  
      10     This program is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13     GNU General Public License for more details.
      14  
      15     You should have received a copy of the GNU General Public License
      16     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      17  
      18  #ifndef TEXINFO_SYSTEM_H
      19  #define TEXINFO_SYSTEM_H
      20  
      21  #define _GNU_SOURCE
      22  
      23  #include <config.h>
      24  
      25  #ifdef MIKTEX
      26  #include <gnu-miktex.h>
      27  #define S_ISDIR(x) ((x)&_S_IFDIR)
      28  #endif
      29  
      30  /* Assume ANSI C89 headers are available.  */
      31  #include <locale.h>
      32  #include <stdio.h>
      33  #include <stdlib.h>
      34  #include <string.h>
      35  #include <ctype.h>
      36  
      37  #include <stdarg.h>
      38  
      39  /* Use POSIX headers.  If they are not available, we use the substitute
      40     provided by gnulib.  */
      41  #include <getopt.h>
      42  #include <unistd.h>
      43  
      44  #include <fcntl.h>
      45  
      46  /* For gettext (NLS).  */
      47  #include "gettext.h"
      48  
      49  #define _(String) gettext (String)
      50  #define N_(String) (String)
      51  
      52  /* Additional gnulib includes.  */
      53  #include "mbchar.h"
      54  #if HAVE_MBRTOWC
      55  #include "mbiter.h"
      56  #endif
      57  #include "mbswidth.h"
      58  #include "xalloc.h"
      59  
      60  #include <errno.h>
      61  #ifndef errno
      62  extern int errno;
      63  #endif
      64  #ifdef VMS
      65  #include <perror.h>
      66  #endif
      67  
      68  #ifndef HAVE_DECL_STRERROR
      69  extern char *strerror ();
      70  #endif
      71  
      72  #include <limits.h>
      73  
      74  #ifndef PATH_MAX
      75  #ifndef _POSIX_PATH_MAX
      76  # define _POSIX_PATH_MAX 255
      77  #endif
      78  #define PATH_MAX _POSIX_PATH_MAX
      79  #endif
      80  
      81  #include <sys/stat.h>
      82  #if STAT_MACROS_BROKEN
      83  # undef S_ISDIR
      84  #endif
      85  #if !defined(S_ISDIR) && defined(S_IFDIR)
      86  # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
      87  #endif
      88  
      89  /* MS-DOS and similar non-Posix systems have some peculiarities:
      90      - they distinguish between binary and text files;
      91      - they use both `/' and `\\' as directory separator in file names;
      92      - they can have a drive letter X: prepended to a file name;
      93      - they have a separate root directory on each drive;
      94      - their filesystems are case-insensitive;
      95      - directories in environment variables (like INFOPATH) are separated
      96          by `;' rather than `:';
      97      - text files can have their lines ended either with \n or with \r\n pairs;
      98     These are all parameterized here except the last, which is
      99     handled by the source code as appropriate (mostly, in info/).  */
     100  #ifndef O_BINARY
     101  # ifdef _O_BINARY
     102  #  define O_BINARY _O_BINARY
     103  # else
     104  #  define O_BINARY 0
     105  # endif
     106  #endif /* O_BINARY */
     107  
     108  #if O_BINARY
     109  # ifdef HAVE_IO_H
     110  #  include <io.h>
     111  # endif
     112  # ifdef __MSDOS__
     113  #  include <limits.h>
     114  #  ifdef __DJGPP__
     115  #   define HAVE_LONG_FILENAMES(dir)  (pathconf (dir, _PC_NAME_MAX) > 12)
     116  #   define NULL_DEVICE	"/dev/null"
     117  #   define DEFAULT_INFOPATH "c:/djgpp/info;/usr/local/info;/usr/info;."
     118  #  else  /* O_BINARY && !__DJGPP__ */
     119  #   define HAVE_LONG_FILENAMES(dir)  (0)
     120  #   define NULL_DEVICE	"NUL"
     121  #  endif /* O_BINARY && !__DJGPP__ */
     122  #  define SET_SCREEN_SIZE_HELPER terminal_prep_terminal()
     123  #  define DEFAULT_INFO_PRINT_COMMAND ">PRN"
     124  # else   /* O_BINARY && !__MSDOS__ */
     125  #  ifndef setmode
     126  #   define setmode(f,m)  _setmode(f,m)
     127  #  endif
     128  #  define HAVE_LONG_FILENAMES(dir)   (1)
     129  #  define NULL_DEVICE	"NUL"
     130  # endif  /* O_BINARY && !__MSDOS__ */
     131  # ifdef __CYGWIN__
     132  #  define PATH_SEP	":"
     133  #  define STRIP_DOT_EXE	0
     134  #  undef NULL_DEVICE
     135  #  define NULL_DEVICE "/dev/null"
     136  #  define PIPE_USE_FORK	1
     137  # else  /* O_BINARY && !__CYGWIN__ */
     138  #  ifdef __MINGW32__
     139  #   define SET_SCREEN_SIZE_HELPER terminal_prep_terminal()
     140  extern int kill (pid_t, int);
     141  #  endif  /* _WIN32 */
     142  #  define PATH_SEP	";"
     143  #  define STRIP_DOT_EXE	1
     144  #  define PIPE_USE_FORK	0
     145  # endif /* O_BINARY && !__CYGWIN__ */
     146    /* Back to any O_BINARY system.  */
     147  # define FILENAME_CMP	mbscasecmp
     148  # define FILENAME_CMPN	mbsncasecmp
     149  # define FOPEN_RBIN	"rb"
     150  # define FOPEN_WBIN	"wb"
     151  # define HAVE_DRIVE(n)	((n)[0] && (n)[1] == ':')
     152  # define IS_SLASH(c)	((c) == '/' || (c) == '\\')
     153  # define HAS_SLASH(s)	(strchr ((s), '/') || strchr ((s), '\\'))
     154  # define IS_ABSOLUTE(n)	(IS_SLASH((n)[0]) || HAVE_DRIVE(n))
     155  # define SET_BINARY(f)  do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
     156  
     157  #else  /* not O_BINARY, i.e., Unix */
     158  # define SET_BINARY(f)	(void)0
     159  # define FOPEN_RBIN	"r"
     160  # define FOPEN_WBIN	"w"
     161  # define IS_SLASH(c)	((c) == '/')
     162  # define HAS_SLASH(s)	(strchr ((s), '/'))
     163  # define HAVE_DRIVE(n)	(0)
     164  # define IS_ABSOLUTE(n)	((n)[0] == '/')
     165  # define FILENAME_CMP	strcmp
     166  # define FILENAME_CMPN	strncmp
     167  # define HAVE_LONG_FILENAMES(dir)   (1)
     168  # define PATH_SEP	":"
     169  # define STRIP_DOT_EXE	0
     170  # define NULL_DEVICE	"/dev/null"
     171  # define PIPE_USE_FORK	1
     172  #endif /* not O_BINARY */
     173  
     174  #ifdef HAVE_PWD_H
     175  #include <pwd.h>
     176  #endif
     177  /* Some systems don't declare this function in pwd.h. */
     178  struct passwd *getpwnam (const char *name);
     179  
     180  /* For convenience.  */
     181  #define STREQ(s1,s2) (strcmp (s1, s2) == 0)
     182  #define STRCASEEQ(s1,s2) (strcasecmp (s1, s2) == 0)
     183  #define STRNCASEEQ(s1,s2,n) (strncasecmp (s1, s2, n) == 0)
     184  
     185  #ifndef TEXINFO_PRINTFLIKE
     186  # ifdef __GNUC__
     187  #  define TEXINFO_PRINTFLIKE(fmt,narg) __attribute__ ((__format__ (__printf__, fmt, narg)))
     188  # else
     189  #  define TEXINFO_PRINTFLIKE(fmt,narg)
     190  # endif
     191  #endif
     192  			     
     193  #endif /* TEXINFO_SYSTEM_H */