system.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* system.h: system-dependent declarations; include this first.
  2. $Id$
  3. Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  4. 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2014, 2015, 2016
  5. Free Software Foundation, Inc.
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #ifndef TEXINFO_SYSTEM_H
  17. #define TEXINFO_SYSTEM_H
  18. #define _GNU_SOURCE
  19. #include <config.h>
  20. #ifdef MIKTEX
  21. #include <gnu-miktex.h>
  22. #define S_ISDIR(x) ((x)&_S_IFDIR)
  23. #endif
  24. /* Assume ANSI C89 headers are available. */
  25. #include <locale.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include <stdarg.h>
  31. /* Use POSIX headers. If they are not available, we use the substitute
  32. provided by gnulib. */
  33. #include <getopt.h>
  34. #include <unistd.h>
  35. /* For gettext (NLS). */
  36. #include "gettext.h"
  37. #define _(String) gettext (String)
  38. #define N_(String) (String)
  39. /* Additional gnulib includes. */
  40. #include "mbchar.h"
  41. #if HAVE_MBRTOWC
  42. #include "mbiter.h"
  43. #endif
  44. #include "mbswidth.h"
  45. #include "xalloc.h"
  46. #include <errno.h>
  47. #ifndef errno
  48. extern int errno;
  49. #endif
  50. #ifdef VMS
  51. #include <perror.h>
  52. #endif
  53. #ifndef HAVE_DECL_STRERROR
  54. extern char *strerror ();
  55. #endif
  56. #ifdef HAVE_LIMITS_H
  57. #include <limits.h>
  58. #endif
  59. #ifndef PATH_MAX
  60. #ifndef _POSIX_PATH_MAX
  61. # define _POSIX_PATH_MAX 255
  62. #endif
  63. #define PATH_MAX _POSIX_PATH_MAX
  64. #endif
  65. #ifndef HAVE_DECL_STRCOLL
  66. extern int strcoll ();
  67. #endif
  68. #include <sys/stat.h>
  69. #if STAT_MACROS_BROKEN
  70. # undef S_ISDIR
  71. #endif
  72. #if !defined(S_ISDIR) && defined(S_IFDIR)
  73. # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
  74. #endif
  75. #ifdef HAVE_SYS_FILE_H
  76. #include <sys/file.h>
  77. #endif /* HAVE_SYS_FILE_H */
  78. #ifndef O_RDONLY
  79. /* Since <fcntl.h> is POSIX, prefer that to <sys/fcntl.h>.
  80. This also avoids some useless warnings on (at least) Linux. */
  81. #ifdef HAVE_FCNTL_H
  82. #include <fcntl.h>
  83. #else /* not HAVE_FCNTL_H */
  84. #ifdef HAVE_SYS_FCNTL_H
  85. #include <sys/fcntl.h>
  86. #endif /* not HAVE_SYS_FCNTL_H */
  87. #endif /* not HAVE_FCNTL_H */
  88. #endif /* not O_RDONLY */
  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. #if O_BINARY
  108. # ifdef HAVE_IO_H
  109. # include <io.h>
  110. # endif
  111. # ifdef __MSDOS__
  112. # include <limits.h>
  113. # ifdef __DJGPP__
  114. # define HAVE_LONG_FILENAMES(dir) (pathconf (dir, _PC_NAME_MAX) > 12)
  115. # define NULL_DEVICE "/dev/null"
  116. # define DEFAULT_INFOPATH "c:/djgpp/info;/usr/local/info;/usr/info;."
  117. /* DJGPP supports /dev/null, which is okay for Unix aficionados,
  118. shell scripts and Makefiles, but interactive DOS die-hards
  119. would probably want to have NUL as well. */
  120. # define ALSO_NULL_DEVICE "NUL"
  121. # else /* O_BINARY && !__DJGPP__ */
  122. # define HAVE_LONG_FILENAMES(dir) (0)
  123. # define NULL_DEVICE "NUL"
  124. # endif /* O_BINARY && !__DJGPP__ */
  125. # define SET_SCREEN_SIZE_HELPER terminal_prep_terminal()
  126. # define DEFAULT_INFO_PRINT_COMMAND ">PRN"
  127. # else /* O_BINARY && !__MSDOS__ */
  128. # ifndef setmode
  129. # define setmode(f,m) _setmode(f,m)
  130. # endif
  131. # define HAVE_LONG_FILENAMES(dir) (1)
  132. # define NULL_DEVICE "NUL"
  133. # endif /* O_BINARY && !__MSDOS__ */
  134. # ifdef __CYGWIN__
  135. # define DEFAULT_TMPDIR "/tmp/"
  136. # define PATH_SEP ":"
  137. # define STRIP_DOT_EXE 0
  138. # undef NULL_DEVICE
  139. # define NULL_DEVICE "/dev/null"
  140. # define PIPE_USE_FORK 1
  141. # else /* O_BINARY && !__CYGWIN__ */
  142. # ifdef __MINGW32__
  143. # define SET_SCREEN_SIZE_HELPER terminal_prep_terminal()
  144. extern int kill (pid_t, int);
  145. # endif /* _WIN32 */
  146. # define DEFAULT_TMPDIR "c:/"
  147. # define PATH_SEP ";"
  148. # define STRIP_DOT_EXE 1
  149. # define PIPE_USE_FORK 0
  150. # endif /* O_BINARY && !__CYGWIN__ */
  151. /* Back to any O_BINARY system. */
  152. # define FILENAME_CMP mbscasecmp
  153. # define FILENAME_CMPN mbsncasecmp
  154. # define FOPEN_RBIN "rb"
  155. # define FOPEN_WBIN "wb"
  156. # define HAVE_DRIVE(n) ((n)[0] && (n)[1] == ':')
  157. # define IS_SLASH(c) ((c) == '/' || (c) == '\\')
  158. # define HAS_SLASH(s) (strchr ((s), '/') || strchr ((s), '\\'))
  159. # define IS_ABSOLUTE(n) (IS_SLASH((n)[0]) || HAVE_DRIVE(n))
  160. # define SET_BINARY(f) do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
  161. #else /* not O_BINARY, i.e., Unix */
  162. # define SET_BINARY(f) (void)0
  163. # define FOPEN_RBIN "r"
  164. # define FOPEN_WBIN "w"
  165. # define IS_SLASH(c) ((c) == '/')
  166. # define HAS_SLASH(s) (strchr ((s), '/'))
  167. # define HAVE_DRIVE(n) (0)
  168. # define IS_ABSOLUTE(n) ((n)[0] == '/')
  169. # define FILENAME_CMP strcmp
  170. # define FILENAME_CMPN strncmp
  171. # define HAVE_LONG_FILENAMES(dir) (1)
  172. # define PATH_SEP ":"
  173. # define STRIP_DOT_EXE 0
  174. # ifdef VMS
  175. # define DEFAULT_TMPDIR "sys$scratch:"
  176. # else
  177. # define DEFAULT_TMPDIR "/tmp/"
  178. # endif
  179. # define NULL_DEVICE "/dev/null"
  180. # define PIPE_USE_FORK 1
  181. #endif /* not O_BINARY */
  182. /* Everything but DJGPP. */
  183. #ifndef ALSO_NULL_DEVICE
  184. # define ALSO_NULL_DEVICE ""
  185. #endif
  186. #ifdef HAVE_PWD_H
  187. #include <pwd.h>
  188. #endif
  189. /* Some systems don't declare this function in pwd.h. */
  190. struct passwd *getpwnam (const char *name);
  191. /* Our library routines not included in any system library. */
  192. extern void xexit (int);
  193. /* For convenience. */
  194. #define STREQ(s1,s2) (strcmp (s1, s2) == 0)
  195. #define STRCASEEQ(s1,s2) (strcasecmp (s1, s2) == 0)
  196. #define STRNCASEEQ(s1,s2,n) (strncasecmp (s1, s2, n) == 0)
  197. /* We don't need anything fancy. If we did need something fancy, gnulib
  198. has it. */
  199. #ifdef MIN
  200. #undef MIN
  201. #endif
  202. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  203. #ifdef MAX
  204. #undef MAX
  205. #endif
  206. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  207. #ifndef TEXINFO_PRINTFLIKE
  208. # ifdef __GNUC__
  209. # define TEXINFO_PRINTFLIKE(fmt,narg) __attribute__ ((__format__ (__printf__, fmt, narg)))
  210. # else
  211. # define TEXINFO_PRINTFLIKE(fmt,narg)
  212. # endif
  213. #endif
  214. #endif /* TEXINFO_SYSTEM_H */