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