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