Chip noticed that the intended optionality of the 'IV' was
[p5sagit/p5-mst-13.2.git] / os2 / os2ish.h
CommitLineData
4633a7c4 1#include <signal.h>
2d766320 2#include <io.h>
3/* #include <sys/select.h> */
4633a7c4 4
5/* HAS_IOCTL:
6 * This symbol, if defined, indicates that the ioctl() routine is
7 * available to set I/O characteristics
8 */
9#define HAS_IOCTL /**/
10
11/* HAS_UTIME:
12 * This symbol, if defined, indicates that the routine utime() is
13 * available to update the access and modification times of files.
14 */
15#define HAS_UTIME /**/
16
17#define HAS_KILL
18#define HAS_WAIT
4ea6d94f 19#define HAS_DLERROR
367f3c24 20#define HAS_WAITPID_RUNTIME (_emx_env & 0x200)
4ea6d94f 21
f72c975a 22/* HAS_PASSWD
23 * This symbol, if defined, indicates that the getpwnam() and
24 * getpwuid() routines are available to get password entries.
25 * The getpwent() has a separate definition, HAS_GETPWENT.
26 */
27#define HAS_PASSWD
28
29/* HAS_GROUP
30 * This symbol, if defined, indicates that the getgrnam() and
31 * getgrgid() routines are available to get group entries.
32 * The getgrent() has a separate definition, HAS_GETGRENT.
33 */
34#define HAS_GROUP
35#define HAS_GETGRENT /* fake */
36#define HAS_SETGRENT /* fake */
37#define HAS_ENDGRENT /* fake */
38
4ea6d94f 39/* USEMYBINMODE
40 * This symbol, if defined, indicates that the program should
16fe6d59 41 * use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
4ea6d94f 42 * that a file is in "binary" mode -- that is, that no translation
43 * of bytes occurs on read or write operations.
44 */
45#undef USEMYBINMODE
46
61bb5906 47/* Stat_t:
48 * This symbol holds the type used to declare buffers for information
49 * returned by stat(). It's usually just struct stat. It may be necessary
50 * to include <sys/stat.h> and <sys/types.h> to get any typedef'ed
51 * information.
52 */
53#define Stat_t struct stat
54
4ea6d94f 55/* USE_STAT_RDEV:
56 * This symbol is defined if this system has a stat structure declaring
57 * st_rdev
58 */
59#define USE_STAT_RDEV /**/
60
61/* ACME_MESS:
62 * This symbol, if defined, indicates that error messages should be
63 * should be generated in a format that allows the use of the Acme
64 * GUI/editor's autofind feature.
65 */
66#undef ACME_MESS /**/
4633a7c4 67
44a8e56a 68/* ALTERNATE_SHEBANG:
69 * This symbol, if defined, contains a "magic" string which may be used
70 * as the first line of a Perl program designed to be executed directly
71 * by name, instead of the standard Unix #!. If ALTERNATE_SHEBANG
72 * begins with a character other then #, then Perl will only treat
73 * it as a command line if if finds the string "perl" in the first
74 * word; otherwise it's treated as the first line of code in the script.
75 * (IOW, Perl won't hand off to another interpreter via an alternate
76 * shebang sequence that might be legal Perl code.)
77 */
aa689395 78#define ALTERNATE_SHEBANG "extproc "
44a8e56a 79
4633a7c4 80#ifndef SIGABRT
81# define SIGABRT SIGILL
82#endif
83#ifndef SIGILL
84# define SIGILL 6 /* blech */
85#endif
7766f137 86#define ABORT() kill(PerlProc_getpid(),SIGABRT);
4633a7c4 87
760ac839 88#define BIT_BUCKET "/dev/nul" /* Will this work? */
c07a80fd 89
202975e6 90/* Apparently TCPIPV4 defines may be included even with only IAK present */
91
92#if !defined(NO_TCPIPV4) && !defined(TCPIPV4)
93# define TCPIPV4
94# define TCPIPV4_FORCED /* Just in case */
95#endif
96
4a6a15c8 97#if defined(I_SYS_UN) && !defined(TCPIPV4)
98/* It is not working without TCPIPV4 defined. */
99# undef I_SYS_UN
100#endif
dd96f567 101
23da6c43 102#define do_spawn(a) os2_do_spawn(a)
103#define do_aspawn(a,b,c) os2_do_aspawn((a),(b),(c))
4a6a15c8 104
aa689395 105void Perl_OS2_init(char **);
764df951 106void Perl_OS2_init3(char **envp, void **excH, int flags);
107void Perl_OS2_term(void **excH, int exitstatus, int flags);
aa689395 108
764df951 109/* The code without INIT3 hideously puts env inside: */
365eb7b5 110
764df951 111/* These ones should be in the same block as PERL_SYS_TERM() */
ed344e4f 112#ifdef PERL_CORE
764df951 113
114# define PERL_SYS_INIT3(argcp, argvp, envp) \
115 { void *xreg[2]; \
ed344e4f 116 _response(argcp, argvp); \
117 _wildcard(argcp, argvp); \
764df951 118 Perl_OS2_init3(*envp, xreg, 0)
119
120# define PERL_SYS_INIT(argcp, argvp) { \
121 { void *xreg[2]; \
eacfb5f1 122 _response(argcp, argvp); \
c0c09dfd 123 _wildcard(argcp, argvp); \
764df951 124 Perl_OS2_init3(NULL, xreg, 0)
125
ed344e4f 126#else /* Compiling embedded Perl or Perl extension */
764df951 127
128# define PERL_SYS_INIT3(argcp, argvp, envp) \
129 { void *xreg[2]; \
130 Perl_OS2_init3(*envp, xreg, 0)
131# define PERL_SYS_INIT(argcp, argvp) { \
132 { void *xreg[2]; \
133 Perl_OS2_init3(NULL, xreg, 0)
ed344e4f 134#endif
135
764df951 136#define FORCE_EMX_DEINIT_EXIT 1
137#define FORCE_EMX_DEINIT_CRT_TERM 2
138#define FORCE_EMX_DEINIT_RUN_ATEXIT 4
139
140#define PERL_SYS_TERM2(xreg,flags) \
141 Perl_OS2_term(xreg, 0, flags); \
142 MALLOC_TERM
143
144#define PERL_SYS_TERM1(xreg) \
145 Perl_OS2_term(xreg, 0, FORCE_EMX_DEINIT_RUN_ATEXIT)
146
147/* This one should come in pair with PERL_SYS_INIT() and in the same block */
148#define PERL_SYS_TERM() \
149 PERL_SYS_TERM1(xreg); \
150 }
151
ed344e4f 152#ifndef __EMX__
aab1f907 153# define PERL_CALLCONV _System
154#endif
ed344e4f 155
4ea6d94f 156/* #define PERL_SYS_TERM() STMT_START { \
157 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */
158
8cc95fdb 159#define dXSUB_SYS OS2_XS_init()
eacfb5f1 160
4ea6d94f 161#ifdef PERL_IS_AOUT
4a6a15c8 162/* # define HAS_FORK */
760ac839 163/* # define HIDEMYMALLOC */
164/* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
165#else /* !PERL_IS_AOUT */
166# ifndef PERL_FOR_X2P
4a6a15c8 167# ifdef EMX_BAD_SBRK
168# define USE_PERL_SBRK
169# endif
170# else
171# define PerlIO FILE
760ac839 172# endif
173# define SYSTEM_ALLOC(a) sys_alloc(a)
174
175void *sys_alloc(int size);
176
177#endif /* !PERL_IS_AOUT */
4a6a15c8 178#if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
179# define PerlIO FILE
180#endif
4ea6d94f 181
23da6c43 182/* os2ish is used from a2p/a2p.h without pTHX/pTHX_ first being
183 * defined. Hack around this to get us to compile.
184*/
185#ifdef PTHX_UNUSED
186# ifndef pTHX
187# define pTHX
188# endif
189# ifndef pTHX_
190# define pTHX_
191# endif
192#endif
193
c0c09dfd 194#define TMPPATH1 "plXXXXXX"
195extern char *tmppath;
23da6c43 196PerlIO *my_syspopen(pTHX_ char *cmd, char *mode);
4a6a15c8 197/* Cannot prototype with I32 at this point. */
198int my_syspclose(PerlIO *f);
55497cff 199FILE *my_tmpfile (void);
200char *my_tmpnam (char *);
5ba48348 201int my_mkdir (__const__ char *, long);
202int my_rmdir (__const__ char *);
f72c975a 203struct passwd *my_getpwent (void);
204void my_setpwent (void);
205void my_endpwent (void);
a64c954a 206char *gcvt_os2(double value, int digits, char *buffer);
f72c975a 207
208struct group *getgrent (void);
209void setgrent (void);
210void endgrent (void);
211
212struct passwd *my_getpwuid (uid_t);
213struct passwd *my_getpwnam (__const__ char *);
55497cff 214
bddf7535 215#undef L_tmpnam
216#define L_tmpnam MAXPATHLEN
217
55497cff 218#define tmpfile my_tmpfile
219#define tmpnam my_tmpnam
3ed26a2c 220#define isatty _isterm
44a8e56a 221#define rand random
222#define srand srandom
e75931a7 223#define strtoll _strtoll
224#define strtoull _strtoull
eacfb5f1 225
4633a7c4 226/*
227 * fwrite1() should be a routine with the same calling sequence as fwrite(),
228 * but which outputs all of the bytes requested as a single stream (unlike
229 * fwrite() itself, which on some systems outputs several distinct records
230 * if the number_of_items parameter is >1).
231 */
232#define fwrite1 fwrite
233
234#define my_getenv(var) getenv(var)
367f3c24 235#define flock my_flock
5ba48348 236#define rmdir my_rmdir
237#define mkdir my_mkdir
f72c975a 238#define setpwent my_setpwent
239#define getpwent my_getpwent
240#define endpwent my_endpwent
241#define getpwuid my_getpwuid
242#define getpwnam my_getpwnam
4633a7c4 243
df3ef7a9 244void *emx_calloc (size_t, size_t);
245void emx_free (void *);
246void *emx_malloc (size_t);
247void *emx_realloc (void *, size_t);
248
4633a7c4 249/*****************************************************************************/
250
251#include <stdlib.h> /* before the following definitions */
252#include <unistd.h> /* before the following definitions */
21cdd7e3 253#include <fcntl.h>
254#include <sys/stat.h>
4633a7c4 255
256#define chdir _chdir2
257#define getcwd _getcwd2
258
259/* This guy is needed for quick stdstd */
260
261#if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
4633a7c4 262 /* Perl uses ungetc only with successful return */
263# define ungetc(c,fp) \
264 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
265 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
266#endif
267
23b84778 268#define PERLIO_IS_BINMODE_FD(fd) _PERLIO_IS_BINMODE_FD(fd)
269
9c75282f 270#ifdef __GNUG__
271# define HAS_BOOL
272#endif
273#ifndef HAS_BOOL
274# define bool char
275# define HAS_BOOL 1
276#endif
277
ab8d95c9 278#include <emx/io.h> /* for _fd_flags() prototype */
377cf4e9 279
23b84778 280static inline bool
281_PERLIO_IS_BINMODE_FD(int fd)
282{
283 int *pflags = _fd_flags(fd);
284
285 return pflags && (*pflags) & O_BINARY;
286}
287
46e87256 288/* ctermid is missing from emx0.9d */
289char *ctermid(char *s);
290
4633a7c4 291#define OP_BINARY O_BINARY
292
293#define OS2_STAT_HACK 1
294#if OS2_STAT_HACK
295
296#define Stat(fname,bufptr) os2_stat((fname),(bufptr))
297#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 298#define Fflush(fp) fflush(fp)
8cc95fdb 299#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4 300
301#undef S_IFBLK
302#undef S_ISBLK
303#define S_IFBLK 0120000
304#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
305
306#else
307
308#define Stat(fname,bufptr) stat((fname),(bufptr))
309#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 310#define Fflush(fp) fflush(fp)
8cc95fdb 311#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4 312
313#endif
365eb7b5 314
44a8e56a 315/* With SD386 it is impossible to debug register variables. */
316#if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
317# define register
318#endif
319
365eb7b5 320/* Our private OS/2 specific data. */
321
322typedef struct OS2_Perl_data {
323 unsigned long flags;
324 unsigned long phab;
325 int (*xs_init)();
4ea6d94f 326 unsigned long rc;
327 unsigned long severity;
4bfbfac5 328 unsigned long phmq; /* Handle to message queue */
329 unsigned long phmq_refcnt;
330 unsigned long phmq_servers;
331 unsigned long initial_mode; /* VIO etc. mode we were started in */
365eb7b5 332} OS2_Perl_data_t;
333
334extern OS2_Perl_data_t OS2_Perl_data;
335
4ea6d94f 336#define Perl_hab ((HAB)OS2_Perl_data.phab)
337#define Perl_rc (OS2_Perl_data.rc)
338#define Perl_severity (OS2_Perl_data.severity)
339#define errno_isOS2 12345678
ed344e4f 340#define errno_isOS2_set 12345679
4ea6d94f 341#define OS2_Perl_flags (OS2_Perl_data.flags)
365eb7b5 342#define Perl_HAB_set_f 1
4ea6d94f 343#define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f)
344#define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f)
345#define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
4bfbfac5 346#define _obtain_Perl_HAB (init_PMWIN_entries(), \
347 Perl_hab = (*PMWIN_entries.Initialize)(0), \
348 set_Perl_HAB_f, Perl_hab)
349#define perl_hab_GET() (Perl_HAB_set ? Perl_hab : _obtain_Perl_HAB)
350#define Acquire_hab() perl_hab_GET()
351#define Perl_hmq ((HMQ)OS2_Perl_data.phmq)
352#define Perl_hmq_refcnt (OS2_Perl_data.phmq_refcnt)
353#define Perl_hmq_servers (OS2_Perl_data.phmq_servers)
354#define Perl_os2_initial_mode (OS2_Perl_data.initial_mode)
355
356unsigned long Perl_hab_GET();
357unsigned long Perl_Register_MQ(int serve);
358void Perl_Deregister_MQ(int serve);
359int Perl_Serve_Messages(int force);
360/* Cannot prototype with I32 at this point. */
361int Perl_Process_Messages(int force, long *cntp);
23da6c43 362char *os2_execname(pTHX);
4bfbfac5 363
364struct _QMSG;
365struct PMWIN_entries_t {
366 unsigned long (*Initialize)( unsigned long fsOptions );
367 unsigned long (*CreateMsgQueue)(unsigned long hab, long cmsg);
368 int (*DestroyMsgQueue)(unsigned long hmq);
369 int (*PeekMsg)(unsigned long hab, struct _QMSG *pqmsg,
370 unsigned long hwndFilter, unsigned long msgFilterFirst,
371 unsigned long msgFilterLast, unsigned long fl);
372 int (*GetMsg)(unsigned long hab, struct _QMSG *pqmsg,
373 unsigned long hwndFilter, unsigned long msgFilterFirst,
374 unsigned long msgFilterLast);
375 void * (*DispatchMsg)(unsigned long hab, struct _QMSG *pqmsg);
5ba48348 376 unsigned long (*GetLastError)(unsigned long hab);
377 unsigned long (*CancelShutdown)(unsigned long hmq, unsigned long fCancelAlways);
4bfbfac5 378};
379extern struct PMWIN_entries_t PMWIN_entries;
380void init_PMWIN_entries(void);
381
ed344e4f 382#define perl_hmq_GET(serve) Perl_Register_MQ(serve)
383#define perl_hmq_UNSET(serve) Perl_Deregister_MQ(serve)
4bfbfac5 384
23da6c43 385#define OS2_XS_init() (*OS2_Perl_data.xs_init)(aTHX)
ed344e4f 386
387#if _EMX_CRT_REV_ >= 60
388# define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2_set, \
389 _setsyserrno(rc))
390#else
391# define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2)
392#endif
393
4ea6d94f 394/* The expressions below return true on error. */
4a6a15c8 395/* INCL_DOSERRORS needed. rc should be declared outside. */
4ea6d94f 396#define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
397/* INCL_WINERRORS needed. */
4ea6d94f 398#define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
30500b05 399
400/* This form propagates the return value, setting $^E if needed */
401#define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
402
403/* This form propagates the return value, dieing with $^E if needed */
404#define SaveCroakWinError(expr,die,name1,name2) \
405 ((expr) ? : (CroakWinError(die,name1 name2), 0))
406
ed344e4f 407#define FillOSError(rc) (os2_setsyserrno(rc), \
4ea6d94f 408 Perl_severity = SEVERITY_ERROR)
5ba48348 409
30500b05 410#define WinError_2_Perl_rc \
411 ( init_PMWIN_entries(), \
412 Perl_rc=(*PMWIN_entries.GetLastError)(perl_hab_GET()) )
413
414/* Calling WinGetLastError() resets the error code of the current thread.
415 Since for some Win* API return value 0 is normal, one needs to call
416 this before calling them to distinguish normal and anomalous returns. */
417/*#define ResetWinError() WinError_2_Perl_rc */
418
5ba48348 419/* At this moment init_PMWIN_entries() should be a nop (WinInitialize should
420 be called already, right?), so we do not risk stepping over our own error */
30500b05 421#define FillWinError ( WinError_2_Perl_rc, \
5ba48348 422 Perl_severity = ERRORIDSEV(Perl_rc), \
423 Perl_rc = ERRORIDERROR(Perl_rc), \
424 os2_setsyserrno(Perl_rc))
4ea6d94f 425
760ac839 426#define STATIC_FILE_LENGTH 127
ff68c719 427
35bc1fdc 428 /* This should match loadOrdinals[] array in os2.c */
429enum entries_ordinals {
430 ORD_DosQueryExtLibpath,
431 ORD_DosSetExtLibpath,
432 ORD_DosVerifyPidTid,
433 ORD_SETHOSTENT,
434 ORD_SETNETENT,
435 ORD_SETPROTOENT,
436 ORD_SETSERVENT,
437 ORD_GETHOSTENT,
438 ORD_GETNETENT,
439 ORD_GETPROTOENT,
440 ORD_GETSERVENT,
441 ORD_ENDHOSTENT,
442 ORD_ENDNETENT,
443 ORD_ENDPROTOENT,
444 ORD_ENDSERVENT,
445 ORD_WinInitialize,
446 ORD_WinCreateMsgQueue,
447 ORD_WinDestroyMsgQueue,
448 ORD_WinPeekMsg,
449 ORD_WinGetMsg,
450 ORD_WinDispatchMsg,
451 ORD_WinGetLastError,
452 ORD_WinCancelShutdown,
453 ORD_RexxStart,
454 ORD_RexxVariablePool,
455 ORD_RexxRegisterFunctionExe,
456 ORD_RexxDeregisterFunction,
457 ORD_DOSSMSETTITLE,
458 ORD_PRF32QUERYPROFILESIZE,
459 ORD_PRF32OPENPROFILE,
460 ORD_PRF32CLOSEPROFILE,
461 ORD_PRF32QUERYPROFILE,
462 ORD_PRF32RESET,
463 ORD_PRF32QUERYPROFILEDATA,
464 ORD_PRF32WRITEPROFILEDATA,
465
466 ORD_WinChangeSwitchEntry,
467 ORD_WinQuerySwitchEntry,
468 ORD_WinQuerySwitchHandle,
469 ORD_WinQuerySwitchList,
470 ORD_WinSwitchToProgram,
471 ORD_WinBeginEnumWindows,
472 ORD_WinEndEnumWindows,
473 ORD_WinEnumDlgItem,
474 ORD_WinGetNextWindow,
475 ORD_WinIsChild,
476 ORD_WinQueryActiveWindow,
477 ORD_WinQueryClassName,
478 ORD_WinQueryFocus,
479 ORD_WinQueryWindow,
480 ORD_WinQueryWindowPos,
481 ORD_WinQueryWindowProcess,
482 ORD_WinQueryWindowText,
483 ORD_WinQueryWindowTextLength,
484 ORD_WinSetFocus,
485 ORD_WinSetWindowPos,
486 ORD_WinSetWindowText,
487 ORD_WinShowWindow,
488 ORD_WinIsWindow,
489 ORD_WinWindowFromId,
490 ORD_WinWindowFromPoint,
491 ORD_WinPostMsg,
30500b05 492 ORD_WinEnableWindow,
493 ORD_WinEnableWindowUpdate,
494 ORD_WinIsWindowEnabled,
495 ORD_WinIsWindowShowing,
496 ORD_WinIsWindowVisible,
497 ORD_WinQueryWindowPtr,
498 ORD_WinQueryWindowULong,
499 ORD_WinQueryWindowUShort,
500 ORD_WinSetWindowBits,
501 ORD_WinSetWindowPtr,
502 ORD_WinSetWindowULong,
503 ORD_WinSetWindowUShort,
504 ORD_WinQueryDesktopWindow,
505 ORD_WinSetActiveWindow,
506 ORD_DosQueryModFromEIP,
35bc1fdc 507 ORD_NENTRIES
508};
509
510/* RET: return type, AT: argument signature in (), ARGS: should be in () */
511#define CallORD(ret,o,at,args) (((ret (*)at) loadByOrdinal(o, 1))args)
512#define DeclFuncByORD(ret,name,o,at,args) \
513 ret name at { return CallORD(ret,o,at,args); }
514#define DeclVoidFuncByORD(name,o,at,args) \
515 void name at { CallORD(void,o,at,args); }
516
517/* These functions return false on error, and save the error info in $^E */
518#define DeclOSFuncByORD(ret,name,o,at,args) \
519 ret name at { unsigned long rc; return !CheckOSError(CallORD(ret,o,at,args)); }
520#define DeclWinFuncByORD(ret,name,o,at,args) \
521 ret name at { return SaveWinError(CallORD(ret,o,at,args)); }
522
523#define AssignFuncPByORD(p,o) (*(Perl_PFN*)&(p) = (loadByOrdinal(o, 1)))
524
30500b05 525/* This flavor caches the procedure pointer (named as p__Win#name) locally */
526#define DeclWinFuncByORD_CACHE(ret,name,o,at,args) \
527 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,1)
528
529/* This flavor may reset the last error before the call (if ret=0 may be OK) */
530#define DeclWinFuncByORD_CACHE_resetError(ret,name,o,at,args) \
531 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,1)
532
533/* Two flavors below do the same as above, but do not auto-croak */
534/* This flavor caches the procedure pointer (named as p__Win#name) locally */
535#define DeclWinFuncByORD_CACHE_survive(ret,name,o,at,args) \
536 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,0)
537
538/* This flavor may reset the last error before the call (if ret=0 may be OK) */
539#define DeclWinFuncByORD_CACHE_resetError_survive(ret,name,o,at,args) \
540 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,0)
541
542#define DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,r,die) \
543 static ret (*CAT2(p__Win,name)) at; \
544 static ret name at { \
545 if (!CAT2(p__Win,name)) \
546 AssignFuncPByORD(CAT2(p__Win,name), o); \
547 if (r) ResetWinError(); \
548 return SaveCroakWinError(CAT2(p__Win,name) args, die, "[Win]", STRINGIFY(name)); }
549
550/* These flavors additionally assume ORD is name with prepended ORD_Win */
551#define DeclWinFunc_CACHE(ret,name,at,args) \
552 DeclWinFuncByORD_CACHE(ret,name,CAT2(ORD_Win,name),at,args)
553#define DeclWinFunc_CACHE_resetError(ret,name,at,args) \
554 DeclWinFuncByORD_CACHE_resetError(ret,name,CAT2(ORD_Win,name),at,args)
555#define DeclWinFunc_CACHE_survive(ret,name,at,args) \
556 DeclWinFuncByORD_CACHE_survive(ret,name,CAT2(ORD_Win,name),at,args)
557#define DeclWinFunc_CACHE_resetError_survive(ret,name,at,args) \
558 DeclWinFuncByORD_CACHE_resetError_survive(ret,name,CAT2(ORD_Win,name),at,args)
559
560void ResetWinError(void);
561void CroakWinError(int die, char *name);
562
760ac839 563#define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
564char *perllib_mangle(char *, unsigned int);
4ea6d94f 565
35bc1fdc 566typedef int (*Perl_PFN)();
567Perl_PFN loadByOrdinal(enum entries_ordinals ord, int fail);
568extern const Perl_PFN * const pExtFCN;
4ea6d94f 569char *os2error(int rc);
2d766320 570int os2_stat(const char *name, struct stat *st);
571int setpriority(int which, int pid, int val);
572int getpriority(int which /* ignored */, int pid);
573
574#ifdef PERL_CORE
575int os2_do_spawn(pTHX_ char *cmd);
576int os2_do_aspawn(pTHX_ SV *really, void **vmark, void **vsp);
577#endif
4ea6d94f 578
ee964dfe 579#ifndef LOG_DAEMON
580
581/* Replacement for syslog.h */
582# define LOG_EMERG 0 /* system is unusable */
583# define LOG_ALERT 1 /* action must be taken immediately */
584# define LOG_CRIT 2 /* critical conditions */
585# define LOG_ERR 3 /* error conditions */
586# define LOG_WARNING 4 /* warning conditions */
587# define LOG_NOTICE 5 /* normal but significant condition */
588# define LOG_INFO 6 /* informational */
589# define LOG_DEBUG 7 /* debug-level messages */
590
591# define LOG_PRIMASK 0x007 /* mask to extract priority part (internal) */
592 /* extract priority */
593# define LOG_PRI(p) ((p) & LOG_PRIMASK)
594# define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
595
596/* facility codes */
597# define LOG_KERN (0<<3) /* kernel messages */
598# define LOG_USER (1<<3) /* random user-level messages */
599# define LOG_MAIL (2<<3) /* mail system */
600# define LOG_DAEMON (3<<3) /* system daemons */
601# define LOG_AUTH (4<<3) /* security/authorization messages */
602# define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */
603# define LOG_LPR (6<<3) /* line printer subsystem */
604# define LOG_NEWS (7<<3) /* network news subsystem */
605# define LOG_UUCP (8<<3) /* UUCP subsystem */
606# define LOG_CRON (15<<3) /* clock daemon */
607 /* other codes through 15 reserved for system use */
608# define LOG_LOCAL0 (16<<3) /* reserved for local use */
609# define LOG_LOCAL1 (17<<3) /* reserved for local use */
610# define LOG_LOCAL2 (18<<3) /* reserved for local use */
611# define LOG_LOCAL3 (19<<3) /* reserved for local use */
612# define LOG_LOCAL4 (20<<3) /* reserved for local use */
613# define LOG_LOCAL5 (21<<3) /* reserved for local use */
614# define LOG_LOCAL6 (22<<3) /* reserved for local use */
615# define LOG_LOCAL7 (23<<3) /* reserved for local use */
616
617# define LOG_NFACILITIES 24 /* current number of facilities */
618# define LOG_FACMASK 0x03f8 /* mask to extract facility part */
619 /* facility of pri */
620# define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
621
622/*
623 * arguments to setlogmask.
624 */
625# define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
626# define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
627
628/*
629 * Option flags for openlog.
630 *
631 * LOG_ODELAY no longer does anything.
632 * LOG_NDELAY is the inverse of what it used to be.
633 */
634# define LOG_PID 0x01 /* log the pid with each message */
635# define LOG_CONS 0x02 /* log on the console if errors in sending */
636# define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
637# define LOG_NDELAY 0x08 /* don't delay open */
638# define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
639# define LOG_PERROR 0x20 /* log to stderr as well */
640
641#endif
642
4ea6d94f 643/* ************************************************************ */
644#define Dos32QuerySysState DosQuerySysState
645#define QuerySysState(flags, pid, buf, bufsz) \
646 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz)
647
648#define QSS_PROCESS 1
df3ef7a9 649#define QSS_MODULE 4
650#define QSS_SEMAPHORES 2
4ea6d94f 651#define QSS_FILE 8 /* Buggy until fixpack18 */
652#define QSS_SHARED 16
653
ed344e4f 654#ifdef _OS2_H
4ea6d94f 655
656APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
657 ULONG _res_,PVOID buf,ULONG bufsz);
658typedef struct {
659 ULONG threadcnt;
660 ULONG proccnt;
661 ULONG modulecnt;
662} QGLOBAL, *PQGLOBAL;
663
664typedef struct {
665 ULONG rectype;
666 USHORT threadid;
667 USHORT slotid;
668 ULONG sleepid;
669 ULONG priority;
670 ULONG systime;
671 ULONG usertime;
672 UCHAR state;
673 UCHAR _reserved1_; /* padding to ULONG */
674 USHORT _reserved2_; /* padding to ULONG */
675} QTHREAD, *PQTHREAD;
676
677typedef struct {
678 USHORT sfn;
679 USHORT refcnt;
680 USHORT flags1;
681 USHORT flags2;
682 USHORT accmode1;
683 USHORT accmode2;
684 ULONG filesize;
685 USHORT volhnd;
686 USHORT attrib;
687 USHORT _reserved_;
688} QFDS, *PQFDS;
689
690typedef struct qfile {
691 ULONG rectype;
692 struct qfile *next;
693 ULONG opencnt;
694 PQFDS filedata;
695 char name[1];
696} QFILE, *PQFILE;
697
698typedef struct {
699 ULONG rectype;
700 PQTHREAD threads;
701 USHORT pid;
702 USHORT ppid;
703 ULONG type;
704 ULONG state;
705 ULONG sessid;
706 USHORT hndmod;
707 USHORT threadcnt;
708 ULONG privsem32cnt;
709 ULONG _reserved2_;
710 USHORT sem16cnt;
711 USHORT dllcnt;
712 USHORT shrmemcnt;
713 USHORT fdscnt;
714 PUSHORT sem16s;
715 PUSHORT dlls;
716 PUSHORT shrmems;
717 PUSHORT fds;
718} QPROCESS, *PQPROCESS;
719
720typedef struct sema {
721 struct sema *next;
722 USHORT refcnt;
723 UCHAR sysflags;
724 UCHAR sysproccnt;
725 ULONG _reserved1_;
726 USHORT index;
727 CHAR name[1];
728} QSEMA, *PQSEMA;
729
730typedef struct {
731 ULONG rectype;
732 ULONG _reserved1_;
733 USHORT _reserved2_;
734 USHORT syssemidx;
735 ULONG index;
736 QSEMA sema;
737} QSEMSTRUC, *PQSEMSTRUC;
738
739typedef struct {
740 USHORT pid;
741 USHORT opencnt;
742} QSEMOWNER32, *PQSEMOWNER32;
743
744typedef struct {
745 PQSEMOWNER32 own;
746 PCHAR name;
747 PVOID semrecs; /* array of associated sema's */
748 USHORT flags;
749 USHORT semreccnt;
750 USHORT waitcnt;
751 USHORT _reserved_; /* padding to ULONG */
752} QSEMSMUX32, *PQSEMSMUX32;
753
754typedef struct {
755 PQSEMOWNER32 own;
756 PCHAR name;
757 PQSEMSMUX32 mux;
758 USHORT flags;
759 USHORT postcnt;
760} QSEMEV32, *PQSEMEV32;
761
762typedef struct {
763 PQSEMOWNER32 own;
764 PCHAR name;
765 PQSEMSMUX32 mux;
766 USHORT flags;
767 USHORT refcnt;
768 USHORT thrdnum;
769 USHORT _reserved_; /* padding to ULONG */
770} QSEMMUX32, *PQSEMMUX32;
771
772typedef struct semstr32 {
773 struct semstr *next;
774 QSEMEV32 evsem;
775 QSEMMUX32 muxsem;
776 QSEMSMUX32 smuxsem;
777} QSEMSTRUC32, *PQSEMSTRUC32;
778
779typedef struct shrmem {
780 struct shrmem *next;
781 USHORT hndshr;
782 USHORT selshr;
783 USHORT refcnt;
784 CHAR name[1];
785} QSHRMEM, *PQSHRMEM;
786
787typedef struct module {
788 struct module *next;
789 USHORT hndmod;
790 USHORT type;
791 ULONG refcnt;
792 ULONG segcnt;
793 PVOID _reserved_;
794 PCHAR name;
795 USHORT modref[1];
796} QMODULE, *PQMODULE;
797
798typedef struct {
799 PQGLOBAL gbldata;
800 PQPROCESS procdata;
801 PQSEMSTRUC semadata;
802 PQSEMSTRUC32 sem32data;
803 PQSHRMEM shrmemdata;
804 PQMODULE moddata;
805 PVOID _reserved2_;
806 PQFILE filedata;
807} QTOPLEVEL, *PQTOPLEVEL;
808/* ************************************************************ */
809
810PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
811
ed344e4f 812#endif /* _OS2_H */
5ae7bdf7 813