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