[inseparable changes from patch from perl5.003_22 to perl5.003_23]
[p5sagit/p5-mst-13.2.git] / os2 / os2ish.h
CommitLineData
4633a7c4 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 */
50/* #define ALTERNATE_SHEBANG "#!" / **/
51
4633a7c4 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 62#if defined(I_SYS_UN) && !defined(TCPIPV4)
63/* It is not working without TCPIPV4 defined. */
64# undef I_SYS_UN
65#endif
66
365eb7b5 67void Perl_OS2_init();
68
69#define PERL_SYS_INIT(argcp, argvp) STMT_START { \
eacfb5f1 70 _response(argcp, argvp); \
c0c09dfd 71 _wildcard(argcp, argvp); \
365eb7b5 72 Perl_OS2_init(); } STMT_END
73
74#define PERL_SYS_TERM()
75
4ea6d94f 76/* #define PERL_SYS_TERM() STMT_START { \
77 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */
78
365eb7b5 79#define dXSUB_SYS int fake = OS2_XS_init()
eacfb5f1 80
4ea6d94f 81#ifdef PERL_IS_AOUT
4a6a15c8 82/* # define HAS_FORK */
760ac839 83/* # define HIDEMYMALLOC */
84/* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
85#else /* !PERL_IS_AOUT */
86# ifndef PERL_FOR_X2P
4a6a15c8 87# ifdef EMX_BAD_SBRK
88# define USE_PERL_SBRK
89# endif
90# else
91# define PerlIO FILE
760ac839 92# endif
93# define SYSTEM_ALLOC(a) sys_alloc(a)
94
95void *sys_alloc(int size);
96
97#endif /* !PERL_IS_AOUT */
4a6a15c8 98#if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
99# define PerlIO FILE
100#endif
4ea6d94f 101
c0c09dfd 102#define TMPPATH tmppath
103#define TMPPATH1 "plXXXXXX"
104extern char *tmppath;
4a6a15c8 105PerlIO *my_syspopen(char *cmd, char *mode);
106/* Cannot prototype with I32 at this point. */
107int my_syspclose(PerlIO *f);
55497cff 108FILE *my_tmpfile (void);
109char *my_tmpnam (char *);
110
111#define tmpfile my_tmpfile
112#define tmpnam my_tmpnam
3ed26a2c 113#define isatty _isterm
44a8e56a 114#define rand random
115#define srand srandom
eacfb5f1 116
4633a7c4 117/*
118 * fwrite1() should be a routine with the same calling sequence as fwrite(),
119 * but which outputs all of the bytes requested as a single stream (unlike
120 * fwrite() itself, which on some systems outputs several distinct records
121 * if the number_of_items parameter is >1).
122 */
123#define fwrite1 fwrite
124
125#define my_getenv(var) getenv(var)
126
df3ef7a9 127void *emx_calloc (size_t, size_t);
128void emx_free (void *);
129void *emx_malloc (size_t);
130void *emx_realloc (void *, size_t);
131
4633a7c4 132/*****************************************************************************/
133
134#include <stdlib.h> /* before the following definitions */
135#include <unistd.h> /* before the following definitions */
136
137#define chdir _chdir2
138#define getcwd _getcwd2
139
140/* This guy is needed for quick stdstd */
141
142#if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
4633a7c4 143 /* Perl uses ungetc only with successful return */
144# define ungetc(c,fp) \
145 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
146 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
147#endif
148
149#define OP_BINARY O_BINARY
150
151#define OS2_STAT_HACK 1
152#if OS2_STAT_HACK
153
154#define Stat(fname,bufptr) os2_stat((fname),(bufptr))
155#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 156#define Fflush(fp) fflush(fp)
4633a7c4 157
158#undef S_IFBLK
159#undef S_ISBLK
160#define S_IFBLK 0120000
161#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
162
163#else
164
165#define Stat(fname,bufptr) stat((fname),(bufptr))
166#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 167#define Fflush(fp) fflush(fp)
4633a7c4 168
169#endif
365eb7b5 170
44a8e56a 171/* With SD386 it is impossible to debug register variables. */
172#if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
173# define register
174#endif
175
365eb7b5 176/* Our private OS/2 specific data. */
177
178typedef struct OS2_Perl_data {
179 unsigned long flags;
180 unsigned long phab;
181 int (*xs_init)();
4ea6d94f 182 unsigned long rc;
183 unsigned long severity;
365eb7b5 184} OS2_Perl_data_t;
185
186extern OS2_Perl_data_t OS2_Perl_data;
187
4ea6d94f 188#define Perl_hab ((HAB)OS2_Perl_data.phab)
189#define Perl_rc (OS2_Perl_data.rc)
190#define Perl_severity (OS2_Perl_data.severity)
191#define errno_isOS2 12345678
192#define OS2_Perl_flags (OS2_Perl_data.flags)
365eb7b5 193#define Perl_HAB_set_f 1
4ea6d94f 194#define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f)
195#define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f)
196#define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
365eb7b5 197#define OS2_XS_init() (*OS2_Perl_data.xs_init)()
4ea6d94f 198/* The expressions below return true on error. */
4a6a15c8 199/* INCL_DOSERRORS needed. rc should be declared outside. */
4ea6d94f 200#define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
201/* INCL_WINERRORS needed. */
202#define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
203#define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
204#define FillOSError(rc) (Perl_rc = rc, \
205 errno = errno_isOS2, \
206 Perl_severity = SEVERITY_ERROR)
207#define FillWinError (Perl_rc = WinGetLastError(Perl_hab), \
208 errno = errno_isOS2, \
209 Perl_severity = ERRORIDSEV(Perl_rc), \
210 Perl_rc = ERRORIDERROR(Perl_rc))
211#define Acquire_hab() if (!Perl_HAB_set) { \
212 Perl_hab = WinInitialize(0); \
213 if (!Perl_hab) die("WinInitialize failed"); \
214 set_Perl_HAB_f; \
215 }
216
760ac839 217#define STATIC_FILE_LENGTH 127
ff68c719 218
760ac839 219#define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
220char *perllib_mangle(char *, unsigned int);
4ea6d94f 221
222char *os2error(int rc);
223
224/* ************************************************************ */
225#define Dos32QuerySysState DosQuerySysState
226#define QuerySysState(flags, pid, buf, bufsz) \
227 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz)
228
229#define QSS_PROCESS 1
df3ef7a9 230#define QSS_MODULE 4
231#define QSS_SEMAPHORES 2
4ea6d94f 232#define QSS_FILE 8 /* Buggy until fixpack18 */
233#define QSS_SHARED 16
234
235#ifdef _OS2EMX_H
236
237APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
238 ULONG _res_,PVOID buf,ULONG bufsz);
239typedef struct {
240 ULONG threadcnt;
241 ULONG proccnt;
242 ULONG modulecnt;
243} QGLOBAL, *PQGLOBAL;
244
245typedef struct {
246 ULONG rectype;
247 USHORT threadid;
248 USHORT slotid;
249 ULONG sleepid;
250 ULONG priority;
251 ULONG systime;
252 ULONG usertime;
253 UCHAR state;
254 UCHAR _reserved1_; /* padding to ULONG */
255 USHORT _reserved2_; /* padding to ULONG */
256} QTHREAD, *PQTHREAD;
257
258typedef struct {
259 USHORT sfn;
260 USHORT refcnt;
261 USHORT flags1;
262 USHORT flags2;
263 USHORT accmode1;
264 USHORT accmode2;
265 ULONG filesize;
266 USHORT volhnd;
267 USHORT attrib;
268 USHORT _reserved_;
269} QFDS, *PQFDS;
270
271typedef struct qfile {
272 ULONG rectype;
273 struct qfile *next;
274 ULONG opencnt;
275 PQFDS filedata;
276 char name[1];
277} QFILE, *PQFILE;
278
279typedef struct {
280 ULONG rectype;
281 PQTHREAD threads;
282 USHORT pid;
283 USHORT ppid;
284 ULONG type;
285 ULONG state;
286 ULONG sessid;
287 USHORT hndmod;
288 USHORT threadcnt;
289 ULONG privsem32cnt;
290 ULONG _reserved2_;
291 USHORT sem16cnt;
292 USHORT dllcnt;
293 USHORT shrmemcnt;
294 USHORT fdscnt;
295 PUSHORT sem16s;
296 PUSHORT dlls;
297 PUSHORT shrmems;
298 PUSHORT fds;
299} QPROCESS, *PQPROCESS;
300
301typedef struct sema {
302 struct sema *next;
303 USHORT refcnt;
304 UCHAR sysflags;
305 UCHAR sysproccnt;
306 ULONG _reserved1_;
307 USHORT index;
308 CHAR name[1];
309} QSEMA, *PQSEMA;
310
311typedef struct {
312 ULONG rectype;
313 ULONG _reserved1_;
314 USHORT _reserved2_;
315 USHORT syssemidx;
316 ULONG index;
317 QSEMA sema;
318} QSEMSTRUC, *PQSEMSTRUC;
319
320typedef struct {
321 USHORT pid;
322 USHORT opencnt;
323} QSEMOWNER32, *PQSEMOWNER32;
324
325typedef struct {
326 PQSEMOWNER32 own;
327 PCHAR name;
328 PVOID semrecs; /* array of associated sema's */
329 USHORT flags;
330 USHORT semreccnt;
331 USHORT waitcnt;
332 USHORT _reserved_; /* padding to ULONG */
333} QSEMSMUX32, *PQSEMSMUX32;
334
335typedef struct {
336 PQSEMOWNER32 own;
337 PCHAR name;
338 PQSEMSMUX32 mux;
339 USHORT flags;
340 USHORT postcnt;
341} QSEMEV32, *PQSEMEV32;
342
343typedef struct {
344 PQSEMOWNER32 own;
345 PCHAR name;
346 PQSEMSMUX32 mux;
347 USHORT flags;
348 USHORT refcnt;
349 USHORT thrdnum;
350 USHORT _reserved_; /* padding to ULONG */
351} QSEMMUX32, *PQSEMMUX32;
352
353typedef struct semstr32 {
354 struct semstr *next;
355 QSEMEV32 evsem;
356 QSEMMUX32 muxsem;
357 QSEMSMUX32 smuxsem;
358} QSEMSTRUC32, *PQSEMSTRUC32;
359
360typedef struct shrmem {
361 struct shrmem *next;
362 USHORT hndshr;
363 USHORT selshr;
364 USHORT refcnt;
365 CHAR name[1];
366} QSHRMEM, *PQSHRMEM;
367
368typedef struct module {
369 struct module *next;
370 USHORT hndmod;
371 USHORT type;
372 ULONG refcnt;
373 ULONG segcnt;
374 PVOID _reserved_;
375 PCHAR name;
376 USHORT modref[1];
377} QMODULE, *PQMODULE;
378
379typedef struct {
380 PQGLOBAL gbldata;
381 PQPROCESS procdata;
382 PQSEMSTRUC semadata;
383 PQSEMSTRUC32 sem32data;
384 PQSHRMEM shrmemdata;
385 PQMODULE moddata;
386 PVOID _reserved2_;
387 PQFILE filedata;
388} QTOPLEVEL, *PQTOPLEVEL;
389/* ************************************************************ */
390
391PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
392
393#endif /* _OS2EMX_H */
5ae7bdf7 394