groff: update vendor branch to v1.20.1
[dragonfly.git] / contrib / groff / src / include / nonposix.h
CommitLineData
4d3e9548 1/* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2009
465b256c 2 Free Software Foundation, Inc.
92d0a6a6
JR
3 Written by Eli Zaretskii (eliz@is.elta.co.il)
4
5This file is part of groff.
6
7groff is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
4d3e9548
JL
9Software Foundation, either version 3 of the License, or
10(at your option) any later version.
92d0a6a6
JR
11
12groff is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
4d3e9548
JL
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>. */
92d0a6a6
JR
19
20/* This header file compartmentalize all idiosyncrasies of non-Posix
21 systems, such as MS-DOS, MS-Windows, etc. It should be loaded after
22 the system headers like stdio.h to protect against warnings and error
23 messages w.r.t. redefining macros. */
24
25#if defined _MSC_VER
26# ifndef _WIN32
27# define _WIN32
28# endif
29#endif
30
31#if defined(__MSDOS__) || defined(__EMX__) \
32 || (defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__))
33
34/* Binary I/O nuisances. */
35# include <fcntl.h>
36# include <io.h>
37# ifdef HAVE_UNISTD_H
38# include <unistd.h>
39# endif
40# ifndef STDIN_FILENO
41# define STDIN_FILENO 0
42# define STDOUT_FILENO 1
43# define STDERR_FILENO 2
44# endif
45# ifdef HAVE_DIRECT_H
46# include <direct.h>
47# endif
48# ifdef HAVE_PROCESS_H
49# include <process.h>
50# endif
51# if defined(_MSC_VER) || defined(__MINGW32__)
52# define POPEN_RT "rt"
53# define POPEN_WT "wt"
54# define popen(c,m) _popen(c,m)
55# define pclose(p) _pclose(p)
56# define pipe(pfd) _pipe((pfd),0,_O_BINARY|_O_NOINHERIT)
57# define mkdir(p,m) _mkdir(p)
58# define setmode(f,m) _setmode(f,m)
59# define WAIT(s,p,m) _cwait(s,p,m)
60# define creat(p,m) _creat(p,m)
61# define read(f,b,s) _read(f,b,s)
62# define write(f,b,s) _write(f,b,s)
63# define dup(f) _dup(f)
64# define dup2(f1,f2) _dup2(f1,f2)
65# define close(f) _close(f)
66# define isatty(f) _isatty(f)
465b256c 67# define access(p,m) _access(p,m)
92d0a6a6
JR
68# endif
69# define SET_BINARY(f) do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
70# define FOPEN_RB "rb"
71# define FOPEN_WB "wb"
72# define FOPEN_RWB "wb+"
73# ifndef O_BINARY
74# ifdef _O_BINARY
75# define O_BINARY (_O_BINARY)
76# endif
77# endif
78
79/* The system shell. Groff assumes a Unixy shell, but non-Posix
80 systems don't have standard places where it lives, and might not
81 have it installed to begin with. We want to give them some leeway. */
82# ifdef __EMX__
83# define getcwd(b,s) _getcwd2(b,s)
84# else
85# define BSHELL (system_shell_name())
86# define BSHELL_DASH_C (system_shell_dash_c())
87# define IS_BSHELL(s) (is_system_shell(s))
88# endif
89
90/* The separator for directories in PATH and other environment
91 variables. */
92# define PATH_SEP ";"
93# define PATH_SEP_CHAR ';'
94
95/* Characters that separate directories in a path name. */
96# define DIR_SEPS "/\\:"
97
98/* How to tell if the argument is an absolute file name. */
99# define IS_ABSOLUTE(f) \
100 ((f)[0] == '/' || (f)[0] == '\\' || (f)[0] && (f)[1] == ':')
101
102/* The executable extension. */
103# define EXE_EXT ".exe"
104
465b256c
JR
105/* Possible executable extensions. */
106# define PATH_EXT ".com;.exe;.bat;.cmd"
107
92d0a6a6
JR
108/* The system null device. */
109# define NULL_DEV "NUL"
110
111/* The default place to create temporary files. */
112# ifndef P_tmpdir
113# ifdef _P_tmpdir
114# define P_tmpdir _P_tmpdir
115# else
116# define P_tmpdir "c:/temp"
117# endif
118# endif
119
120/* Prototypes. */
121# ifdef __cplusplus
122 extern "C" {
123# endif
124 char * system_shell_name(void);
125 const char * system_shell_dash_c(void);
126 int is_system_shell(const char *);
127# ifdef __cplusplus
128 }
129# endif
130
131#endif
132
133#if defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__)
134/* Win32 implementations which use the Microsoft runtime library
135 * are prone to hanging when a pipe reader quits with unread data in the pipe.
136 * `gtroff' avoids this, by invoking `FLUSH_INPUT_PIPE()', defined as ... */
137# define FLUSH_INPUT_PIPE(fd) \
138 do if (!isatty(fd)) \
139 { \
140 char drain[BUFSIZ]; \
141 while (read(fd, drain, sizeof(drain)) > 0) \
142 ; \
143 } while (0)
144
145/* The Microsoft runtime library also has a broken argument passing mechanism,
146 * which may result in improper grouping of arguments passed to a child process
147 * by the `spawn()' family of functions. In `groff', only the `spawnvp()'
148 * function is affected; we work around this defect, by substituting a
149 * wrapper function in place of `spawnvp()' calls. */
150
151# ifdef __cplusplus
152 extern "C" {
153# endif
154 int spawnvp_wrapper(int, char *, char **);
155# ifdef __cplusplus
156 }
157# endif
158# ifndef SPAWN_FUNCTION_WRAPPERS
159# undef spawnvp
160# define spawnvp spawnvp_wrapper
161# undef _spawnvp
162# define _spawnvp spawnvp
163# endif /* SPAWN_FUNCTION_WRAPPERS */
164
165#else
166/* Other implementations do not suffer from Microsoft runtime bugs,
167 * but `gtroff' requires a dummy definition for FLUSH_INPUT_PIPE() */
168# define FLUSH_INPUT_PIPE(fd) do {} while(0)
169#endif
170
171/* Defaults, for Posix systems. */
172
173#ifndef SET_BINARY
174# define SET_BINARY(f) do {} while(0)
175#endif
176#ifndef FOPEN_RB
177# define FOPEN_RB "r"
178#endif
179#ifndef FOPEN_WB
180# define FOPEN_WB "w"
181#endif
182#ifndef FOPEN_RWB
183# define FOPEN_RWB "w+"
184#endif
185#ifndef POPEN_RT
186# define POPEN_RT "r"
187#endif
188#ifndef POPEN_WT
189# define POPEN_WT "w"
190#endif
191#ifndef O_BINARY
192# define O_BINARY 0
193#endif
194#ifndef BSHELL
195# define BSHELL "/bin/sh"
196#endif
197#ifndef BSHELL_DASH_C
198# define BSHELL_DASH_C "-c"
199#endif
200#ifndef IS_BSHELL
201# define IS_BSHELL(s) ((s) && strcmp(s,BSHELL) == 0)
202#endif
203#ifndef PATH_SEP
204# define PATH_SEP ":"
205# define PATH_SEP_CHAR ':'
206#endif
207#ifndef DIR_SEPS
208# define DIR_SEPS "/"
209#endif
210#ifndef IS_ABSOLUTE
211# define IS_ABSOLUTE(f) ((f)[0] == '/')
212#endif
213#ifndef EXE_EXT
214# define EXE_EXT ""
215#endif
465b256c
JR
216#ifndef PATH_EXT
217# define PATH_EXT ""
218#endif
92d0a6a6
JR
219#ifndef NULL_DEV
220# define NULL_DEV "/dev/null"
221#endif
222#ifndef GS_NAME
223# define GS_NAME "gs"
224#endif
225#ifndef WAIT
226# define WAIT(s,p,m) wait(s)
227#endif
228#ifndef _WAIT_CHILD
229# define _WAIT_CHILD 0
230#endif