This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[inseparable changes from match from perl-5.003_97h to perl-5.003_97i]
[perl5.git] / os2 / os2ish.h
CommitLineData
4633a7c4
LW
1#include <signal.h>
2
3/* HAS_IOCTL:
4 * This symbol, if defined, indicates that the ioctl() routine is
5 * available to set I/O characteristics
6 */
7#define HAS_IOCTL /**/
8
9/* HAS_UTIME:
10 * This symbol, if defined, indicates that the routine utime() is
11 * available to update the access and modification times of files.
12 */
13#define HAS_UTIME /**/
14
15#define HAS_KILL
16#define HAS_WAIT
4ea6d94f 17#define HAS_DLERROR
18
19/* USEMYBINMODE
20 * This symbol, if defined, indicates that the program should
21 * use the routine my_binmode(FILE *fp, char iotype) to insure
22 * that a file is in "binary" mode -- that is, that no translation
23 * of bytes occurs on read or write operations.
24 */
25#undef USEMYBINMODE
26
27/* USE_STAT_RDEV:
28 * This symbol is defined if this system has a stat structure declaring
29 * st_rdev
30 */
31#define USE_STAT_RDEV /**/
32
33/* ACME_MESS:
34 * This symbol, if defined, indicates that error messages should be
35 * should be generated in a format that allows the use of the Acme
36 * GUI/editor's autofind feature.
37 */
38#undef ACME_MESS /**/
4633a7c4 39
44a8e56a 40/* ALTERNATE_SHEBANG:
41 * This symbol, if defined, contains a "magic" string which may be used
42 * as the first line of a Perl program designed to be executed directly
43 * by name, instead of the standard Unix #!. If ALTERNATE_SHEBANG
44 * begins with a character other then #, then Perl will only treat
45 * it as a command line if if finds the string "perl" in the first
46 * word; otherwise it's treated as the first line of code in the script.
47 * (IOW, Perl won't hand off to another interpreter via an alternate
48 * shebang sequence that might be legal Perl code.)
49 */
aa689395 50#define ALTERNATE_SHEBANG "extproc "
44a8e56a 51
4633a7c4
LW
52#ifndef SIGABRT
53# define SIGABRT SIGILL
54#endif
55#ifndef SIGILL
56# define SIGILL 6 /* blech */
57#endif
58#define ABORT() kill(getpid(),SIGABRT);
59
760ac839 60#define BIT_BUCKET "/dev/nul" /* Will this work? */
c07a80fd 61
4a6a15c8
IZ
62#if defined(I_SYS_UN) && !defined(TCPIPV4)
63/* It is not working without TCPIPV4 defined. */
64# undef I_SYS_UN
65#endif
66
aa689395 67void Perl_OS2_init(char **);
68
69/* XXX This code hideously puts env inside: */
365eb7b5 70
71#define PERL_SYS_INIT(argcp, argvp) STMT_START { \
eacfb5f1 72 _response(argcp, argvp); \
c0c09dfd 73 _wildcard(argcp, argvp); \
aa689395 74 Perl_OS2_init(env); } STMT_END
365eb7b5 75
76#define PERL_SYS_TERM()
77
4ea6d94f 78/* #define PERL_SYS_TERM() STMT_START { \
79 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */
80
8cc95fdb 81#define dXSUB_SYS OS2_XS_init()
eacfb5f1 82
4ea6d94f 83#ifdef PERL_IS_AOUT
4a6a15c8 84/* # define HAS_FORK */
760ac839
LW
85/* # define HIDEMYMALLOC */
86/* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
87#else /* !PERL_IS_AOUT */
88# ifndef PERL_FOR_X2P
4a6a15c8
IZ
89# ifdef EMX_BAD_SBRK
90# define USE_PERL_SBRK
91# endif
92# else
93# define PerlIO FILE
760ac839
LW
94# endif
95# define SYSTEM_ALLOC(a) sys_alloc(a)
96
97void *sys_alloc(int size);
98
99#endif /* !PERL_IS_AOUT */
4a6a15c8
IZ
100#if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
101# define PerlIO FILE
102#endif
4ea6d94f 103
c0c09dfd 104#define TMPPATH tmppath
105#define TMPPATH1 "plXXXXXX"
106extern char *tmppath;
4a6a15c8
IZ
107PerlIO *my_syspopen(char *cmd, char *mode);
108/* Cannot prototype with I32 at this point. */
109int my_syspclose(PerlIO *f);
55497cff 110FILE *my_tmpfile (void);
111char *my_tmpnam (char *);
112
113#define tmpfile my_tmpfile
114#define tmpnam my_tmpnam
3ed26a2c 115#define isatty _isterm
44a8e56a 116#define rand random
117#define srand srandom
eacfb5f1 118
4633a7c4
LW
119/*
120 * fwrite1() should be a routine with the same calling sequence as fwrite(),
121 * but which outputs all of the bytes requested as a single stream (unlike
122 * fwrite() itself, which on some systems outputs several distinct records
123 * if the number_of_items parameter is >1).
124 */
125#define fwrite1 fwrite
126
127#define my_getenv(var) getenv(var)
128
df3ef7a9
IZ
129void *emx_calloc (size_t, size_t);
130void emx_free (void *);
131void *emx_malloc (size_t);
132void *emx_realloc (void *, size_t);
133
4633a7c4
LW
134/*****************************************************************************/
135
136#include <stdlib.h> /* before the following definitions */
137#include <unistd.h> /* before the following definitions */
138
139#define chdir _chdir2
140#define getcwd _getcwd2
141
142/* This guy is needed for quick stdstd */
143
144#if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
4633a7c4
LW
145 /* Perl uses ungetc only with successful return */
146# define ungetc(c,fp) \
147 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
148 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
149#endif
150
151#define OP_BINARY O_BINARY
152
153#define OS2_STAT_HACK 1
154#if OS2_STAT_HACK
155
156#define Stat(fname,bufptr) os2_stat((fname),(bufptr))
157#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 158#define Fflush(fp) fflush(fp)
8cc95fdb 159#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4
LW
160
161#undef S_IFBLK
162#undef S_ISBLK
163#define S_IFBLK 0120000
164#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
165
166#else
167
168#define Stat(fname,bufptr) stat((fname),(bufptr))
169#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 170#define Fflush(fp) fflush(fp)
8cc95fdb 171#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4
LW
172
173#endif
365eb7b5 174
44a8e56a 175/* With SD386 it is impossible to debug register variables. */
176#if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
177# define register
178#endif
179
365eb7b5 180/* Our private OS/2 specific data. */
181
182typedef struct OS2_Perl_data {
183 unsigned long flags;
184 unsigned long phab;
185 int (*xs_init)();
4ea6d94f 186 unsigned long rc;
187 unsigned long severity;
365eb7b5 188} OS2_Perl_data_t;
189
190extern OS2_Perl_data_t OS2_Perl_data;
191
4ea6d94f 192#define Perl_hab ((HAB)OS2_Perl_data.phab)
193#define Perl_rc (OS2_Perl_data.rc)
194#define Perl_severity (OS2_Perl_data.severity)
195#define errno_isOS2 12345678
196#define OS2_Perl_flags (OS2_Perl_data.flags)
365eb7b5 197#define Perl_HAB_set_f 1
4ea6d94f 198#define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f)
199#define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f)
200#define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
365eb7b5 201#define OS2_XS_init() (*OS2_Perl_data.xs_init)()
4ea6d94f 202/* The expressions below return true on error. */
4a6a15c8 203/* INCL_DOSERRORS needed. rc should be declared outside. */
4ea6d94f 204#define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
205/* INCL_WINERRORS needed. */
206#define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
207#define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
208#define FillOSError(rc) (Perl_rc = rc, \
209 errno = errno_isOS2, \
210 Perl_severity = SEVERITY_ERROR)
211#define FillWinError (Perl_rc = WinGetLastError(Perl_hab), \
212 errno = errno_isOS2, \
213 Perl_severity = ERRORIDSEV(Perl_rc), \
214 Perl_rc = ERRORIDERROR(Perl_rc))
215#define Acquire_hab() if (!Perl_HAB_set) { \
216 Perl_hab = WinInitialize(0); \
217 if (!Perl_hab) die("WinInitialize failed"); \
218 set_Perl_HAB_f; \
219 }
220
760ac839 221#define STATIC_FILE_LENGTH 127
ff68c719 222
760ac839
LW
223#define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
224char *perllib_mangle(char *, unsigned int);
4ea6d94f 225
226char *os2error(int rc);
227
228/* ************************************************************ */
229#define Dos32QuerySysState DosQuerySysState
230#define QuerySysState(flags, pid, buf, bufsz) \
231 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz)
232
233#define QSS_PROCESS 1
df3ef7a9
IZ
234#define QSS_MODULE 4
235#define QSS_SEMAPHORES 2
4ea6d94f 236#define QSS_FILE 8 /* Buggy until fixpack18 */
237#define QSS_SHARED 16
238
239#ifdef _OS2EMX_H
240
241APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
242 ULONG _res_,PVOID buf,ULONG bufsz);
243typedef struct {
244 ULONG threadcnt;
245 ULONG proccnt;
246 ULONG modulecnt;
247} QGLOBAL, *PQGLOBAL;
248
249typedef struct {
250 ULONG rectype;
251 USHORT threadid;
252 USHORT slotid;
253 ULONG sleepid;
254 ULONG priority;
255 ULONG systime;
256 ULONG usertime;
257 UCHAR state;
258 UCHAR _reserved1_; /* padding to ULONG */
259 USHORT _reserved2_; /* padding to ULONG */
260} QTHREAD, *PQTHREAD;
261
262typedef struct {
263 USHORT sfn;
264 USHORT refcnt;
265 USHORT flags1;
266 USHORT flags2;
267 USHORT accmode1;
268 USHORT accmode2;
269 ULONG filesize;
270 USHORT volhnd;
271 USHORT attrib;
272 USHORT _reserved_;
273} QFDS, *PQFDS;
274
275typedef struct qfile {
276 ULONG rectype;
277 struct qfile *next;
278 ULONG opencnt;
279 PQFDS filedata;
280 char name[1];
281} QFILE, *PQFILE;
282
283typedef struct {
284 ULONG rectype;
285 PQTHREAD threads;
286 USHORT pid;
287 USHORT ppid;
288 ULONG type;
289 ULONG state;
290 ULONG sessid;
291 USHORT hndmod;
292 USHORT threadcnt;
293 ULONG privsem32cnt;
294 ULONG _reserved2_;
295 USHORT sem16cnt;
296 USHORT dllcnt;
297 USHORT shrmemcnt;
298 USHORT fdscnt;
299 PUSHORT sem16s;
300 PUSHORT dlls;
301 PUSHORT shrmems;
302 PUSHORT fds;
303} QPROCESS, *PQPROCESS;
304
305typedef struct sema {
306 struct sema *next;
307 USHORT refcnt;
308 UCHAR sysflags;
309 UCHAR sysproccnt;
310 ULONG _reserved1_;
311 USHORT index;
312 CHAR name[1];
313} QSEMA, *PQSEMA;
314
315typedef struct {
316 ULONG rectype;
317 ULONG _reserved1_;
318 USHORT _reserved2_;
319 USHORT syssemidx;
320 ULONG index;
321 QSEMA sema;
322} QSEMSTRUC, *PQSEMSTRUC;
323
324typedef struct {
325 USHORT pid;
326 USHORT opencnt;
327} QSEMOWNER32, *PQSEMOWNER32;
328
329typedef struct {
330 PQSEMOWNER32 own;
331 PCHAR name;
332 PVOID semrecs; /* array of associated sema's */
333 USHORT flags;
334 USHORT semreccnt;
335 USHORT waitcnt;
336 USHORT _reserved_; /* padding to ULONG */
337} QSEMSMUX32, *PQSEMSMUX32;
338
339typedef struct {
340 PQSEMOWNER32 own;
341 PCHAR name;
342 PQSEMSMUX32 mux;
343 USHORT flags;
344 USHORT postcnt;
345} QSEMEV32, *PQSEMEV32;
346
347typedef struct {
348 PQSEMOWNER32 own;
349 PCHAR name;
350 PQSEMSMUX32 mux;
351 USHORT flags;
352 USHORT refcnt;
353 USHORT thrdnum;
354 USHORT _reserved_; /* padding to ULONG */
355} QSEMMUX32, *PQSEMMUX32;
356
357typedef struct semstr32 {
358 struct semstr *next;
359 QSEMEV32 evsem;
360 QSEMMUX32 muxsem;
361 QSEMSMUX32 smuxsem;
362} QSEMSTRUC32, *PQSEMSTRUC32;
363
364typedef struct shrmem {
365 struct shrmem *next;
366 USHORT hndshr;
367 USHORT selshr;
368 USHORT refcnt;
369 CHAR name[1];
370} QSHRMEM, *PQSHRMEM;
371
372typedef struct module {
373 struct module *next;
374 USHORT hndmod;
375 USHORT type;
376 ULONG refcnt;
377 ULONG segcnt;
378 PVOID _reserved_;
379 PCHAR name;
380 USHORT modref[1];
381} QMODULE, *PQMODULE;
382
383typedef struct {
384 PQGLOBAL gbldata;
385 PQPROCESS procdata;
386 PQSEMSTRUC semadata;
387 PQSEMSTRUC32 sem32data;
388 PQSHRMEM shrmemdata;
389 PQMODULE moddata;
390 PVOID _reserved2_;
391 PQFILE filedata;
392} QTOPLEVEL, *PQTOPLEVEL;
393/* ************************************************************ */
394
395PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
396
397#endif /* _OS2EMX_H */
5ae7bdf7 398