3 * VMS-specific C header file for perl5.
5 * Last revised: 18-Feb-1997 by Charles Bailey bailey@genetics.upenn.edu
9 #ifndef __vmsish_h_included
10 #define __vmsish_h_included
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 #include <stsdef.h> /* bitmasks for exit status testing */
18 /* Suppress compiler warnings from DECC for VMS-specific extensions:
19 * GLOBALEXT, NOSHAREEXT, READONLYEXT: global[dr]ef declarations
20 * ADDRCONSTEXT,NEEDCONSTEXT: initialization of data with non-constant values
21 * (e.g. pointer fields of descriptors)
24 # pragma message disable (GLOBALEXT,NOSHAREEXT,READONLYEXT,ADDRCONSTEXT,NEEDCONSTEXT)
27 /* DEC's C compilers and gcc use incompatible definitions of _to(upp|low)er() */
31 #define _toupper(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) & ~040)
35 #define _tolower(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) | 040)
36 /* DECC 1.3 has a funny definition of abs; it's fixed in DECC 4.0, so this
37 * can go away once DECC 1.3 isn't in use any more. */
38 #if defined(__ALPHA) && defined(__DECC)
40 #define abs(__x) __ABS(__x)
42 #define labs(__x) __LABS(__x)
43 #endif /* __ALPHA && __DECC */
45 /* Assorted things to look like Unix */
47 #ifndef _IOLBF /* gcc's stdio.h doesn't define this */
51 #include <processes.h> /* for vfork() */
54 #include <file.h> /* it's not <sys/file.h>, so don't use I_SYS_FILE */
55 #if defined(__DECC) && defined(__DECC_VER) && __DECC_VER > 20000000
56 # include <unistd.h> /* DECC has this; VAXC and gcc don't */
59 #ifdef NO_PERL_TYPEDEFS /* a2p; we don't want Perl's special routines */
60 # define DONT_MASK_RTL_CALLS
63 /* defined for vms.c so we can see CRTL | defined for a2p */
64 #ifndef DONT_MASK_RTL_CALLS
68 # define getenv(v) my_getenv(v) /* getenv used for regular logical names */
71 /* DECC introduces this routine in the RTL as of VMS 7.0; for now,
72 * we'll use ours, since it gives us the full VMS exit status. */
76 # define Pid_t unsigned int
78 #define waitpid my_waitpid
80 /* Our own contribution to PerlShr's global symbols . . . */
82 # define my_trnlnm Perl_my_trnlnm
83 # define my_getenv Perl_my_getenv
84 # define prime_env_iter Perl_prime_env_iter
85 # define my_setenv Perl_my_setenv
86 # define my_crypt Perl_my_crypt
87 # define my_waitpid Perl_my_waitpid
88 # define my_gconvert Perl_my_gconvert
89 # define do_rmdir Perl_do_rmdir
90 # define kill_file Perl_kill_file
91 # define my_mkdir Perl_my_mkdir
92 # define my_utime Perl_my_utime
93 # define rmsexpand Perl_rmsexpand
94 # define rmsexpand_ts Perl_rmsexpand_ts
95 # define fileify_dirspec Perl_fileify_dirspec
96 # define fileify_dirspec_ts Perl_fileify_dirspec_ts
97 # define pathify_dirspec Perl_pathify_dirspec
98 # define pathify_dirspec_ts Perl_pathify_dirspec_ts
99 # define tounixspec Perl_tounixspec
100 # define tounixspec_ts Perl_tounixspec_ts
101 # define tovmsspec Perl_tovmsspec
102 # define tovmsspec_ts Perl_tovmsspec_ts
103 # define tounixpath Perl_tounixpath
104 # define tounixpath_ts Perl_tounixpath_ts
105 # define tovmspath Perl_tovmspath
106 # define tovmspath_ts Perl_tovmspath_ts
107 # define vms_image_init Perl_vms_image_init
108 # define opendir Perl_opendir
109 # define readdir Perl_readdir
110 # define telldir Perl_telldir
111 # define seekdir Perl_seekdir
112 # define closedir Perl_closedir
113 # define vmsreaddirversions Perl_vmsreaddirversions
114 #if __VMS_VER < 70000000 || __DECC_VER < 50200000
115 # define my_gmtime Perl_my_gmtime
116 # define my_localtime Perl_my_localtime
117 # define my_time Perl_my_time
119 # define cando_by_name Perl_cando_by_name
120 # define flex_fstat Perl_flex_fstat
121 # define flex_stat Perl_flex_stat
122 # define trim_unixpath Perl_trim_unixpath
123 # define my_vfork Perl_my_vfork
124 # define vms_do_aexec Perl_vms_do_aexec
125 # define vms_do_exec Perl_vms_do_exec
126 # define do_aspawn Perl_do_aspawn
127 # define do_spawn Perl_do_spawn
128 # define my_fwrite Perl_my_fwrite
129 # define my_flush Perl_my_flush
130 # define my_binmode Perl_my_binmode
131 # define my_getpwnam Perl_my_getpwnam
132 # define my_getpwuid Perl_my_getpwuid
133 # define my_getpwent Perl_my_getpwent
134 # define my_endpwent Perl_my_endpwent
135 # define my_getlogin Perl_my_getlogin
136 # define rmscopy Perl_rmscopy
137 # define init_os_extras Perl_init_os_extras
140 /* Delete if at all possible, changing protections if necessary. */
141 #define unlink kill_file
144 * Intercept calls to fork, so we know whether subsequent calls to
145 * exec should be handled in VMSish or Unixish style.
147 #define fork my_vfork
148 #ifndef DONT_MASK_RTL_CALLS /* #defined in vms.c so we see real vfork */
152 # define vfork my_vfork
156 * This symbol is defined if Time_t is an unsigned type on this system.
161 * This symbol is defined if this system has a stat structure declaring
164 #define USE_STAT_RDEV /**/
167 * This symbol, if defined, indicates that error messages should be
168 * should be generated in a format that allows the use of the Acme
169 * GUI/editor's autofind feature.
171 #undef ACME_MESS /**/
173 /* ALTERNATE_SHEBANG:
174 * This symbol, if defined, contains a "magic" string which may be used
175 * as the first line of a Perl program designed to be executed directly
176 * by name, instead of the standard Unix #!. If ALTERNATE_SHEBANG
177 * begins with a character other then #, then Perl will only treat
178 * it as a command line if if finds the string "perl" in the first
179 * word; otherwise it's treated as the first line of code in the script.
180 * (IOW, Perl won't hand off to another interpreter via an alternate
181 * shebang sequence that might be legal Perl code.)
183 #define ALTERNATE_SHEBANG "$"
185 /* Macros to set errno using the VAX thread-safe calls, if present */
186 #if (defined(__DECC) || defined(__DECCXX)) && !defined(__ALPHA)
187 # define set_errno(v) (cma$tis_errno_set_value(v))
188 void cma$tis_errno_set_value(int __value); /* missing in some errno.h */
189 # define set_vaxc_errno(v) (vaxc$errno = (v))
191 # define set_errno(v) (errno = (v))
192 # define set_vaxc_errno(v) (vaxc$errno = (v))
195 /* Support for 'vmsish' behaviors enabled with C<use vmsish> pragma */
197 #define COMPLEX_STATUS 1 /* We track both "POSIX" and VMS values */
199 #define HINT_V_VMSISH 24
200 #define HINT_M_VMSISH_STATUS 0x01000000 /* system, $? return VMS status */
201 #define HINT_M_VMSISH_EXIT 0x02000000 /* exit(1) ==> SS$_NORMAL */
202 #define HINT_M_VMSISH_TIME 0x04000000 /* times are local, not UTC */
203 #define NATIVE_HINTS (hints >> HINT_V_VMSISH) /* used in op.c */
205 #define TEST_VMSISH(h) (curcop->op_private & ((h) >> HINT_V_VMSISH))
206 #define VMSISH_STATUS TEST_VMSISH(HINT_M_VMSISH_STATUS)
207 #define VMSISH_EXIT TEST_VMSISH(HINT_M_VMSISH_EXIT)
208 #define VMSISH_TIME TEST_VMSISH(HINT_M_VMSISH_TIME)
210 /* Handy way to vet calls to VMS system services and RTL routines. */
211 #define _ckvmssts(call) STMT_START { register unsigned long int __ckvms_sts; \
212 if (!((__ckvms_sts=(call))&1)) { \
213 set_errno(EVMSERR); set_vaxc_errno(__ckvms_sts); \
214 croak("Fatal VMS error (status=%d) at %s, line %d", \
215 __ckvms_sts,__FILE__,__LINE__); } } STMT_END
217 /* Same thing, but don't call back to Perl's croak(); useful for errors
218 * occurring during startup, before Perl's state is initialized */
219 #define _ckvmssts_noperl(call) STMT_START { register unsigned long int __ckvms_sts; \
220 if (!((__ckvms_sts=(call))&1)) { \
221 set_errno(EVMSERR); set_vaxc_errno(__ckvms_sts); \
222 fprintf(Perl_debug_log,"Fatal VMS error (status=%d) at %s, line %d", \
223 __ckvms_sts,__FILE__,__LINE__); lib$signal(__ckvms_sts); } } STMT_END
225 #ifdef VMS_DO_SOCKETS
226 #include "sockadapt.h"
229 #define BIT_BUCKET "_NLA0:"
230 #define PERL_SYS_INIT(c,v) vms_image_init((c),(v))
231 #define PERL_SYS_TERM()
237 * This symbol, if defined, indicates that the program is running under
238 * VMS. It's a symbol automagically defined by all VMS C compilers I've seen.
239 * Just in case, however . . . */
245 * This symbol, if defined, indicates that the ioctl() routine is
246 * available to set I/O characteristics
248 #undef HAS_IOCTL /**/
251 * This symbol, if defined, indicates that the routine utime() is
252 * available to update the access and modification times of files.
254 #define HAS_UTIME /**/
257 * This symbol, if defined, indicates that the getgrnam(),
258 * getgrgid(), and getgrent() routines are available to
261 #undef HAS_GROUP /**/
264 * This symbol, if defined, indicates that the getpwnam(),
265 * getpwuid(), and getpwent() routines are available to
266 * get password entries.
268 #define HAS_PASSWD /**/
274 * This symbol, if defined, indicates that the program should
275 * use the routine my_binmode(FILE *fp, char iotype) to insure
276 * that a file is in "binary" mode -- that is, that no translation
277 * of bytes occurs on read or write operations.
282 * fwrite1() should be a routine with the same calling sequence as fwrite(),
283 * but which outputs all of the bytes requested as a single stream (unlike
284 * fwrite() itself, which on some systems outputs several distinct records
285 * if the number_of_items parameter is >1).
287 #define fwrite1 my_fwrite
289 /* By default, flush data all the way to disk, not just to RMS buffers */
290 #define Fflush(fp) my_flush(fp)
292 /* Use our own rmdir() */
293 #define rmdir(name) do_rmdir(name)
295 /* Assorted fiddling with sigs . . . */
297 #define ABORT() abort()
298 /* VAXC's signal.h doesn't #define SIG_ERR, but provides BADSIG instead. */
299 #if !defined(SIG_ERR) && defined(BADSIG)
300 # define SIG_ERR BADSIG
304 /* Used with our my_utime() routine in vms.c */
309 #define utime my_utime
311 /* This is what times() returns, but <times.h> calls it tbuffer_t on VMS
312 * prior to v7.0. We check the DECC manifest to see whether it's already
313 * done this for us, relying on the fact that perl.h #includes <time.h>
314 * before it #includes "vmsish.h".
319 clock_t tms_utime; /* user time */
320 clock_t tms_stime; /* system time - always 0 on VMS */
321 clock_t tms_cutime; /* user time, children */
322 clock_t tms_cstime; /* system time, children - always 0 on VMS */
325 /* The new headers change the times() prototype to tms from tbuffer */
326 # define tbuffer_t struct tms
329 /* Prior to VMS 7.0, the CRTL gmtime() routine was a stub which always
330 * returned NULL. Substitute our own routine, which uses the logical
331 * SYS$TIMEZONE_DIFFERENTIAL, whcih the native UTC support routines
332 * in VMS 6.0 or later use. We also add shims for time() and localtime()
333 * so we can run on UTC by default.
335 #if __VMS_VER < 70000000 || __DECC_VER < 50200000
336 #define gmtime(t) my_gmtime(t)
337 #define localtime(t) my_localtime(t)
338 #define time(t) my_time(t)
341 /* VMS doesn't use a real sys_nerr, but we need this when scanning for error
342 * messages in text strings . . .
345 #define sys_nerr EVMSERR /* EVMSERR is as high as we can go. */
347 /* Look up new %ENV values on the fly */
348 #define DYNAMIC_ENV_FETCH 1
349 #define ENV_HV_NAME "%EnV%VmS%"
350 /* Special getenv function for retrieving %ENV elements. */
351 #define ENV_getenv(v) my_getenv(v)
354 /* Thin jacket around cuserid() tomatch Unix' calling sequence */
355 #define getlogin my_getlogin
357 /* Ditto for sys$hash_passwrod() . . . */
358 #define crypt my_crypt
360 /* Tweak arg to mkdir first, so we can tolerate trailing /. */
361 #define Mkdir(dir,mode) my_mkdir((dir),(mode))
363 /* Use our own stat() clones, which handle Unix-style directory names */
364 #define Stat(name,bufptr) flex_stat(name,bufptr)
365 #define Fstat(fd,bufptr) flex_fstat(fd,bufptr)
367 /* Setup for the dirent routines:
368 * opendir(), closedir(), readdir(), seekdir(), telldir(), and
369 * vmsreaddirversions(), and preprocessor stuff on which these depend:
370 * Written by Rich $alz, <rsalz@bbn.com> in August, 1990.
372 /* Data structure returned by READDIR(). */
374 char d_name[256]; /* File name */
375 int d_namlen; /* Length of d_name */
376 int vms_verscount; /* Number of versions */
377 int vms_versions[20]; /* Version numbers */
380 /* Handle returned by opendir(), used by the other routines. You
381 * are not supposed to care what's inside this structure. */
382 typedef struct _dirdesc {
384 int vms_wantversions;
385 unsigned long int count;
388 struct dsc$descriptor_s pat;
391 #define rewinddir(dirp) seekdir((dirp), 0)
393 /* used for our emulation of getpw* */
395 char *pw_name; /* Username */
397 Uid_t pw_uid; /* UIC member number */
398 Gid_t pw_gid; /* UIC group number */
399 char *pw_comment; /* Default device/directory (Unix-style) */
400 char *pw_gecos; /* Owner */
401 char *pw_dir; /* Default device/directory (VMS-style) */
402 char *pw_shell; /* Default CLI name (eg. DCL) */
404 #define pw_unixdir pw_comment /* Default device/directory (Unix-style) */
405 #define getpwnam my_getpwnam
406 #define getpwuid my_getpwuid
407 #define getpwent my_getpwent
408 #define endpwent my_endpwent
409 #define setpwent my_endpwent
411 /* Our own stat_t substitute, since we play with st_dev and st_ino -
412 * we want atomic types so Unix-bound code which compares these fields
413 * for two files will work most of the time under VMS.
414 * N.B. 1. The st_ino hack assumes that sizeof(unsigned short[3]) ==
415 * sizeof(unsigned) + sizeof(unsigned short). We can't use a union type
416 * to map the unsigned int we want and the unsigned short[3] the CRTL
417 * returns into the same member, since gcc has different ideas than DECC
418 * and VAXC about sizing union types.
419 * N.B 2. The routine cando() in vms.c assumes that &stat.st_ino is the
422 /* First, grab the system types, so we don't clobber them later */
424 /* Since we've got to match the size of the CRTL's stat_t, we need
425 * to mimic DECC's alignment settings.
427 #if defined(__DECC) || defined(__DECCXX)
428 # pragma __member_alignment __save
429 # pragma __nomember_alignment
432 # pragma __message __save
433 # pragma __message disable (__MISALGNDSTRCT)
434 # pragma __message disable (__MISALGNDMEM)
438 char *st_devnam; /* pointer to device name */
439 unsigned st_ino; /* hack - CRTL uses unsigned short[3] for */
440 unsigned short rvn; /* FID (num,seq,rvn) */
441 unsigned short st_mode; /* file "mode" i.e. prot, dir, reg, etc. */
442 int st_nlink; /* for compatibility - not really used */
443 unsigned st_uid; /* from ACP - QIO uic field */
444 unsigned short st_gid; /* group number extracted from st_uid */
445 dev_t st_rdev; /* for compatibility - always zero */
446 off_t st_size; /* file size in bytes */
447 unsigned st_atime; /* file access time; always same as st_mtime */
448 unsigned st_mtime; /* last modification time */
449 unsigned st_ctime; /* file creation time */
450 char st_fab_rfm; /* record format */
451 char st_fab_rat; /* record attributes */
452 char st_fab_fsz; /* fixed header size */
453 unsigned st_dev; /* encoded device name */
455 typedef unsigned mydev_t;
456 typedef unsigned myino_t;
457 #ifndef DONT_MASK_RTL_CALLS /* defined for vms.c so we can see RTL calls */
462 # define dev_t mydev_t
463 # define ino_t myino_t
465 #if defined(__DECC) || defined(__DECCXX)
466 # pragma __member_alignment __restore
469 # pragma __message __restore
471 /* Cons up a 'delete' bit for testing access */
472 #define S_IDUSR (S_IWUSR | S_IXUSR)
473 #define S_IDGRP (S_IWGRP | S_IXGRP)
474 #define S_IDOTH (S_IWOTH | S_IXOTH)
476 /* Prototypes for functions unique to vms.c. Don't include replacements
477 * for routines in the mainline source files excluded by #ifndef VMS;
478 * their prototypes are already in proto.h.
480 * In order to keep Gen_ShrFls.Pl happy, functions which are to be made
481 * available to images linked to PerlShr.Exe must be declared between the
482 * __VMS_PROTOTYPES__ and __VMS_SEPYTOTORP__ lines, and must be in the form
483 * <data type><TAB>name<WHITESPACE>_((<prototype args>));
486 #ifdef NO_PERL_TYPEDEFS
487 /* We don't have Perl typedefs available (e.g. when building a2p), so
488 we fake them here. N.B. There is *no* guarantee that the faked
489 prototypes will actually match the real routines. If you want to
490 call Perl routines, include perl.h to get the real typedefs. */
493 # define __MY_BOOL_TYPE_FAKE
497 # define __MY_I32_TYPE_FAKE
500 # define SV void /* Since we only see SV * in prototypes */
501 # define __MY_SV_TYPE_FAKE
505 void prime_env_iter _((void));
506 void init_os_extras _(());
507 /* prototype section start marker; `typedef' passes through cpp */
508 typedef char __VMS_PROTOTYPES__;
509 int my_trnlnm _((char *, char *, unsigned long int));
510 char * my_getenv _((char *));
511 char * my_crypt _((const char *, const char *));
512 Pid_t my_waitpid _((Pid_t, int *, int));
513 char * my_gconvert _((double, int, int, char *));
514 int do_rmdir _((char *));
515 int kill_file _((char *));
516 int my_mkdir _((char *, Mode_t));
517 int my_utime _((char *, struct utimbuf *));
518 char * rmsexpand _((char *, char *, char *, unsigned));
519 char * rmsexpand_ts _((char *, char *, char *, unsigned));
520 char * fileify_dirspec _((char *, char *));
521 char * fileify_dirspec_ts _((char *, char *));
522 char * pathify_dirspec _((char *, char *));
523 char * pathify_dirspec_ts _((char *, char *));
524 char * tounixspec _((char *, char *));
525 char * tounixspec_ts _((char *, char *));
526 char * tovmsspec _((char *, char *));
527 char * tovmsspec_ts _((char *, char *));
528 char * tounixpath _((char *, char *));
529 char * tounixpath_ts _((char *, char *));
530 char * tovmspath _((char *, char *));
531 char * tovmspath_ts _((char *, char *));
532 void vms_image_init _((int *, char ***));
533 DIR * opendir _((char *));
534 struct dirent * readdir _((DIR *));
535 long telldir _((DIR *));
536 void seekdir _((DIR *, long));
537 void closedir _((DIR *));
538 void vmsreaddirversions _((DIR *, int));
540 struct tm * my_gmtime _((const time_t *));
541 struct tm * my_localtime _((const time_t *));
542 time_t my_time _((time_t *));
543 #endif /* We're assuming these three come as a package */
544 I32 cando_by_name _((I32, I32, char *));
545 int flex_fstat _((int, struct mystat *));
546 int flex_stat _((char *, struct mystat *));
547 int trim_unixpath _((char *, char*, int));
549 bool vms_do_aexec _((SV *, SV **, SV **));
550 bool vms_do_exec _((char *));
551 unsigned long int do_aspawn _((SV *, SV **, SV **));
552 unsigned long int do_spawn _((char *));
553 int my_fwrite _((void *, size_t, size_t, FILE *));
554 int my_flush _((FILE *));
555 FILE * my_binmode _((FILE *, char));
556 struct passwd * my_getpwnam _((char *name));
557 struct passwd * my_getpwuid _((Uid_t uid));
558 struct passwd * my_getpwent _(());
559 void my_endpwent _(());
560 char * my_getlogin _(());
561 int rmscopy _((char *, char *, int));
562 typedef char __VMS_SEPYTOTORP__;
563 /* prototype section end marker; `typedef' passes through cpp */
565 #ifdef NO_PERL_TYPEDEFS /* We'll try not to scramble later files */
566 # ifdef __MY_BOOL_TYPE_FAKE
568 # undef __MY_BOOL_TYPE_FAKE
570 # ifdef __MY_I32_TYPE_FAKE
572 # undef __MY_I32_TYPE_FAKE
574 # ifdef __MY_SV_TYPE_FAKE
576 # undef __MY_SV_TYPE_FAKE
580 #ifndef VMS_DO_SOCKETS
581 /* This relies on tricks in perl.h to pick up that these manifest constants
582 * are undefined and set up conversion routines. It will then redefine
583 * these manifest constants, so the actual values will match config.h
591 #define TMPPATH "sys$scratch:perl-eXXXXXX"
593 #endif /* __vmsish_h_included */