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