system.h revision 114472
150479Speter/* system.h: system-dependent declarations; include this first. 26059Samurai $Id: system.h,v 1.4 2002/10/31 13:44:06 karl Exp $ 36059Samurai 446686Sbrian Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software 546686Sbrian Foundation, Inc. 664802Sbrian 746686Sbrian This program is free software; you can redistribute it and/or modify 846686Sbrian it under the terms of the GNU General Public License as published by 947061Sbrian the Free Software Foundation; either version 2, or (at your option) 1036288Sbrian any later version. 1143313Sbrian 1243313Sbrian This program is distributed in the hope that it will be useful, 1364802Sbrian but WITHOUT ANY WARRANTY; without even the implied warranty of 1464802Sbrian MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1564802Sbrian GNU General Public License for more details. 1650438Sjkh 1740530Sbrian You should have received a copy of the GNU General Public License 1864802Sbrian along with this program; if not, write to the Free Software Foundation, 1929083Sbrian Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2036285Sbrian 2136285Sbrian#ifndef TEXINFO_SYSTEM_H 2232860Sbrian#define TEXINFO_SYSTEM_H 2332860Sbrian 2432860Sbrian#define _GNU_SOURCE 2532860Sbrian 2651526Sbrian#include <config.h> 2751526Sbrian 2851526Sbrian#ifdef MIKTEX 2951526Sbrian#include <gnu-miktex.h> 3058071Sbrian#define S_ISDIR(x) ((x)&_S_IFDIR) 3158071Sbrian#else 3258071Sbrian/* MiKTeX defines substring() in a separate DLL, where it has its 3358071Sbrian own __declspec declaration. We don't want to try to duplicate 3450264Sbrian this Microsoft-ism here. */ 3550191Sbrianextern char *substring (); 3631343Sbrian#endif 3737191Sbrian 3851075Sbrian/* <unistd.h> should be included before any preprocessor test 3937191Sbrian of _POSIX_VERSION. */ 4037191Sbrian#ifdef HAVE_UNISTD_H 4131343Sbrian#include <unistd.h> 4237191Sbrian#endif /* HAVE_UNISTD_H */ 4331343Sbrian 4465862Sbrian#include <stdio.h> 4565862Sbrian#include <sys/types.h> 4665862Sbrian#include <ctype.h> 4765862Sbrian 4865862Sbrian/* All systems nowadays probably have these functions, but ... */ 4965862Sbrian#ifdef HAVE_LOCALE_H 5065862Sbrian#include <locale.h> 5164802Sbrian#endif 5264802Sbrian#ifndef HAVE_SETLOCALE 5364802Sbrian#define setlocale(category,locale) /* empty */ 5464802Sbrian#endif 5564802Sbrian 5664802Sbrian/* For gettext (NLS). */ 5764802Sbrian#define const 5864802Sbrian#include "gettext.h" 5957841Skris#undef const 6057624Smarkm 6129840Sbrian#define _(String) gettext (String) 6229840Sbrian#define N_(String) (String) 6357451Smarkm 6457451Smarkm#ifndef HAVE_LC_MESSAGES 6529840Sbrian#define LC_MESSAGES (-1) 6629840Sbrian#endif 6743313Sbrian 6843313Sbrian#ifdef STDC_HEADERS 6943313Sbrian#define getopt system_getopt 7043313Sbrian#include <stdlib.h> 7143313Sbrian#undef getopt 7243313Sbrian#else 7343313Sbrianextern char *getenv (); 7443313Sbrian#endif 7543313Sbrian 7643313Sbrian/* Don't use bcopy! Use memmove if source and destination may overlap, 7750264Sbrian memcpy otherwise. */ 7849472Sbrian#ifdef HAVE_STRING_H 7949472Sbrian# if !STDC_HEADERS && HAVE_MEMORY_H 8049472Sbrian# include <memory.h> 8149472Sbrian# endif 8249472Sbrian# include <string.h> 8352942Sbrian#else 8452942Sbrian# include <strings.h> 8552942Sbrianchar *memchr (); 8652942Sbrian#endif 8752942Sbrian 8852942Sbrian#include <errno.h> 8952942Sbrian#ifndef errno 9052942Sbrianextern int errno; 9132589Sbrian#endif 9243313Sbrian#ifdef VMS 9332589Sbrian#include <perror.h> 9464802Sbrian#endif 9564802Sbrian 9664802Sbrian#ifndef HAVE_DECL_STRERROR 9736799Simpextern char *strerror (); 9836799Simp#endif 9932589Sbrian 10032589Sbrian#ifdef HAVE_LIMITS_H 1016059Samurai#include <limits.h> 102#endif 103#ifndef PATH_MAX 104#ifndef _POSIX_PATH_MAX 105# define _POSIX_PATH_MAX 255 106#endif 107#define PATH_MAX _POSIX_PATH_MAX 108#endif 109 110#ifndef HAVE_DECL_STRCASECMP 111extern int strcasecmp (); 112#endif 113 114#ifndef HAVE_DECL_STRNCASECMP 115extern int strncasecmp (); 116#endif 117 118#ifndef HAVE_DECL_STRCOLL 119extern int strcoll (); 120#endif 121 122#include <sys/stat.h> 123#if STAT_MACROS_BROKEN 124# undef S_ISDIR 125#endif 126#if !defined(S_ISDIR) && defined(S_IFDIR) 127# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 128#endif 129 130#ifdef HAVE_SYS_FILE_H 131#include <sys/file.h> 132#endif /* HAVE_SYS_FILE_H */ 133 134#ifndef O_RDONLY 135/* Since <fcntl.h> is POSIX, prefer that to <sys/fcntl.h>. 136 This also avoids some useless warnings on (at least) Linux. */ 137#ifdef HAVE_FCNTL_H 138#include <fcntl.h> 139#else /* not HAVE_FCNTL_H */ 140#ifdef HAVE_SYS_FCNTL_H 141#include <sys/fcntl.h> 142#endif /* not HAVE_SYS_FCNTL_H */ 143#endif /* not HAVE_FCNTL_H */ 144#endif /* not O_RDONLY */ 145 146/* MS-DOS and similar non-Posix systems have some peculiarities: 147 - they distinguish between binary and text files; 148 - they use both `/' and `\\' as directory separator in file names; 149 - they can have a drive letter X: prepended to a file name; 150 - they have a separate root directory on each drive; 151 - their filesystems are case-insensitive; 152 - directories in environment variables (like INFOPATH) are separated 153 by `;' rather than `:'; 154 - text files can have their lines ended either with \n or with \r\n pairs; 155 These are all parameterized here except the last, which is 156 handled by the source code as appropriate (mostly, in info/). */ 157#ifndef O_BINARY 158# ifdef _O_BINARY 159# define O_BINARY _O_BINARY 160# else 161# define O_BINARY 0 162# endif 163#endif /* O_BINARY */ 164 165/* We'd like to take advantage of _doprnt if it's around, a la error.c, 166 but then we'd have no VA_SPRINTF. */ 167#if HAVE_VPRINTF 168# if __STDC__ 169# include <stdarg.h> 170# define VA_START(args, lastarg) va_start(args, lastarg) 171# else 172# include <varargs.h> 173# define VA_START(args, lastarg) va_start(args) 174# endif 175# define VA_FPRINTF(file, fmt, ap) vfprintf (file, fmt, ap) 176# define VA_SPRINTF(str, fmt, ap) vsprintf (str, fmt, ap) 177#else /* not HAVE_VPRINTF */ 178# define VA_START(args, lastarg) 179# define va_alist a1, a2, a3, a4, a5, a6, a7, a8 180# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; 181# define va_end(args) 182#endif 183 184#if O_BINARY 185# ifdef HAVE_IO_H 186# include <io.h> 187# endif 188# ifdef __MSDOS__ 189# include <limits.h> 190# ifdef __DJGPP__ 191# define HAVE_LONG_FILENAMES(dir) (pathconf (dir, _PC_NAME_MAX) > 12) 192# define NULL_DEVICE "/dev/null" 193# define DEFAULT_INFOPATH "c:/djgpp/info;/usr/local/info;/usr/info;." 194# else /* !__DJGPP__ */ 195# define HAVE_LONG_FILENAMES(dir) (0) 196# define NULL_DEVICE "NUL" 197# endif /* !__DJGPP__ */ 198# define SET_SCREEN_SIZE_HELPER terminal_prep_terminal() 199# define DEFAULT_INFO_PRINT_COMMAND ">PRN" 200# else /* !__MSDOS__ */ 201# define setmode(f,m) _setmode(f,m) 202# define HAVE_LONG_FILENAMES(dir) (1) 203# define NULL_DEVICE "NUL" 204# endif /* !__MSDOS__ */ 205# define SET_BINARY(f) do {if (!isatty(f)) setmode(f,O_BINARY);} while(0) 206# define FOPEN_RBIN "rb" 207# define FOPEN_WBIN "wb" 208# define IS_SLASH(c) ((c) == '/' || (c) == '\\') 209# define HAVE_DRIVE(n) ((n)[0] && (n)[1] == ':') 210# define IS_ABSOLUTE(n) (IS_SLASH((n)[0]) || ((n)[0] && (n)[1] == ':')) 211# define FILENAME_CMP strcasecmp 212# define FILENAME_CMPN strncasecmp 213# define PATH_SEP ";" 214# define STRIP_DOT_EXE 1 215# define DEFAULT_TMPDIR "c:/" 216# define PIPE_USE_FORK 0 217#else /* not O_BINARY */ 218# define SET_BINARY(f) (void)0 219# define FOPEN_RBIN "r" 220# define FOPEN_WBIN "w" 221# define IS_SLASH(c) ((c) == '/') 222# define HAVE_DRIVE(n) (0) 223# define IS_ABSOLUTE(n) ((n)[0] == '/') 224# define FILENAME_CMP strcmp 225# define FILENAME_CMPN strncmp 226# define HAVE_LONG_FILENAMES(dir) (1) 227# define PATH_SEP ":" 228# define STRIP_DOT_EXE 0 229# ifdef VMS 230# define DEFAULT_TMPDIR "sys$scratch:" 231# else 232# define DEFAULT_TMPDIR "/tmp/" 233# endif 234# define NULL_DEVICE "/dev/null" 235# define PIPE_USE_FORK 1 236#endif /* not O_BINARY */ 237 238/* DJGPP supports /dev/null, which is okay for Unix aficionados, 239 shell scripts and Makefiles, but interactive DOS die-hards 240 would probably want to have NUL as well. */ 241#ifdef __DJGPP__ 242# define ALSO_NULL_DEVICE "NUL" 243#else 244# define ALSO_NULL_DEVICE "" 245#endif 246 247#ifdef HAVE_PWD_H 248#include <pwd.h> 249#endif 250/* Some systems don't declare this function in pwd.h. */ 251struct passwd *getpwnam (); 252 253/* Our library routines not included in any system library. */ 254extern void *xmalloc (), *xrealloc (); 255extern char *xstrdup (); 256extern void xexit (); 257 258/* For convenience. */ 259#define STREQ(s1,s2) (strcmp (s1, s2) == 0) 260 261#endif /* TEXINFO_SYSTEM_H */ 262