1 /*@ This header file compartmentalize all idiosyncrasies of non-Posix
2 *@ systems, such as MS-DOS, MS-Windows, etc. It should be loaded after
3 *@ the system headers like stdio.h to protect against warnings and error
4 *@ messages w.r.t. redefining macros.
6 * Copyright (c) 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
8 * Copyright (C) 2000 - 2005
9 * Free Software Foundation, Inc.
10 * Written by Eli Zaretskii (eliz@is.elta.co.il)
12 * This is free software; you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2, or (at your option) any later
17 * This is distributed in the hope that it will be useful, but WITHOUT ANY
18 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with groff; see the file COPYING. If not, write to the Free Software
24 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
37 #if defined(__MSDOS__) || defined(__EMX__) \
38 || (defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__))
40 /* Binary I/O nuisances. */
47 # define STDIN_FILENO 0
48 # define STDOUT_FILENO 1
49 # define STDERR_FILENO 2
54 # ifdef HAVE_PROCESS_H
57 # if defined(_MSC_VER) || defined(__MINGW32__)
58 # define POPEN_RT "rt"
59 # define POPEN_WT "wt"
60 # define popen(c,m) _popen(c,m)
61 # define pclose(p) _pclose(p)
62 # define pipe(pfd) _pipe((pfd),0,_O_BINARY|_O_NOINHERIT)
63 # define mkdir(p,m) _mkdir(p)
64 # define setmode(f,m) _setmode(f,m)
65 # define WAIT(s,p,m) _cwait(s,p,m)
66 # define creat(p,m) _creat(p,m)
67 # define read(f,b,s) _read(f,b,s)
68 # define write(f,b,s) _write(f,b,s)
69 # define dup(f) _dup(f)
70 # define dup2(f1,f2) _dup2(f1,f2)
71 # define close(f) _close(f)
72 # define isatty(f) _isatty(f)
73 # define access(p,m) _access(p,m)
75 # define SET_BINARY(f) do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
76 # define FOPEN_RB "rb"
77 # define FOPEN_WB "wb"
78 # define FOPEN_RWB "wb+"
81 # define O_BINARY (_O_BINARY)
85 /* The system shell. Groff assumes a Unixy shell, but non-Posix
86 systems don't have standard places where it lives, and might not
87 have it installed to begin with. We want to give them some leeway. */
89 # define getcwd(b,s) _getcwd2(b,s)
91 # define BSHELL (system_shell_name())
92 # define BSHELL_DASH_C (system_shell_dash_c())
93 # define IS_BSHELL(s) (is_system_shell(s))
96 /* The separator for directories in PATH and other environment
99 # define PATH_SEP_CHAR ';'
101 /* Characters that separate directories in a path name. */
102 # define DIR_SEPS "/\\:"
104 /* How to tell if the argument is an absolute file name. */
105 # define IS_ABSOLUTE(f) \
106 ((f)[0] == '/' || (f)[0] == '\\' || (f)[0] && (f)[1] == ':')
108 /* The executable extension. */
109 # define EXE_EXT ".exe"
111 /* Possible executable extensions. */
112 # define PATH_EXT ".com;.exe;.bat;.cmd"
114 /* The system null device. */
115 # define NULL_DEV "NUL"
117 /* The default place to create temporary files. */
120 # define P_tmpdir _P_tmpdir
122 # define P_tmpdir "c:/temp"
130 char * system_shell_name(void);
131 const char * system_shell_dash_c(void);
132 int is_system_shell(const char *);
139 #if defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__)
140 /* Win32 implementations which use the Microsoft runtime library
141 * are prone to hanging when a pipe reader quits with unread data in the pipe.
142 * `gtroff' avoids this, by invoking `FLUSH_INPUT_PIPE()', defined as ... */
143 # define FLUSH_INPUT_PIPE(fd) \
144 do if (!isatty(fd)) \
146 char drain[BUFSIZ]; \
147 while (read(fd, drain, sizeof(drain)) > 0) \
151 /* The Microsoft runtime library also has a broken argument passing mechanism,
152 * which may result in improper grouping of arguments passed to a child process
153 * by the `spawn()' family of functions. In `groff', only the `spawnvp()'
154 * function is affected; we work around this defect, by substituting a
155 * wrapper function in place of `spawnvp()' calls. */
160 int spawnvp_wrapper(int, char *, char **);
164 # ifndef SPAWN_FUNCTION_WRAPPERS
166 # define spawnvp spawnvp_wrapper
168 # define _spawnvp spawnvp
169 # endif /* SPAWN_FUNCTION_WRAPPERS */
172 /* Other implementations do not suffer from Microsoft runtime bugs,
173 * but `gtroff' requires a dummy definition for FLUSH_INPUT_PIPE() */
174 # define FLUSH_INPUT_PIPE(fd) do {} while(0)
177 /* Defaults, for Posix systems. */
180 # define SET_BINARY(f) do {} while(0)
183 # define FOPEN_RB "r"
186 # define FOPEN_WB "w"
189 # define FOPEN_RWB "w+"
192 # define POPEN_RT "r"
195 # define POPEN_WT "w"
201 # define BSHELL "/bin/sh"
203 #ifndef BSHELL_DASH_C
204 # define BSHELL_DASH_C "-c"
207 # define IS_BSHELL(s) ((s) && strcmp(s,BSHELL) == 0)
210 # define PATH_SEP ":"
211 # define PATH_SEP_CHAR ':'
214 # define DIR_SEPS "/"
217 # define IS_ABSOLUTE(f) ((f)[0] == '/')
226 # define NULL_DEV "/dev/null"
229 # define GS_NAME "gs"
232 # define WAIT(s,p,m) wait(s)
235 # define _WAIT_CHILD 0
238 #endif // _NONPOSIX_H