Minor OS/2 fixes
[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
103 /*
104  * fwrite1() should be a routine with the same calling sequence as fwrite(),
105  * but which outputs all of the bytes requested as a single stream (unlike
106  * fwrite() itself, which on some systems outputs several distinct records
107  * if the number_of_items parameter is >1).
108  */
109 #define fwrite1 fwrite
110
111 #define my_getenv(var) getenv(var)
112
113 void *emx_calloc (size_t, size_t);
114 void emx_free (void *);
115 void *emx_malloc (size_t);
116 void *emx_realloc (void *, size_t);
117
118 /*****************************************************************************/
119
120 #include <stdlib.h>     /* before the following definitions */
121 #include <unistd.h>     /* before the following definitions */
122
123 #define chdir   _chdir2
124 #define getcwd  _getcwd2
125
126 /* This guy is needed for quick stdstd  */
127
128 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
129 #  define _filbuf _fill
130         /* Perl uses ungetc only with successful return */
131 #  define ungetc(c,fp) \
132         (FILE_ptr(fp) > FILE_base(fp) && c == (int)*(FILE_ptr(fp) - 1) \
133          ? (--FILE_ptr(fp), ++FILE_cnt(fp), (int)c) : ungetc(c,fp))
134 #endif
135
136 #define OP_BINARY O_BINARY
137
138 #define OS2_STAT_HACK 1
139 #if OS2_STAT_HACK
140
141 #define Stat(fname,bufptr) os2_stat((fname),(bufptr))
142 #define Fstat(fd,bufptr)   fstat((fd),(bufptr))
143 #define Fflush(fp)         fflush(fp)
144
145 #undef S_IFBLK
146 #undef S_ISBLK
147 #define S_IFBLK         0120000
148 #define S_ISBLK(mode)   (((mode) & S_IFMT) == S_IFBLK)
149
150 #else
151
152 #define Stat(fname,bufptr) stat((fname),(bufptr))
153 #define Fstat(fd,bufptr)   fstat((fd),(bufptr))
154 #define Fflush(fp)         fflush(fp)
155
156 #endif
157
158 /* Our private OS/2 specific data. */
159
160 typedef struct OS2_Perl_data {
161   unsigned long flags;
162   unsigned long phab;
163   int (*xs_init)();
164   unsigned long rc;
165   unsigned long severity;
166 } OS2_Perl_data_t;
167
168 extern OS2_Perl_data_t OS2_Perl_data;
169
170 #define Perl_hab                ((HAB)OS2_Perl_data.phab)
171 #define Perl_rc                 (OS2_Perl_data.rc)
172 #define Perl_severity           (OS2_Perl_data.severity)
173 #define errno_isOS2             12345678
174 #define OS2_Perl_flags  (OS2_Perl_data.flags)
175 #define Perl_HAB_set_f  1
176 #define Perl_HAB_set    (OS2_Perl_flags & Perl_HAB_set_f)
177 #define set_Perl_HAB_f  (OS2_Perl_flags |= Perl_HAB_set_f)
178 #define set_Perl_HAB(h) (set_Perl_HAB_f, Perl_hab = h)
179 #define OS2_XS_init() (*OS2_Perl_data.xs_init)()
180 /* The expressions below return true on error. */
181 /* INCL_DOSERRORS needed. rc should be declared outside. */
182 #define CheckOSError(expr) (!(rc = (expr)) ? 0 : (FillOSError(rc), 1))
183 /* INCL_WINERRORS needed. */
184 #define SaveWinError(expr) ((expr) ? : (FillWinError, 0))
185 #define CheckWinError(expr) ((expr) ? 0: (FillWinError, 1))
186 #define FillOSError(rc) (Perl_rc = rc,                                  \
187                         errno = errno_isOS2,                            \
188                         Perl_severity = SEVERITY_ERROR) 
189 #define FillWinError (Perl_rc = WinGetLastError(Perl_hab),              \
190                         errno = errno_isOS2,                            \
191                         Perl_severity = ERRORIDSEV(Perl_rc),            \
192                         Perl_rc = ERRORIDERROR(Perl_rc)) 
193 #define Acquire_hab() if (!Perl_HAB_set) {                              \
194            Perl_hab = WinInitialize(0);                                 \
195            if (!Perl_hab) die("WinInitialize failed");                  \
196            set_Perl_HAB_f;                                              \
197         }
198
199 #define STATIC_FILE_LENGTH 127
200
201 #define PERLLIB_MANGLE(s, n) perllib_mangle((s), (n))
202 char *perllib_mangle(char *, unsigned int);
203
204 char *os2error(int rc);
205
206 /* ************************************************************ */
207 #define Dos32QuerySysState DosQuerySysState
208 #define QuerySysState(flags, pid, buf, bufsz) \
209         Dos32QuerySysState(flags, 0,  pid, 0, buf, bufsz)
210
211 #define QSS_PROCESS     1
212 #define QSS_MODULE      4
213 #define QSS_SEMAPHORES  2
214 #define QSS_FILE        8               /* Buggy until fixpack18 */
215 #define QSS_SHARED      16
216
217 #ifdef _OS2EMX_H
218
219 APIRET APIENTRY Dos32QuerySysState(ULONG func,ULONG arg1,ULONG pid,
220                         ULONG _res_,PVOID buf,ULONG bufsz);
221 typedef struct {
222         ULONG   threadcnt;
223         ULONG   proccnt;
224         ULONG   modulecnt;
225 } QGLOBAL, *PQGLOBAL;
226
227 typedef struct {
228         ULONG   rectype;
229         USHORT  threadid;
230         USHORT  slotid;
231         ULONG   sleepid;
232         ULONG   priority;
233         ULONG   systime;
234         ULONG   usertime;
235         UCHAR   state;
236         UCHAR   _reserved1_;    /* padding to ULONG */
237         USHORT  _reserved2_;    /* padding to ULONG */
238 } QTHREAD, *PQTHREAD;
239
240 typedef struct {
241         USHORT  sfn;
242         USHORT  refcnt;
243         USHORT  flags1;
244         USHORT  flags2;
245         USHORT  accmode1;
246         USHORT  accmode2;
247         ULONG   filesize;
248         USHORT  volhnd;
249         USHORT  attrib;
250         USHORT  _reserved_;
251 } QFDS, *PQFDS;
252
253 typedef struct qfile {
254         ULONG           rectype;
255         struct qfile    *next;
256         ULONG           opencnt;
257         PQFDS           filedata;
258         char            name[1];
259 } QFILE, *PQFILE;
260
261 typedef struct {
262         ULONG   rectype;
263         PQTHREAD threads;
264         USHORT  pid;
265         USHORT  ppid;
266         ULONG   type;
267         ULONG   state;
268         ULONG   sessid;
269         USHORT  hndmod;
270         USHORT  threadcnt;
271         ULONG   privsem32cnt;
272         ULONG   _reserved2_;
273         USHORT  sem16cnt;
274         USHORT  dllcnt;
275         USHORT  shrmemcnt;
276         USHORT  fdscnt;
277         PUSHORT sem16s;
278         PUSHORT dlls;
279         PUSHORT shrmems;
280         PUSHORT fds;
281 } QPROCESS, *PQPROCESS;
282
283 typedef struct sema {
284         struct sema *next;
285         USHORT  refcnt;
286         UCHAR   sysflags;
287         UCHAR   sysproccnt;
288         ULONG   _reserved1_;
289         USHORT  index;
290         CHAR    name[1];
291 } QSEMA, *PQSEMA;
292
293 typedef struct {
294         ULONG   rectype;
295         ULONG   _reserved1_;
296         USHORT  _reserved2_;
297         USHORT  syssemidx;
298         ULONG   index;
299         QSEMA   sema;
300 } QSEMSTRUC, *PQSEMSTRUC;
301
302 typedef struct {
303         USHORT  pid;
304         USHORT  opencnt;
305 } QSEMOWNER32, *PQSEMOWNER32;
306
307 typedef struct {
308         PQSEMOWNER32    own;
309         PCHAR           name;
310         PVOID           semrecs; /* array of associated sema's */
311         USHORT          flags;
312         USHORT          semreccnt;
313         USHORT          waitcnt;
314         USHORT          _reserved_;     /* padding to ULONG */
315 } QSEMSMUX32, *PQSEMSMUX32;
316
317 typedef struct {
318         PQSEMOWNER32    own;
319         PCHAR           name;
320         PQSEMSMUX32     mux;
321         USHORT          flags;
322         USHORT          postcnt;
323 } QSEMEV32, *PQSEMEV32;
324
325 typedef struct {
326         PQSEMOWNER32    own;
327         PCHAR           name;
328         PQSEMSMUX32     mux;
329         USHORT          flags;
330         USHORT          refcnt;
331         USHORT          thrdnum;
332         USHORT          _reserved_;     /* padding to ULONG */
333 } QSEMMUX32, *PQSEMMUX32;
334
335 typedef struct semstr32 {
336         struct semstr *next;
337         QSEMEV32 evsem;
338         QSEMMUX32  muxsem;
339         QSEMSMUX32 smuxsem;
340 } QSEMSTRUC32, *PQSEMSTRUC32;
341
342 typedef struct shrmem {
343         struct shrmem *next;
344         USHORT  hndshr;
345         USHORT  selshr;
346         USHORT  refcnt;
347         CHAR    name[1];
348 } QSHRMEM, *PQSHRMEM;
349
350 typedef struct module {
351         struct module *next;
352         USHORT  hndmod;
353         USHORT  type;
354         ULONG   refcnt;
355         ULONG   segcnt;
356         PVOID   _reserved_;
357         PCHAR   name;
358         USHORT  modref[1];
359 } QMODULE, *PQMODULE;
360
361 typedef struct {
362         PQGLOBAL        gbldata;
363         PQPROCESS       procdata;
364         PQSEMSTRUC      semadata;
365         PQSEMSTRUC32    sem32data;
366         PQSHRMEM        shrmemdata;
367         PQMODULE        moddata;
368         PVOID           _reserved2_;
369         PQFILE          filedata;
370 } QTOPLEVEL, *PQTOPLEVEL;
371 /* ************************************************************ */
372
373 PQTOPLEVEL get_sysinfo(ULONG pid, ULONG flags);
374
375 #endif /* _OS2EMX_H */
376