perl 5.003_06: t/op/each.t
[p5sagit/p5-mst-13.2.git] / vms / vmsish.h
1 /*  vmsish.h
2  *
3  * VMS-specific C header file for perl5.
4  *
5  * Last revised: 01-Oct-1995 by Charles Bailey  bailey@genetics.upenn.edu
6  * Version: 5.1.6
7  */
8
9 #ifndef __vmsish_h_included
10 #define __vmsish_h_included
11
12 #include <descrip.h> /* for dirent struct definitions */
13 #include <libdef.h>  /* status codes for various places */
14 #include <rmsdef.h>  /* at which errno and vaxc$errno are */
15 #include <ssdef.h>   /* explicitly set in the perl source code */
16
17 /* Suppress compiler warnings from DECC for VMS-specific extensions:
18  * GLOBALEXT, NOSHAREEXT: global[dr]ef declarations
19  * ADDRCONSTEXT,NEEDCONSTEXT: initialization of data with non-constant values
20  *                            (e.g. pointer fields of descriptors)
21  */
22 #ifdef __DECC
23 #  pragma message disable (GLOBALEXT,NOSHAREEXT,ADDRCONSTEXT,NEEDCONSTEXT)
24 #endif
25
26 /* DEC's C compilers and gcc use incompatible definitions of _to(upp|low)er() */
27 #ifdef _toupper
28 #  undef _toupper
29 #endif
30 #define _toupper(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) & ~040)
31 #ifdef _tolower
32 #  undef _tolower
33 #endif
34 #define _tolower(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) | 040)
35 /* DECC 1.3 has a funny definition of abs; it's fixed in DECC 4.0, so this
36  * can go away once DECC 1.3 isn't in use any more. */
37 #if defined(__ALPHA) && defined(__DECC)
38 #undef abs
39 #define abs(__x)        __ABS(__x)
40 #undef labs
41 #define labs(__x)        __LABS(__x)
42 #endif /* __ALPHA && __DECC */
43
44 /* Assorted things to look like Unix */
45 #ifdef __GNUC__
46 #ifndef _IOLBF /* gcc's stdio.h doesn't define this */
47 #define _IOLBF 1
48 #endif
49 #endif
50 #include <processes.h> /* for vfork() */
51 #include <unixio.h>
52 #include <unixlib.h>
53 #include <file.h>  /* it's not <sys/file.h>, so don't use I_SYS_FILE */
54
55 /* Our own contribution to PerlShr's global symbols . . . */
56 #ifdef EMBED
57 #  define my_trnlnm             Perl_my_trnlnm
58 #  define my_getenv             Perl_my_getenv
59 #  define prime_env_iter        Perl_prime_env_iter
60 #  define my_setenv             Perl_my_setenv
61 #  define my_crypt              Perl_my_crypt
62 #  define waitpid               Perl_waitpid
63 #  define my_gconvert           Perl_my_gconvert
64 #  define do_rmdir              Perl_do_rmdir
65 #  define kill_file             Perl_kill_file
66 #  define my_utime              Perl_my_utime
67 #  define fileify_dirspec       Perl_fileify_dirspec
68 #  define fileify_dirspec_ts    Perl_fileify_dirspec_ts
69 #  define pathify_dirspec       Perl_pathify_dirspec
70 #  define pathify_dirspec_ts    Perl_pathify_dirspec_ts
71 #  define tounixspec            Perl_tounixspec
72 #  define tounixspec_ts         Perl_tounixspec_ts
73 #  define tovmsspec             Perl_tovmsspec
74 #  define tovmsspec_ts          Perl_tovmsspec_ts
75 #  define tounixpath            Perl_tounixpath
76 #  define tounixpath_ts         Perl_tounixpath_ts
77 #  define tovmspath             Perl_tovmspath
78 #  define tovmspath_ts          Perl_tovmspath_ts
79 #  define getredirection        Perl_getredirection
80 #  define opendir               Perl_opendir
81 #  define readdir               Perl_readdir
82 #  define telldir               Perl_telldir
83 #  define seekdir               Perl_seekdir
84 #  define closedir              Perl_closedir
85 #  define vmsreaddirversions    Perl_vmsreaddirversions
86 #  define getredirection        Perl_getredirection
87 #  define my_gmtime             Perl_my_gmtime
88 #  define cando_by_name         Perl_cando_by_name
89 #  define flex_fstat            Perl_flex_fstat
90 #  define flex_stat             Perl_flex_stat
91 #  define trim_unixpath         Perl_trim_unixpath
92 #  define my_vfork              Perl_my_vfork
93 #  define vms_do_aexec          Perl_vms_do_aexec
94 #  define vms_do_exec           Perl_vms_do_exec
95 #  define do_aspawn             Perl_do_aspawn
96 #  define do_spawn              Perl_do_spawn
97 #  define my_fwrite             Perl_my_fwrite
98 #  define my_binmode            Perl_my_binmode
99 #  define my_getpwnam           Perl_my_getpwnam
100 #  define my_getpwuid           Perl_my_getpwuid
101 #  define my_getpwent           Perl_my_getpwent
102 #  define my_endpwent           Perl_my_endpwent
103 #  define my_getlogin           Perl_my_getlogin
104 #  define rmscopy               Perl_rmscopy
105 #  define init_os_extras        Perl_init_os_extras
106 #endif
107
108 /* Delete if at all possible, changing protections if necessary. */
109 #define unlink kill_file
110
111 /* 
112  * Intercept calls to fork, so we know whether subsequent calls to
113  * exec should be handled in VMSish or Unixish style.
114  */
115 #define fork my_vfork
116 #ifndef __DONT_MASK_VFORK  /* #defined in vms.c so we see real vfork */
117 #  ifdef vfork
118 #    undef vfork
119 #  endif
120 #  define vfork my_vfork
121 #endif
122
123 /* BIG_TIME:
124  *      This symbol is defined if Time_t is an unsigned type on this system.
125  */
126 #define BIG_TIME
127
128 /* USE_STAT_RDEV:
129  *      This symbol is defined if this system has a stat structure declaring
130  *      st_rdev
131  */
132 #define USE_STAT_RDEV   /**/
133
134 /* ACME_MESS:
135  *      This symbol, if defined, indicates that error messages should be 
136  *      should be generated in a format that allows the use of the Acme
137  *      GUI/editor's autofind feature.
138  */
139 #undef ACME_MESS        /**/
140
141 /* Macros to set errno using the VAX thread-safe calls, if present */
142 #if (defined(__DECC) || defined(__DECCXX)) && !defined(__ALPHA)
143 #  define set_errno(v)      (cma$tis_errno_set_value(v))
144 #  define set_vaxc_errno(v) (vaxc$errno = (v))
145 #else
146 #  define set_errno(v)      (errno = (v))
147 #  define set_vaxc_errno(v) (vaxc$errno = (v))
148 #endif
149
150 /* Handy way to vet calls to VMS system services and RTL routines. */
151 #define _ckvmssts(call) STMT_START { register unsigned long int __ckvms_sts; \
152   if (!((__ckvms_sts=(call))&1)) { \
153   set_errno(EVMSERR); set_vaxc_errno(__ckvms_sts); \
154   croak("Fatal VMS error (status=%d) at %s, line %d", \
155   __ckvms_sts,__FILE__,__LINE__); } } STMT_END
156
157 /* Same thing, but don't call back to Perl's croak(); useful for errors
158  * occurring during startup, before Perl's state is initialized */
159 #define _ckvmssts_noperl(call) STMT_START { register unsigned long int __ckvms_sts; \
160   if (!((__ckvms_sts=(call))&1)) { \
161   set_errno(EVMSERR); set_vaxc_errno(__ckvms_sts); \
162   fprintf(Perl_debug_log,"Fatal VMS error (status=%d) at %s, line %d", \
163   __ckvms_sts,__FILE__,__LINE__); lib$signal(__ckvms_sts); } } STMT_END
164
165 #ifdef VMS_DO_SOCKETS
166 #include "sockadapt.h"
167 #endif
168
169 #define BIT_BUCKET "_NLA0:"
170 #define PERL_SYS_INIT(c,v)  getredirection((c),(v))
171 #define PERL_SYS_TERM()
172 #define dXSUB_SYS int dummy
173 #define HAS_KILL
174 #define HAS_WAIT
175
176 /* VMS:
177  *      This symbol, if defined, indicates that the program is running under
178  *      VMS.  It's a symbol automagically defined by all VMS C compilers I've seen.
179  * Just in case, however . . . */
180 #ifndef VMS
181 #define VMS             /**/
182 #endif
183
184 /* HAS_IOCTL:
185  *      This symbol, if defined, indicates that the ioctl() routine is
186  *      available to set I/O characteristics
187  */
188 #undef  HAS_IOCTL               /**/
189  
190 /* HAS_UTIME:
191  *      This symbol, if defined, indicates that the routine utime() is
192  *      available to update the access and modification times of files.
193  */
194 #define HAS_UTIME               /**/
195
196 /* HAS_GROUP
197  *      This symbol, if defined, indicates that the getgrnam(),
198  *      getgrgid(), and getgrent() routines are available to 
199  *      get group entries.
200  */
201 #undef HAS_GROUP                /**/
202
203 /* HAS_PASSWD
204  *      This symbol, if defined, indicates that the getpwnam(),
205  *      getpwuid(), and getpwent() routines are available to 
206  *      get password entries.
207  */
208 #define HAS_PASSWD              /**/
209
210 #define HAS_KILL
211 #define HAS_WAIT
212   
213 /* USEMYBINMODE
214  *      This symbol, if defined, indicates that the program should
215  *      use the routine my_binmode(FILE *fp, char iotype) to insure
216  *      that a file is in "binary" mode -- that is, that no translation
217  *      of bytes occurs on read or write operations.
218  */
219 #define USEMYBINMODE
220
221 /*
222  * fwrite1() should be a routine with the same calling sequence as fwrite(),
223  * but which outputs all of the bytes requested as a single stream (unlike
224  * fwrite() itself, which on some systems outputs several distinct records
225  * if the number_of_items parameter is >1).
226  */
227 #define fwrite1 my_fwrite
228
229 /* Use our own rmdir() */
230 #define rmdir(name) do_rmdir(name)
231
232 /* Assorted fiddling with sigs . . . */
233 # include <signal.h>
234 #define ABORT() abort()
235
236 /* Used with our my_utime() routine in vms.c */
237 struct utimbuf {
238   time_t actime;
239   time_t modtime;
240 };
241 #define utime my_utime
242
243 /* This is what times() returns, but <times.h> calls it tbuffer_t on VMS
244  * prior to v7.0.  We check the DECC manifest to see whether it's already
245  * done this for us, relying on the fact that perl.h #includes <time.h>
246  * before it #includes "vmsish.h".
247  */
248
249 #ifndef __TMS
250   struct tms {
251     clock_t tms_utime;    /* user time */
252     clock_t tms_stime;    /* system time - always 0 on VMS */
253     clock_t tms_cutime;   /* user time, children */
254     clock_t tms_cstime;   /* system time, children - always 0 on VMS */
255   };
256 #endif
257
258 /* Prior to VMS 7.0, the CRTL gmtime() routine was a stub which always
259  * returned NULL.  Substitute our own routine, which uses the logical
260  * SYS$TIMEZONE_DIFFERENTIAL, whcih the native UTC support routines
261  * in VMS 6.0 or later use.*
262  */
263 #define gmtime(t) my_gmtime(t)
264
265 /* VMS doesn't use a real sys_nerr, but we need this when scanning for error
266  * messages in text strings . . .
267  */
268
269 #define sys_nerr EVMSERR  /* EVMSERR is as high as we can go. */
270
271 /* Look up new %ENV values on the fly */
272 #define DYNAMIC_ENV_FETCH 1
273 #define ENV_HV_NAME "%EnV%VmS%"
274
275 /* Thin jacket around cuserid() tomatch Unix' calling sequence */
276 #define getlogin my_getlogin
277
278 /* Ditto for sys$hash_passwrod() . . . */
279 #define crypt  my_crypt
280
281 /* Use our own stat() clones, which handle Unix-style directory names */
282 #define Stat(name,bufptr) flex_stat(name,bufptr)
283 #define Fstat(fd,bufptr) flex_fstat(fd,bufptr)
284
285 /* By default, flush data all the way to disk, not just to RMS buffers */
286 #define Fflush(fp) ((fflush(fp) || fsync(fileno(fp))) ? EOF : 0)
287
288 /* Setup for the dirent routines:
289  * opendir(), closedir(), readdir(), seekdir(), telldir(), and
290  * vmsreaddirversions(), and preprocessor stuff on which these depend:
291  *    Written by Rich $alz, <rsalz@bbn.com> in August, 1990.
292  *    This code has no copyright.
293  */
294     /* Data structure returned by READDIR(). */
295 struct dirent {
296     char        d_name[256];            /* File name            */
297     int         d_namlen;                       /* Length of d_name */
298     int         vms_verscount;          /* Number of versions   */
299     int         vms_versions[20];       /* Version numbers      */
300 };
301
302     /* Handle returned by opendir(), used by the other routines.  You
303      * are not supposed to care what's inside this structure. */
304 typedef struct _dirdesc {
305     long                        context;
306     int                         vms_wantversions;
307     unsigned long int           count;
308     char                        *pattern;
309     struct dirent               entry;
310     struct dsc$descriptor_s     pat;
311 } DIR;
312
313 #define rewinddir(dirp)         seekdir((dirp), 0)
314
315 /* used for our emulation of getpw* */
316 struct passwd {
317         char    *pw_name;    /* Username */
318         char    *pw_passwd;
319         Uid_t   pw_uid;      /* UIC member number */
320         Gid_t   pw_gid;      /* UIC group  number */
321         char    *pw_comment; /* Default device/directory (Unix-style) */
322         char    *pw_gecos;   /* Owner */
323         char    *pw_dir;     /* Default device/directory (VMS-style) */
324         char    *pw_shell;   /* Default CLI name (eg. DCL) */
325 };
326 #define pw_unixdir pw_comment  /* Default device/directory (Unix-style) */
327 #define getpwnam my_getpwnam
328 #define getpwuid my_getpwuid
329 #define getpwent my_getpwent
330 #define endpwent my_endpwent
331 #define setpwent my_endpwent
332
333 /* Our own stat_t substitute, since we play with st_dev and st_ino -
334  * we want atomic types so Unix-bound code which compares these fields
335  * for two files will work most of the time under VMS.
336  * N.B. 1. The st_ino hack assumes that sizeof(unsigned short[3]) ==
337  * sizeof(unsigned) + sizeof(unsigned short).  We can't use a union type
338  * to map the unsigned int we want and the unsigned short[3] the CRTL
339  * returns into the same member, since gcc has different ideas than DECC
340  * and VAXC about sizing union types.
341  * N.B 2. The routine cando() in vms.c assumes that &stat.st_ino is the
342  * address of a FID.
343  */
344 /* First, grab the system types, so we don't clobber them later */
345 #include <stat.h>
346 /* Since we've got to match the size of the CRTL's stat_t, we need
347  * to mimic DECC's alignment settings.
348  */
349 #if defined(__DECC) || defined(__DECCXX)
350 #  pragma __member_alignment __save
351 #  pragma __nomember_alignment
352 #endif
353 #if defined(__DECC) 
354 #  pragma __message __save
355 #  pragma __message disable (__MISALGNDSTRCT)
356 #  pragma __message disable (__MISALGNDMEM)
357 #endif
358 struct mystat
359 {
360         char *st_devnam;  /* pointer to device name */
361         unsigned st_ino;    /* hack - CRTL uses unsigned short[3] for */
362         unsigned short rvn; /* FID (num,seq,rvn) */
363         unsigned short st_mode; /* file "mode" i.e. prot, dir, reg, etc. */
364         int     st_nlink;       /* for compatibility - not really used */
365         unsigned st_uid;        /* from ACP - QIO uic field */
366         unsigned short st_gid;  /* group number extracted from st_uid */
367         dev_t   st_rdev;        /* for compatibility - always zero */
368         off_t   st_size;        /* file size in bytes */
369         unsigned st_atime;      /* file access time; always same as st_mtime */
370         unsigned st_mtime;      /* last modification time */
371         unsigned st_ctime;      /* file creation time */
372         char    st_fab_rfm;     /* record format */
373         char    st_fab_rat;     /* record attributes */
374         char    st_fab_fsz;     /* fixed header size */
375         unsigned st_dev;        /* encoded device name */
376 };
377 #define stat mystat
378 typedef unsigned mydev_t;
379 #define dev_t mydev_t
380 typedef unsigned myino_t;
381 #define ino_t myino_t
382 #if defined(__DECC) || defined(__DECCXX)
383 #  pragma __member_alignment __restore
384 #endif
385 #if defined(__DECC) 
386 #  pragma __message __restore
387 #endif
388 /* Cons up a 'delete' bit for testing access */
389 #define S_IDUSR (S_IWUSR | S_IXUSR)
390 #define S_IDGRP (S_IWGRP | S_IXGRP)
391 #define S_IDOTH (S_IWOTH | S_IXOTH)
392
393 /* Prototypes for functions unique to vms.c.  Don't include replacements
394  * for routines in the mainline source files excluded by #ifndef VMS;
395  * their prototypes are already in proto.h.
396  *
397  * In order to keep Gen_ShrFls.Pl happy, functions which are to be made
398  * available to images linked to PerlShr.Exe must be declared between the
399  * __VMS_PROTOTYPES__ and __VMS_SEPYTOTORP__ lines, and must be in the form
400  *    <data type><TAB>name<WHITESPACE>_((<prototype args>));
401  */
402
403 void    prime_env_iter _((void));
404 void    getredirection _((int *, char ***));
405 void    init_os_extras _(());
406 /* prototype section start marker; `typedef' passes through cpp */
407 typedef char  __VMS_PROTOTYPES__;
408 int     my_trnlnm _((char *, char *, unsigned long int));
409 char *  my_getenv _((char *));
410 char *  my_crypt _((const char *, const char *));
411 unsigned long int       waitpid _((unsigned long int, int *, int));
412 char *  my_gconvert _((double, int, int, char *));
413 int     do_rmdir _((char *));
414 int     kill_file _((char *));
415 int     my_utime _((char *, struct utimbuf *));
416 char *  fileify_dirspec _((char *, char *));
417 char *  fileify_dirspec_ts _((char *, char *));
418 char *  pathify_dirspec _((char *, char *));
419 char *  pathify_dirspec_ts _((char *, char *));
420 char *  tounixspec _((char *, char *));
421 char *  tounixspec_ts _((char *, char *));
422 char *  tovmsspec _((char *, char *));
423 char *  tovmsspec_ts _((char *, char *));
424 char *  tounixpath _((char *, char *));
425 char *  tounixpath_ts _((char *, char *));
426 char *  tovmspath _((char *, char *));
427 char *  tovmspath_ts _((char *, char *));
428 void    getredirection _(());
429 DIR *   opendir _((char *));
430 struct dirent * readdir _((DIR *));
431 long    telldir _((DIR *));
432 void    seekdir _((DIR *, long));
433 void    closedir _((DIR *));
434 void    vmsreaddirversions _((DIR *, int));
435 struct tm *my_gmtime _((const time_t *));
436 I32     cando_by_name _((I32, I32, char *));
437 int     flex_fstat _((int, struct stat *));
438 int     flex_stat _((char *, struct stat *));
439 int     trim_unixpath _((char *, char*));
440 int     my_vfork _(());
441 bool    vms_do_aexec _((SV *, SV **, SV **));
442 bool    vms_do_exec _((char *));
443 unsigned long int       do_aspawn _((SV *, SV **, SV **));
444 unsigned long int       do_spawn _((char *));
445 int     my_fwrite _((void *, size_t, size_t, FILE *));
446 FILE *  my_binmode _((FILE *, char));
447 struct passwd * my_getpwnam _((char *name));
448 struct passwd * my_getpwuid _((Uid_t uid));
449 struct passwd * my_getpwent _(());
450 void    my_endpwent _(());
451 char *  my_getlogin _(());
452 int     rmscopy _((char *, char *, int));
453 typedef char __VMS_SEPYTOTORP__;
454 /* prototype section end marker; `typedef' passes through cpp */
455
456 #ifndef VMS_DO_SOCKETS
457 /* This relies on tricks in perl.h to pick up that these manifest constants
458  * are undefined and set up conversion routines.  It will then redefine
459  * these manifest constants, so the actual values will match config.h
460  */
461 #undef HAS_HTONS
462 #undef HAS_NTOHS
463 #undef HAS_HTONL
464 #undef HAS_NTOHL
465 #endif
466
467 #define TMPPATH "sys$scratch:perl-eXXXXXX"
468
469 #endif  /* __vmsish_h_included */