1/* system.h: system-dependent declarations; include this first. 2 $Id: system.h,v 1.12 2004/04/26 13:56:57 karl 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. */ 35extern 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#undef getopt 64#else 65extern char *getenv (); 66#endif 67 68/* Don't use bcopy! Use memmove if source and destination may overlap, 69 memcpy otherwise. */ 70#if HAVE_STRING_H 71# if !STDC_HEADERS && HAVE_MEMORY_H 72# include <memory.h> 73# endif 74# include <string.h> 75#endif 76 77#if HAVE_STRINGS_H 78/* Always include <strings.h> if we have it. This is because that's 79 what Autoconf's AC_CHECK_DECL does. On IBM AIX 4.2, strncasecmp is 80 only declared in strings.h. */ 81# include <strings.h> 82#endif 83 84#if !HAVE_STRNCASECMP || !HAVE_STRCASECMP 85# include "strcase.h" 86#endif 87 88#if !HAVE_DECL_MEMCHR 89char *memchr (); 90#endif 91 92/* <unistd.h> defines _POSIX_VERSION, but Paul Eggert points out that is 93 only supposed to be used in user code, not other system headers. */ 94#ifdef HAVE_UNISTD_H 95#include <unistd.h> 96#endif /* HAVE_UNISTD_H */ 97 98#include <errno.h> 99#ifndef errno 100extern int errno; 101#endif 102#ifdef VMS 103#include <perror.h> 104#endif 105 106#ifndef HAVE_DECL_STRERROR 107extern char *strerror (); 108#endif 109 110#ifdef HAVE_LIMITS_H 111#include <limits.h> 112#endif 113#ifndef PATH_MAX 114#ifndef _POSIX_PATH_MAX 115# define _POSIX_PATH_MAX 255 116#endif 117#define PATH_MAX _POSIX_PATH_MAX 118#endif 119 120#ifndef HAVE_DECL_STRCASECMP 121extern int strcasecmp (); 122#endif 123 124#ifndef HAVE_DECL_STRNCASECMP 125extern int strncasecmp (); 126#endif 127 128#ifndef HAVE_DECL_STRCOLL 129extern int strcoll (); 130#endif 131 132#include <sys/stat.h> 133#if STAT_MACROS_BROKEN 134# undef S_ISDIR 135#endif 136#if !defined(S_ISDIR) && defined(S_IFDIR) 137# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 138#endif 139 140#ifdef HAVE_SYS_FILE_H 141#include <sys/file.h> 142#endif /* HAVE_SYS_FILE_H */ 143 144#ifndef O_RDONLY 145/* Since <fcntl.h> is POSIX, prefer that to <sys/fcntl.h>. 146 This also avoids some useless warnings on (at least) Linux. */ 147#ifdef HAVE_FCNTL_H 148#include <fcntl.h> 149#else /* not HAVE_FCNTL_H */ 150#ifdef HAVE_SYS_FCNTL_H 151#include <sys/fcntl.h> 152#endif /* not HAVE_SYS_FCNTL_H */ 153#endif /* not HAVE_FCNTL_H */ 154#endif /* not O_RDONLY */ 155 156/* MS-DOS and similar non-Posix systems have some peculiarities: 157 - they distinguish between binary and text files; 158 - they use both `/' and `\\' as directory separator in file names; 159 - they can have a drive letter X: prepended to a file name; 160 - they have a separate root directory on each drive; 161 - their filesystems are case-insensitive; 162 - directories in environment variables (like INFOPATH) are separated 163 by `;' rather than `:'; 164 - text files can have their lines ended either with \n or with \r\n pairs; 165 These are all parameterized here except the last, which is 166 handled by the source code as appropriate (mostly, in info/). */ 167#ifndef O_BINARY 168# ifdef _O_BINARY 169# define O_BINARY _O_BINARY 170# else 171# define O_BINARY 0 172# endif 173#endif /* O_BINARY */ 174 175/* We'd like to take advantage of _doprnt if it's around, a la error.c, 176 but then we'd have no VA_SPRINTF. */ 177#if HAVE_VPRINTF 178# if __STDC__ 179# include <stdarg.h> 180# define VA_START(args, lastarg) va_start(args, lastarg) 181# else 182# include <varargs.h> 183# define VA_START(args, lastarg) va_start(args) 184# endif 185# define VA_FPRINTF(file, fmt, ap) vfprintf (file, fmt, ap) 186# define VA_SPRINTF(str, fmt, ap) vsprintf (str, fmt, ap) 187#else /* not HAVE_VPRINTF */ 188# define VA_START(args, lastarg) 189# define va_alist a1, a2, a3, a4, a5, a6, a7, a8 190# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; 191# define va_end(args) 192#endif 193 194#if O_BINARY 195# ifdef HAVE_IO_H 196# include <io.h> 197# endif 198# ifdef __MSDOS__ 199# include <limits.h> 200# ifdef __DJGPP__ 201# define HAVE_LONG_FILENAMES(dir) (pathconf (dir, _PC_NAME_MAX) > 12) 202# define NULL_DEVICE "/dev/null" 203# define DEFAULT_INFOPATH "c:/djgpp/info;/usr/local/info;/usr/info;." 204 /* DJGPP supports /dev/null, which is okay for Unix aficionados, 205 shell scripts and Makefiles, but interactive DOS die-hards 206 would probably want to have NUL as well. */ 207# define ALSO_NULL_DEVICE "NUL" 208# else /* O_BINARY && !__DJGPP__ */ 209# define HAVE_LONG_FILENAMES(dir) (0) 210# define NULL_DEVICE "NUL" 211# endif /* O_BINARY && !__DJGPP__ */ 212# define SET_SCREEN_SIZE_HELPER terminal_prep_terminal() 213# define DEFAULT_INFO_PRINT_COMMAND ">PRN" 214# else /* O_BINARY && !__MSDOS__ */ 215# define setmode(f,m) _setmode(f,m) 216# define HAVE_LONG_FILENAMES(dir) (1) 217# define NULL_DEVICE "NUL" 218# endif /* O_BINARY && !__MSDOS__ */ 219# ifdef __CYGWIN__ 220# define DEFAULT_TMPDIR "/tmp/" 221# define PATH_SEP ":" 222# else /* O_BINARY && !__CYGWIN__ */ 223# define DEFAULT_TMPDIR "c:/" 224# define PATH_SEP ";" 225# endif /* O_BINARY && !__CYGWIN__ */ 226 /* Back to any O_BINARY system. */ 227# define FILENAME_CMP strcasecmp 228# define FILENAME_CMPN strncasecmp 229# define FOPEN_RBIN "rb" 230# define FOPEN_WBIN "wb" 231# define HAVE_DRIVE(n) ((n)[0] && (n)[1] == ':') 232# define IS_SLASH(c) ((c) == '/' || (c) == '\\') 233# define IS_ABSOLUTE(n) (IS_SLASH((n)[0]) || ((n)[0] && (n)[1] == ':')) 234# define PIPE_USE_FORK 0 235# define SET_BINARY(f) do {if (!isatty(f)) setmode(f,O_BINARY);} while(0) 236# define STRIP_DOT_EXE 1 237 238#else /* not O_BINARY, i.e., Unix */ 239# define SET_BINARY(f) (void)0 240# define FOPEN_RBIN "r" 241# define FOPEN_WBIN "w" 242# define IS_SLASH(c) ((c) == '/') 243# define HAVE_DRIVE(n) (0) 244# define IS_ABSOLUTE(n) ((n)[0] == '/') 245# define FILENAME_CMP strcmp 246# define FILENAME_CMPN strncmp 247# define HAVE_LONG_FILENAMES(dir) (1) 248# define PATH_SEP ":" 249# define STRIP_DOT_EXE 0 250# ifdef VMS 251# define DEFAULT_TMPDIR "sys$scratch:" 252# else 253# define DEFAULT_TMPDIR "/tmp/" 254# endif 255# define NULL_DEVICE "/dev/null" 256# define PIPE_USE_FORK 1 257#endif /* not O_BINARY */ 258 259/* Everything but DJGPP. */ 260#ifndef ALSO_NULL_DEVICE 261# define ALSO_NULL_DEVICE "" 262#endif 263 264#ifdef HAVE_PWD_H 265#include <pwd.h> 266#endif 267/* Some systems don't declare this function in pwd.h. */ 268struct passwd *getpwnam (const char *name); 269 270/* Our library routines not included in any system library. */ 271extern void *xmalloc (size_t), *xrealloc (void *, size_t); 272extern char *xstrdup (const char *); 273extern void xexit (int); 274 275/* For convenience. */ 276#define STREQ(s1,s2) (strcmp (s1, s2) == 0) 277#define STRCASEEQ(s1,s2) (strcasecmp (s1, s2) == 0) 278#define STRNCASEEQ(s1,s2,n) (strncasecmp (s1, s2, n) == 0) 279 280/* We don't need anything fancy. If we did need something fancy, gnulib 281 has it. */ 282#ifdef MIN 283#undef MIN 284#endif 285#define MIN(a,b) ((a) < (b) ? (a) : (b)) 286#ifdef MAX 287#undef MAX 288#endif 289#define MAX(a,b) ((a) > (b) ? (a) : (b)) 290 291#endif /* TEXINFO_SYSTEM_H */ 292