fix File::Spec->abs2rel() to return absolute $path more often for VMS
[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
5c728af0 102#ifdef USE_ITHREADS
103
104#define do_spawn(a) os2_do_spawn(aTHX_ (a))
105#define do_aspawn(a,b,c) os2_do_aspawn(aTHX_ (a),(b),(c))
106
107#define OS2_ERROR_ALREADY_POSTED 299 /* Avoid os2.h */
108
109extern int rc;
110
111#define MUTEX_INIT(m) \
112 STMT_START { \
113 int rc; \
114 if ((rc = _rmutex_create(m,0))) \
115 Perl_croak_nocontext("panic: MUTEX_INIT: rc=%i", rc); \
116 } STMT_END
117#define MUTEX_LOCK(m) \
118 STMT_START { \
119 int rc; \
120 if ((rc = _rmutex_request(m,_FMR_IGNINT))) \
121 Perl_croak_nocontext("panic: MUTEX_LOCK: rc=%i", rc); \
122 } STMT_END
123#define MUTEX_UNLOCK(m) \
124 STMT_START { \
125 int rc; \
126 if ((rc = _rmutex_release(m))) \
127 Perl_croak_nocontext("panic: MUTEX_UNLOCK: rc=%i", rc); \
128 } STMT_END
129#define MUTEX_DESTROY(m) \
130 STMT_START { \
131 int rc; \
132 if ((rc = _rmutex_close(m))) \
133 Perl_croak_nocontext("panic: MUTEX_DESTROY: rc=%i", rc); \
134 } STMT_END
135
136#define COND_INIT(c) \
137 STMT_START { \
138 int rc; \
139 if ((rc = DosCreateEventSem(NULL,c,0,0))) \
140 Perl_croak_nocontext("panic: COND_INIT: rc=%i", rc); \
141 } STMT_END
142#define COND_SIGNAL(c) \
143 STMT_START { \
144 int rc; \
145 if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
146 Perl_croak_nocontext("panic: COND_SIGNAL, rc=%ld", rc); \
147 } STMT_END
148#define COND_BROADCAST(c) \
149 STMT_START { \
150 int rc; \
151 if ((rc = DosPostEventSem(*(c))) && rc != OS2_ERROR_ALREADY_POSTED)\
152 Perl_croak_nocontext("panic: COND_BROADCAST, rc=%i", rc); \
153 } STMT_END
154/* #define COND_WAIT(c, m) \
155 STMT_START { \
156 if (WaitForSingleObject(*(c),INFINITE) == WAIT_FAILED) \
157 Perl_croak_nocontext("panic: COND_WAIT"); \
158 } STMT_END
159*/
160#define COND_WAIT(c, m) os2_cond_wait(c,m)
161
162#define COND_WAIT_win32(c, m) \
163 STMT_START { \
164 int rc; \
165 if ((rc = SignalObjectAndWait(*(m),*(c),INFINITE,FALSE))) \
166 Perl_croak_nocontext("panic: COND_WAIT"); \
167 else \
168 MUTEX_LOCK(m); \
169 } STMT_END
170#define COND_DESTROY(c) \
171 STMT_START { \
172 int rc; \
173 if ((rc = DosCloseEventSem(*(c)))) \
174 Perl_croak_nocontext("panic: COND_DESTROY, rc=%i", rc); \
175 } STMT_END
176/*#define THR ((struct thread *) TlsGetValue(PL_thr_key))
177*/
178
179#ifdef USE_SLOW_THREAD_SPECIFIC
180# define pthread_getspecific(k) (*_threadstore())
181# define pthread_setspecific(k,v) (*_threadstore()=v,0)
182# define pthread_key_create(keyp,flag) (*keyp=_gettid(),0)
183#else /* USE_SLOW_THREAD_SPECIFIC */
184# define pthread_getspecific(k) (*(k))
185# define pthread_setspecific(k,v) (*(k)=(v),0)
186# define pthread_key_create(keyp,flag) \
187 ( DosAllocThreadLocalMemory(1,(unsigned long**)keyp) \
188 ? Perl_croak_nocontext("LocalMemory"),1 \
189 : 0 \
190 )
191#endif /* USE_SLOW_THREAD_SPECIFIC */
192#define pthread_key_delete(keyp)
193#define pthread_self() _gettid()
194#define YIELD DosSleep(0)
195
196#ifdef PTHREADS_INCLUDED /* For ./x2p stuff. */
197int pthread_join(pthread_t tid, void **status);
198int pthread_detach(pthread_t tid);
199int pthread_create(pthread_t *tid, const pthread_attr_t *attr,
200 void *(*start_routine)(void*), void *arg);
201#endif /* PTHREAD_INCLUDED */
202
203#define THREADS_ELSEWHERE
204
205#else /* USE_ITHREADS */
206
23da6c43 207#define do_spawn(a) os2_do_spawn(a)
208#define do_aspawn(a,b,c) os2_do_aspawn((a),(b),(c))
4a6a15c8 209
aa689395 210void Perl_OS2_init(char **);
764df951 211void Perl_OS2_init3(char **envp, void **excH, int flags);
212void Perl_OS2_term(void **excH, int exitstatus, int flags);
aa689395 213
764df951 214/* The code without INIT3 hideously puts env inside: */
365eb7b5 215
764df951 216/* These ones should be in the same block as PERL_SYS_TERM() */
ed344e4f 217#ifdef PERL_CORE
764df951 218
219# define PERL_SYS_INIT3(argcp, argvp, envp) \
220 { void *xreg[2]; \
22f7c9c9 221 MALLOC_CHECK_TAINT(*argcp, *argvp, *envp) \
ed344e4f 222 _response(argcp, argvp); \
223 _wildcard(argcp, argvp); \
764df951 224 Perl_OS2_init3(*envp, xreg, 0)
225
226# define PERL_SYS_INIT(argcp, argvp) { \
227 { void *xreg[2]; \
eacfb5f1 228 _response(argcp, argvp); \
c0c09dfd 229 _wildcard(argcp, argvp); \
764df951 230 Perl_OS2_init3(NULL, xreg, 0)
231
ed344e4f 232#else /* Compiling embedded Perl or Perl extension */
764df951 233
234# define PERL_SYS_INIT3(argcp, argvp, envp) \
235 { void *xreg[2]; \
236 Perl_OS2_init3(*envp, xreg, 0)
237# define PERL_SYS_INIT(argcp, argvp) { \
238 { void *xreg[2]; \
239 Perl_OS2_init3(NULL, xreg, 0)
ed344e4f 240#endif
241
764df951 242#define FORCE_EMX_DEINIT_EXIT 1
243#define FORCE_EMX_DEINIT_CRT_TERM 2
244#define FORCE_EMX_DEINIT_RUN_ATEXIT 4
245
246#define PERL_SYS_TERM2(xreg,flags) \
247 Perl_OS2_term(xreg, 0, flags); \
248 MALLOC_TERM
249
250#define PERL_SYS_TERM1(xreg) \
251 Perl_OS2_term(xreg, 0, FORCE_EMX_DEINIT_RUN_ATEXIT)
252
253/* This one should come in pair with PERL_SYS_INIT() and in the same block */
254#define PERL_SYS_TERM() \
255 PERL_SYS_TERM1(xreg); \
256 }
257
ed344e4f 258#ifndef __EMX__
aab1f907 259# define PERL_CALLCONV _System
260#endif
ed344e4f 261
4ea6d94f 262/* #define PERL_SYS_TERM() STMT_START { \
263 if (Perl_HAB_set) WinTerminate(Perl_hab); } STMT_END */
264
8cc95fdb 265#define dXSUB_SYS OS2_XS_init()
eacfb5f1 266
4ea6d94f 267#ifdef PERL_IS_AOUT
4a6a15c8 268/* # define HAS_FORK */
760ac839 269/* # define HIDEMYMALLOC */
270/* # define PERL_SBRK_VIA_MALLOC */ /* gets off-page sbrk... */
271#else /* !PERL_IS_AOUT */
272# ifndef PERL_FOR_X2P
4a6a15c8 273# ifdef EMX_BAD_SBRK
274# define USE_PERL_SBRK
275# endif
276# else
277# define PerlIO FILE
760ac839 278# endif
279# define SYSTEM_ALLOC(a) sys_alloc(a)
280
281void *sys_alloc(int size);
282
283#endif /* !PERL_IS_AOUT */
4a6a15c8 284#if !defined(PERL_CORE) && !defined(PerlIO) /* a2p */
285# define PerlIO FILE
286#endif
4ea6d94f 287
23da6c43 288/* os2ish is used from a2p/a2p.h without pTHX/pTHX_ first being
289 * defined. Hack around this to get us to compile.
290*/
291#ifdef PTHX_UNUSED
292# ifndef pTHX
293# define pTHX
294# endif
295# ifndef pTHX_
296# define pTHX_
297# endif
298#endif
299
c0c09dfd 300#define TMPPATH1 "plXXXXXX"
622913ab 301extern const char *tmppath;
23da6c43 302PerlIO *my_syspopen(pTHX_ char *cmd, char *mode);
4a6a15c8 303/* Cannot prototype with I32 at this point. */
304int my_syspclose(PerlIO *f);
55497cff 305FILE *my_tmpfile (void);
306char *my_tmpnam (char *);
5ba48348 307int my_mkdir (__const__ char *, long);
308int my_rmdir (__const__ char *);
f72c975a 309struct passwd *my_getpwent (void);
310void my_setpwent (void);
311void my_endpwent (void);
a64c954a 312char *gcvt_os2(double value, int digits, char *buffer);
f72c975a 313
622913ab 314#define MAX_SLEEP (((1<30) / (1000/4))-1) /* 1<32 msec */
315
316static __inline__ unsigned
317my_sleep(unsigned sec)
318{
319 int remain;
320 while (sec > MAX_SLEEP) {
321 sec -= MAX_SLEEP;
322 remain = sleep(MAX_SLEEP);
323 if (remain)
324 return remain + sec;
325 }
326 return sleep(sec);
327}
328
329#define sleep my_sleep
330
331#ifndef INCL_DOS
332unsigned long DosSleep(unsigned long);
333unsigned long DosAllocThreadLocalMemory (unsigned long cb, unsigned long **p);
334#endif
335
f72c975a 336struct group *getgrent (void);
337void setgrent (void);
338void endgrent (void);
339
340struct passwd *my_getpwuid (uid_t);
341struct passwd *my_getpwnam (__const__ char *);
55497cff 342
bddf7535 343#undef L_tmpnam
344#define L_tmpnam MAXPATHLEN
345
55497cff 346#define tmpfile my_tmpfile
347#define tmpnam my_tmpnam
3ed26a2c 348#define isatty _isterm
44a8e56a 349#define rand random
350#define srand srandom
e75931a7 351#define strtoll _strtoll
352#define strtoull _strtoull
eacfb5f1 353
622913ab 354#define usleep(usec) ((void)_sleep2(((usec)+500)/1000))
355
356
4633a7c4 357/*
358 * fwrite1() should be a routine with the same calling sequence as fwrite(),
359 * but which outputs all of the bytes requested as a single stream (unlike
360 * fwrite() itself, which on some systems outputs several distinct records
361 * if the number_of_items parameter is >1).
362 */
363#define fwrite1 fwrite
364
365#define my_getenv(var) getenv(var)
367f3c24 366#define flock my_flock
5ba48348 367#define rmdir my_rmdir
368#define mkdir my_mkdir
f72c975a 369#define setpwent my_setpwent
370#define getpwent my_getpwent
371#define endpwent my_endpwent
372#define getpwuid my_getpwuid
373#define getpwnam my_getpwnam
4633a7c4 374
df3ef7a9 375void *emx_calloc (size_t, size_t);
376void emx_free (void *);
377void *emx_malloc (size_t);
378void *emx_realloc (void *, size_t);
379
4633a7c4 380/*****************************************************************************/
381
382#include <stdlib.h> /* before the following definitions */
383#include <unistd.h> /* before the following definitions */
21cdd7e3 384#include <fcntl.h>
385#include <sys/stat.h>
4633a7c4 386
387#define chdir _chdir2
388#define getcwd _getcwd2
389
390/* This guy is needed for quick stdstd */
391
392#if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
4633a7c4 393 /* Perl uses ungetc only with successful return */
394# define ungetc(c,fp) \
395 (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
396 ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
397#endif
398
23b84778 399#define PERLIO_IS_BINMODE_FD(fd) _PERLIO_IS_BINMODE_FD(fd)
400
9c75282f 401#ifdef __GNUG__
402# define HAS_BOOL
403#endif
404#ifndef HAS_BOOL
405# define bool char
406# define HAS_BOOL 1
407#endif
408
ab8d95c9 409#include <emx/io.h> /* for _fd_flags() prototype */
377cf4e9 410
23b84778 411static inline bool
412_PERLIO_IS_BINMODE_FD(int fd)
413{
414 int *pflags = _fd_flags(fd);
415
416 return pflags && (*pflags) & O_BINARY;
417}
418
46e87256 419/* ctermid is missing from emx0.9d */
420char *ctermid(char *s);
421
4633a7c4 422#define OP_BINARY O_BINARY
423
424#define OS2_STAT_HACK 1
425#if OS2_STAT_HACK
426
427#define Stat(fname,bufptr) os2_stat((fname),(bufptr))
5c728af0 428#define Fstat(fd,bufptr) os2_fstat((fd),(bufptr))
365eb7b5 429#define Fflush(fp) fflush(fp)
8cc95fdb 430#define Mkdir(path,mode) mkdir((path),(mode))
5c728af0 431#define chmod(path,mode) os2_chmod((path),(mode))
4633a7c4 432
433#undef S_IFBLK
434#undef S_ISBLK
5c728af0 435#define S_IFBLK 0120000 /* Hacks to make things compile... */
4633a7c4 436#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
437
5c728af0 438int os2_chmod(const char *name, int pmode);
439int os2_fstat(int handle, struct stat *st);
440
4633a7c4 441#else
442
443#define Stat(fname,bufptr) stat((fname),(bufptr))
444#define Fstat(fd,bufptr) fstat((fd),(bufptr))
365eb7b5 445#define Fflush(fp) fflush(fp)
8cc95fdb 446#define Mkdir(path,mode) mkdir((path),(mode))
4633a7c4 447
448#endif
365eb7b5 449
44a8e56a 450/* With SD386 it is impossible to debug register variables. */
451#if !defined(PERL_IS_AOUT) && defined(DEBUGGING) && !defined(register)
452# define register
453#endif
454
365eb7b5 455/* Our private OS/2 specific data. */
456
457typedef struct OS2_Perl_data {
458 unsigned long flags;
459 unsigned long phab;
460 int (*xs_init)();
4ea6d94f 461 unsigned long rc;
462 unsigned long severity;
4bfbfac5 463 unsigned long phmq; /* Handle to message queue */
464 unsigned long phmq_refcnt;
465 unsigned long phmq_servers;
466 unsigned long initial_mode; /* VIO etc. mode we were started in */
622913ab 467 unsigned long morph_refcnt;
365eb7b5 468} OS2_Perl_data_t;
469
470extern OS2_Perl_data_t OS2_Perl_data;
471
4ea6d94f 472#define Perl_hab ((HAB)OS2_Perl_data.phab)
473#define Perl_rc (OS2_Perl_data.rc)
474#define Perl_severity (OS2_Perl_data.severity)
475#define errno_isOS2 12345678
ed344e4f 476#define errno_isOS2_set 12345679
4ea6d94f 477#define OS2_Perl_flags (OS2_Perl_data.flags)
365eb7b5 478#define Perl_HAB_set_f 1
4ea6d94f 479#define Perl_HAB_set (OS2_Perl_flags & Perl_HAB_set_f)
480#define set_Perl_HAB_f (OS2_Perl_flags |= Perl_HAB_set_f)
481#define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
4bfbfac5 482#define _obtain_Perl_HAB (init_PMWIN_entries(), \
483 Perl_hab = (*PMWIN_entries.Initialize)(0), \
484 set_Perl_HAB_f, Perl_hab)
485#define perl_hab_GET() (Perl_HAB_set ? Perl_hab : _obtain_Perl_HAB)
486#define Acquire_hab() perl_hab_GET()
487#define Perl_hmq ((HMQ)OS2_Perl_data.phmq)
488#define Perl_hmq_refcnt (OS2_Perl_data.phmq_refcnt)
489#define Perl_hmq_servers (OS2_Perl_data.phmq_servers)
490#define Perl_os2_initial_mode (OS2_Perl_data.initial_mode)
622913ab 491#define Perl_morph_refcnt (OS2_Perl_data.morph_refcnt)
4bfbfac5 492
493unsigned long Perl_hab_GET();
494unsigned long Perl_Register_MQ(int serve);
495void Perl_Deregister_MQ(int serve);
496int Perl_Serve_Messages(int force);
497/* Cannot prototype with I32 at this point. */
498int Perl_Process_Messages(int force, long *cntp);
23da6c43 499char *os2_execname(pTHX);
4bfbfac5 500
501struct _QMSG;
502struct PMWIN_entries_t {
503 unsigned long (*Initialize)( unsigned long fsOptions );
504 unsigned long (*CreateMsgQueue)(unsigned long hab, long cmsg);
505 int (*DestroyMsgQueue)(unsigned long hmq);
506 int (*PeekMsg)(unsigned long hab, struct _QMSG *pqmsg,
507 unsigned long hwndFilter, unsigned long msgFilterFirst,
508 unsigned long msgFilterLast, unsigned long fl);
509 int (*GetMsg)(unsigned long hab, struct _QMSG *pqmsg,
510 unsigned long hwndFilter, unsigned long msgFilterFirst,
511 unsigned long msgFilterLast);
512 void * (*DispatchMsg)(unsigned long hab, struct _QMSG *pqmsg);
5ba48348 513 unsigned long (*GetLastError)(unsigned long hab);
514 unsigned long (*CancelShutdown)(unsigned long hmq, unsigned long fCancelAlways);
4bfbfac5 515};
516extern struct PMWIN_entries_t PMWIN_entries;
517void init_PMWIN_entries(void);
518
ed344e4f 519#define perl_hmq_GET(serve) Perl_Register_MQ(serve)
520#define perl_hmq_UNSET(serve) Perl_Deregister_MQ(serve)
4bfbfac5 521
23da6c43 522#define OS2_XS_init() (*OS2_Perl_data.xs_init)(aTHX)
ed344e4f 523
524#if _EMX_CRT_REV_ >= 60
525# define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2_set, \
526 _setsyserrno(rc))
527#else
528# define os2_setsyserrno(rc) (Perl_rc = rc, errno = errno_isOS2)
529#endif
530
4ea6d94f 531/* The expressions below return true on error. */
4a6a15c8 532/* INCL_DOSERRORS needed. rc should be declared outside. */
4ea6d94f 533#define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
534/* INCL_WINERRORS needed. */
4ea6d94f 535#define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
30500b05 536
537/* This form propagates the return value, setting $^E if needed */
538#define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
539
540/* This form propagates the return value, dieing with $^E if needed */
541#define SaveCroakWinError(expr,die,name1,name2) \
542 ((expr) ? : (CroakWinError(die,name1 name2), 0))
543
ed344e4f 544#define FillOSError(rc) (os2_setsyserrno(rc), \
4ea6d94f 545 Perl_severity = SEVERITY_ERROR)
5ba48348 546
30500b05 547#define WinError_2_Perl_rc \
548 ( init_PMWIN_entries(), \
549 Perl_rc=(*PMWIN_entries.GetLastError)(perl_hab_GET()) )
550
551/* Calling WinGetLastError() resets the error code of the current thread.
552 Since for some Win* API return value 0 is normal, one needs to call
553 this before calling them to distinguish normal and anomalous returns. */
554/*#define ResetWinError() WinError_2_Perl_rc */
555
5ba48348 556/* At this moment init_PMWIN_entries() should be a nop (WinInitialize should
557 be called already, right?), so we do not risk stepping over our own error */
30500b05 558#define FillWinError ( WinError_2_Perl_rc, \
5ba48348 559 Perl_severity = ERRORIDSEV(Perl_rc), \
560 Perl_rc = ERRORIDERROR(Perl_rc), \
561 os2_setsyserrno(Perl_rc))
4ea6d94f 562
760ac839 563#define STATIC_FILE_LENGTH 127
ff68c719 564
35bc1fdc 565 /* This should match loadOrdinals[] array in os2.c */
566enum entries_ordinals {
567 ORD_DosQueryExtLibpath,
568 ORD_DosSetExtLibpath,
569 ORD_DosVerifyPidTid,
570 ORD_SETHOSTENT,
571 ORD_SETNETENT,
572 ORD_SETPROTOENT,
573 ORD_SETSERVENT,
574 ORD_GETHOSTENT,
575 ORD_GETNETENT,
576 ORD_GETPROTOENT,
577 ORD_GETSERVENT,
578 ORD_ENDHOSTENT,
579 ORD_ENDNETENT,
580 ORD_ENDPROTOENT,
581 ORD_ENDSERVENT,
582 ORD_WinInitialize,
583 ORD_WinCreateMsgQueue,
584 ORD_WinDestroyMsgQueue,
585 ORD_WinPeekMsg,
586 ORD_WinGetMsg,
587 ORD_WinDispatchMsg,
588 ORD_WinGetLastError,
589 ORD_WinCancelShutdown,
590 ORD_RexxStart,
591 ORD_RexxVariablePool,
592 ORD_RexxRegisterFunctionExe,
593 ORD_RexxDeregisterFunction,
594 ORD_DOSSMSETTITLE,
595 ORD_PRF32QUERYPROFILESIZE,
596 ORD_PRF32OPENPROFILE,
597 ORD_PRF32CLOSEPROFILE,
598 ORD_PRF32QUERYPROFILE,
599 ORD_PRF32RESET,
600 ORD_PRF32QUERYPROFILEDATA,
601 ORD_PRF32WRITEPROFILEDATA,
602
603 ORD_WinChangeSwitchEntry,
604 ORD_WinQuerySwitchEntry,
605 ORD_WinQuerySwitchHandle,
606 ORD_WinQuerySwitchList,
607 ORD_WinSwitchToProgram,
608 ORD_WinBeginEnumWindows,
609 ORD_WinEndEnumWindows,
610 ORD_WinEnumDlgItem,
611 ORD_WinGetNextWindow,
612 ORD_WinIsChild,
613 ORD_WinQueryActiveWindow,
614 ORD_WinQueryClassName,
615 ORD_WinQueryFocus,
616 ORD_WinQueryWindow,
617 ORD_WinQueryWindowPos,
618 ORD_WinQueryWindowProcess,
619 ORD_WinQueryWindowText,
620 ORD_WinQueryWindowTextLength,
621 ORD_WinSetFocus,
622 ORD_WinSetWindowPos,
623 ORD_WinSetWindowText,
624 ORD_WinShowWindow,
625 ORD_WinIsWindow,
626 ORD_WinWindowFromId,
627 ORD_WinWindowFromPoint,
628 ORD_WinPostMsg,
30500b05 629 ORD_WinEnableWindow,
630 ORD_WinEnableWindowUpdate,
631 ORD_WinIsWindowEnabled,
632 ORD_WinIsWindowShowing,
633 ORD_WinIsWindowVisible,
634 ORD_WinQueryWindowPtr,
635 ORD_WinQueryWindowULong,
636 ORD_WinQueryWindowUShort,
637 ORD_WinSetWindowBits,
638 ORD_WinSetWindowPtr,
639 ORD_WinSetWindowULong,
640 ORD_WinSetWindowUShort,
641 ORD_WinQueryDesktopWindow,
642 ORD_WinSetActiveWindow,
643 ORD_DosQueryModFromEIP,
622913ab 644 ORD_Dos32QueryHeaderInfo,
645 ORD_DosTmrQueryFreq,
646 ORD_DosTmrQueryTime,
647 ORD_WinQueryActiveDesktopPathname,
648 ORD_WinInvalidateRect,
649 ORD_WinCreateFrameControls,
650 ORD_WinQueryClipbrdFmtInfo,
651 ORD_WinQueryClipbrdOwner,
652 ORD_WinQueryClipbrdViewer,
653 ORD_WinQueryClipbrdData,
654 ORD_WinOpenClipbrd,
655 ORD_WinCloseClipbrd,
656 ORD_WinSetClipbrdData,
657 ORD_WinSetClipbrdOwner,
658 ORD_WinSetClipbrdViewer,
659 ORD_WinEnumClipbrdFmts,
660 ORD_WinEmptyClipbrd,
661 ORD_WinAddAtom,
662 ORD_WinFindAtom,
663 ORD_WinDeleteAtom,
664 ORD_WinQueryAtomUsage,
665 ORD_WinQueryAtomName,
666 ORD_WinQueryAtomLength,
667 ORD_WinQuerySystemAtomTable,
668 ORD_WinCreateAtomTable,
669 ORD_WinDestroyAtomTable,
670 ORD_WinOpenWindowDC,
671 ORD_DevOpenDC,
672 ORD_DevQueryCaps,
673 ORD_DevCloseDC,
674 ORD_WinMessageBox,
675 ORD_WinMessageBox2,
676 ORD_WinQuerySysValue,
677 ORD_WinSetSysValue,
678 ORD_WinAlarm,
679 ORD_WinFlashWindow,
680 ORD_WinLoadPointer,
681 ORD_WinQuerySysPointer,
35bc1fdc 682 ORD_NENTRIES
683};
684
685/* RET: return type, AT: argument signature in (), ARGS: should be in () */
686#define CallORD(ret,o,at,args) (((ret (*)at) loadByOrdinal(o, 1))args)
687#define DeclFuncByORD(ret,name,o,at,args) \
688 ret name at { return CallORD(ret,o,at,args); }
689#define DeclVoidFuncByORD(name,o,at,args) \
690 void name at { CallORD(void,o,at,args); }
691
692/* These functions return false on error, and save the error info in $^E */
693#define DeclOSFuncByORD(ret,name,o,at,args) \
694 ret name at { unsigned long rc; return !CheckOSError(CallORD(ret,o,at,args)); }
695#define DeclWinFuncByORD(ret,name,o,at,args) \
696 ret name at { return SaveWinError(CallORD(ret,o,at,args)); }
697
698#define AssignFuncPByORD(p,o) (*(Perl_PFN*)&(p) = (loadByOrdinal(o, 1)))
699
30500b05 700/* This flavor caches the procedure pointer (named as p__Win#name) locally */
701#define DeclWinFuncByORD_CACHE(ret,name,o,at,args) \
702 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,1)
703
704/* This flavor may reset the last error before the call (if ret=0 may be OK) */
705#define DeclWinFuncByORD_CACHE_resetError(ret,name,o,at,args) \
706 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,1)
707
708/* Two flavors below do the same as above, but do not auto-croak */
709/* This flavor caches the procedure pointer (named as p__Win#name) locally */
710#define DeclWinFuncByORD_CACHE_survive(ret,name,o,at,args) \
711 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,0,0)
712
713/* This flavor may reset the last error before the call (if ret=0 may be OK) */
714#define DeclWinFuncByORD_CACHE_resetError_survive(ret,name,o,at,args) \
715 DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,1,0)
716
717#define DeclWinFuncByORD_CACHE_r(ret,name,o,at,args,r,die) \
718 static ret (*CAT2(p__Win,name)) at; \
719 static ret name at { \
720 if (!CAT2(p__Win,name)) \
721 AssignFuncPByORD(CAT2(p__Win,name), o); \
722 if (r) ResetWinError(); \
723 return SaveCroakWinError(CAT2(p__Win,name) args, die, "[Win]", STRINGIFY(name)); }
724
725/* These flavors additionally assume ORD is name with prepended ORD_Win */
726#define DeclWinFunc_CACHE(ret,name,at,args) \
727 DeclWinFuncByORD_CACHE(ret,name,CAT2(ORD_Win,name),at,args)
728#define DeclWinFunc_CACHE_resetError(ret,name,at,args) \
729 DeclWinFuncByORD_CACHE_resetError(ret,name,CAT2(ORD_Win,name),at,args)
730#define DeclWinFunc_CACHE_survive(ret,name,at,args) \
731 DeclWinFuncByORD_CACHE_survive(ret,name,CAT2(ORD_Win,name),at,args)
732#define DeclWinFunc_CACHE_resetError_survive(ret,name,at,args) \
733 DeclWinFuncByORD_CACHE_resetError_survive(ret,name,CAT2(ORD_Win,name),at,args)
734
735void ResetWinError(void);
736void CroakWinError(int die, char *name);
737
760ac839 738#define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
739char *perllib_mangle(char *, unsigned int);
4ea6d94f 740
5c728af0 741#define fork fork_with_resources
742
46c6a8ac 743#ifdef EINTR /* x2p do not include perl.h!!! */
622913ab 744static __inline__ int
745my_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
746{
747 if (nfds == 0 && timeout && (_emx_env & 0x200)) {
748 if (DosSleep(1000 * timeout->tv_sec + (timeout->tv_usec + 500)/1000) == 0)
749 return 0;
750 errno = EINTR;
751 return -1;
752 }
753 return select(nfds, readfds, writefds, exceptfds, timeout);
754}
755
756#define select my_select
46c6a8ac 757#endif
622913ab 758
759
35bc1fdc 760typedef int (*Perl_PFN)();
761Perl_PFN loadByOrdinal(enum entries_ordinals ord, int fail);
762extern const Perl_PFN * const pExtFCN;
4ea6d94f 763char *os2error(int rc);
2d766320 764int os2_stat(const char *name, struct stat *st);
5c728af0 765int fork_with_resources();
2d766320 766int setpriority(int which, int pid, int val);
767int getpriority(int which /* ignored */, int pid);
768
622913ab 769void croak_with_os2error(char *s) __attribute__((noreturn));
770
2d766320 771#ifdef PERL_CORE
772int os2_do_spawn(pTHX_ char *cmd);
622913ab 773int os2_do_aspawn(pTHX_ SV *really, SV **vmark, SV **vsp);
2d766320 774#endif
4ea6d94f 775
ee964dfe 776#ifndef LOG_DAEMON
777
778/* Replacement for syslog.h */
779# define LOG_EMERG 0 /* system is unusable */
780# define LOG_ALERT 1 /* action must be taken immediately */
781# define LOG_CRIT 2 /* critical conditions */
782# define LOG_ERR 3 /* error conditions */
783# define LOG_WARNING 4 /* warning conditions */
784# define LOG_NOTICE 5 /* normal but significant condition */
785# define LOG_INFO 6 /* informational */
786# define LOG_DEBUG 7 /* debug-level messages */
787
788# define LOG_PRIMASK 0x007 /* mask to extract priority part (internal) */
789 /* extract priority */
790# define LOG_PRI(p) ((p) & LOG_PRIMASK)
791# define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
792
793/* facility codes */
794# define LOG_KERN (0<<3) /* kernel messages */
795# define LOG_USER (1<<3) /* random user-level messages */
796# define LOG_MAIL (2<<3) /* mail system */
797# define LOG_DAEMON (3<<3) /* system daemons */
798# define LOG_AUTH (4<<3) /* security/authorization messages */
799# define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */
800# define LOG_LPR (6<<3) /* line printer subsystem */
801# define LOG_NEWS (7<<3) /* network news subsystem */
802# define LOG_UUCP (8<<3) /* UUCP subsystem */
803# define LOG_CRON (15<<3) /* clock daemon */
804 /* other codes through 15 reserved for system use */
805# define LOG_LOCAL0 (16<<3) /* reserved for local use */
806# define LOG_LOCAL1 (17<<3) /* reserved for local use */
807# define LOG_LOCAL2 (18<<3) /* reserved for local use */
808# define LOG_LOCAL3 (19<<3) /* reserved for local use */
809# define LOG_LOCAL4 (20<<3) /* reserved for local use */
810# define LOG_LOCAL5 (21<<3) /* reserved for local use */
811# define LOG_LOCAL6 (22<<3) /* reserved for local use */
812# define LOG_LOCAL7 (23<<3) /* reserved for local use */
813
814# define LOG_NFACILITIES 24 /* current number of facilities */
815# define LOG_FACMASK 0x03f8 /* mask to extract facility part */
816 /* facility of pri */
817# define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
818
819/*
820 * arguments to setlogmask.
821 */
822# define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
823# define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
824
825/*
826 * Option flags for openlog.
827 *
828 * LOG_ODELAY no longer does anything.
829 * LOG_NDELAY is the inverse of what it used to be.
830 */
831# define LOG_PID 0x01 /* log the pid with each message */
832# define LOG_CONS 0x02 /* log on the console if errors in sending */
833# define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
834# define LOG_NDELAY 0x08 /* don't delay open */
835# define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
836# define LOG_PERROR 0x20 /* log to stderr as well */
837
838#endif
839
4ea6d94f 840/* ************************************************************ */
841#define Dos32QuerySysState DosQuerySysState
842#define QuerySysState(flags, pid, buf, bufsz) \
843 Dos32QuerySysState(flags, 0, pid, 0, buf, bufsz)
844
845#define QSS_PROCESS 1
df3ef7a9 846#define QSS_MODULE 4
847#define QSS_SEMAPHORES 2
4ea6d94f 848#define QSS_FILE 8 /* Buggy until fixpack18 */
849#define QSS_SHARED 16
850
ed344e4f 851#ifdef _OS2_H
4ea6d94f 852
853APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
854 ULONG _res_,PVOID buf,ULONG bufsz);
855typedef struct {
856 ULONG threadcnt;
857 ULONG proccnt;
858 ULONG modulecnt;
859} QGLOBAL, *PQGLOBAL;
860
861typedef struct {
862 ULONG rectype;
863 USHORT threadid;
864 USHORT slotid;
865 ULONG sleepid;
866 ULONG priority;
867 ULONG systime;
868 ULONG usertime;
869 UCHAR state;
870 UCHAR _reserved1_; /* padding to ULONG */
871 USHORT _reserved2_; /* padding to ULONG */
872} QTHREAD, *PQTHREAD;
873
874typedef struct {
875 USHORT sfn;
876 USHORT refcnt;
877 USHORT flags1;
878 USHORT flags2;
879 USHORT accmode1;
880 USHORT accmode2;
881 ULONG filesize;
882 USHORT volhnd;
883 USHORT attrib;
884 USHORT _reserved_;
885} QFDS, *PQFDS;
886
887typedef struct qfile {
888 ULONG rectype;
889 struct qfile *next;
890 ULONG opencnt;
891 PQFDS filedata;
892 char name[1];
893} QFILE, *PQFILE;
894
895typedef struct {
896 ULONG rectype;
897 PQTHREAD threads;
898 USHORT pid;
899 USHORT ppid;
900 ULONG type;
901 ULONG state;
902 ULONG sessid;
903 USHORT hndmod;
904 USHORT threadcnt;
905 ULONG privsem32cnt;
906 ULONG _reserved2_;
907 USHORT sem16cnt;
908 USHORT dllcnt;
909 USHORT shrmemcnt;
910 USHORT fdscnt;
911 PUSHORT sem16s;
912 PUSHORT dlls;
913 PUSHORT shrmems;
914 PUSHORT fds;
915} QPROCESS, *PQPROCESS;
916
917typedef struct sema {
918 struct sema *next;
919 USHORT refcnt;
920 UCHAR sysflags;
921 UCHAR sysproccnt;
922 ULONG _reserved1_;
923 USHORT index;
924 CHAR name[1];
925} QSEMA, *PQSEMA;
926
927typedef struct {
928 ULONG rectype;
929 ULONG _reserved1_;
930 USHORT _reserved2_;
931 USHORT syssemidx;
932 ULONG index;
933 QSEMA sema;
934} QSEMSTRUC, *PQSEMSTRUC;
935
936typedef struct {
937 USHORT pid;
938 USHORT opencnt;
939} QSEMOWNER32, *PQSEMOWNER32;
940
941typedef struct {
942 PQSEMOWNER32 own;
943 PCHAR name;
944 PVOID semrecs; /* array of associated sema's */
945 USHORT flags;
946 USHORT semreccnt;
947 USHORT waitcnt;
948 USHORT _reserved_; /* padding to ULONG */
949} QSEMSMUX32, *PQSEMSMUX32;
950
951typedef struct {
952 PQSEMOWNER32 own;
953 PCHAR name;
954 PQSEMSMUX32 mux;
955 USHORT flags;
956 USHORT postcnt;
957} QSEMEV32, *PQSEMEV32;
958
959typedef struct {
960 PQSEMOWNER32 own;
961 PCHAR name;
962 PQSEMSMUX32 mux;
963 USHORT flags;
964 USHORT refcnt;
965 USHORT thrdnum;
966 USHORT _reserved_; /* padding to ULONG */
967} QSEMMUX32, *PQSEMMUX32;
968
969typedef struct semstr32 {
970 struct semstr *next;
971 QSEMEV32 evsem;
972 QSEMMUX32 muxsem;
973 QSEMSMUX32 smuxsem;
974} QSEMSTRUC32, *PQSEMSTRUC32;
975
976typedef struct shrmem {
977 struct shrmem *next;
978 USHORT hndshr;
979 USHORT selshr;
980 USHORT refcnt;
981 CHAR name[1];
982} QSHRMEM, *PQSHRMEM;
983
984typedef struct module {
985 struct module *next;
986 USHORT hndmod;
987 USHORT type;
988 ULONG refcnt;
989 ULONG segcnt;
990 PVOID _reserved_;
991 PCHAR name;
992 USHORT modref[1];
993} QMODULE, *PQMODULE;
994
995typedef struct {
996 PQGLOBAL gbldata;
997 PQPROCESS procdata;
998 PQSEMSTRUC semadata;
999 PQSEMSTRUC32 sem32data;
1000 PQSHRMEM shrmemdata;
1001 PQMODULE moddata;
1002 PVOID _reserved2_;
1003 PQFILE filedata;
1004} QTOPLEVEL, *PQTOPLEVEL;
1005/* ************************************************************ */
1006
1007PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
1008
ed344e4f 1009#endif /* _OS2_H */
5ae7bdf7 1010