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