Possible NULL pointer reference found by Coverity checks.
[p5sagit/p5-mst-13.2.git] / vms / vmsish.h
1 /*  vmsish.h
2  *
3  * VMS-specific C header file for perl5.
4  *
5  * revised: 16-Sep-1998 by Charles Bailey  bailey@newman.upenn.edu
6  * Version: 5.5.2
7  *
8  * Last revised: 10-Oct-2005 by John Malmberg (HP OpenVMS) wb8twy@qsl.net
9  *                           Add SYMLINK support, and updated Craig Berry's
10  *                           largefile support.
11  */
12
13 #ifndef __vmsish_h_included
14 #define __vmsish_h_included
15
16 #include <descrip.h> /* for dirent struct definitions */
17 #include <libdef.h>  /* status codes for various places */
18 #include <rmsdef.h>  /* at which errno and vaxc$errno are */
19 #include <ssdef.h>   /* explicitly set in the perl source code */
20 #include <stsdef.h>  /* bitmasks for exit status testing */
21
22 /* Suppress compiler warnings from DECC for VMS-specific extensions:
23  * ADDRCONSTEXT,NEEDCONSTEXT: initialization of data with non-constant values
24  *                            (e.g. pointer fields of descriptors)
25  */
26 #if defined(__DECC) || defined(__DECCXX)
27 #  pragma message disable (ADDRCONSTEXT,NEEDCONSTEXT)
28 #endif
29
30 /* DEC's C compilers and gcc use incompatible definitions of _to(upp|low)er() */
31 #ifdef _toupper
32 #  undef _toupper
33 #endif
34 #define _toupper(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) & ~040)
35 #ifdef _tolower
36 #  undef _tolower
37 #endif
38 #define _tolower(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) | 040)
39 /* DECC 1.3 has a funny definition of abs; it's fixed in DECC 4.0, so this
40  * can go away once DECC 1.3 isn't in use any more. */
41 #if defined(__ALPHA) && (defined(__DECC) || defined(__DECCXX))
42 #undef abs
43 #define abs(__x)        __ABS(__x)
44 #undef labs
45 #define labs(__x)        __LABS(__x)
46 #endif /* __ALPHA && __DECC */
47
48 /* Assorted things to look like Unix */
49 #ifdef __GNUC__
50 #ifndef _IOLBF /* gcc's stdio.h doesn't define this */
51 #define _IOLBF 1
52 #endif
53 #endif
54 #include <processes.h> /* for vfork() */
55 #include <unixio.h>
56 #include <unixlib.h>
57 #include <file.h>  /* it's not <sys/file.h>, so don't use I_SYS_FILE */
58 #if (defined(__DECC) && defined(__DECC_VER) && __DECC_VER > 20000000) || defined(__DECCXX)
59 #  include <unistd.h> /* DECC has this; gcc doesn't */
60 #endif
61
62 #ifdef NO_PERL_TYPEDEFS /* a2p; we don't want Perl's special routines */
63 #  define DONT_MASK_RTL_CALLS
64 #endif
65
66 /* Note that we do, in fact, have this */
67 #define HAS_GETENV_SV
68 #define HAS_GETENV_LEN
69
70 /* All this stiff is for the x2P programs. Hopefully they'll still work */
71 #if defined(PERL_FOR_X2P)
72 #ifndef aTHX_
73 #define aTHX_
74 #endif
75 #ifndef pTHX_
76 #define pTHX_
77 #endif
78 #ifndef pTHX
79 #define pTHX
80 #endif
81 #endif
82
83 #ifndef DONT_MASK_RTL_CALLS
84 #  ifdef getenv
85 #    undef getenv
86 #  endif
87   /* getenv used for regular logical names */
88 #  define getenv(v) Perl_my_getenv(aTHX_ v,TRUE)
89 #endif
90 #ifdef getenv_len
91 #  undef getenv_len
92 #endif
93 #define getenv_len(v,l) Perl_my_getenv_len(aTHX_ v,l,TRUE)
94
95 /* DECC introduces this routine in the RTL as of VMS 7.0; for now,
96  * we'll use ours, since it gives us the full VMS exit status. */
97 #define waitpid my_waitpid
98
99 /* Don't redeclare standard RTL routines in Perl's header files;
100  * VMS history or extensions makes some of the formal protoypes
101  * differ from the common Unix forms.
102  */
103 #define DONT_DECLARE_STD 1
104
105 /* Our own contribution to PerlShr's global symbols . . . */
106 #define prime_env_iter  Perl_prime_env_iter
107 #define vms_image_init  Perl_vms_image_init
108 #define my_tmpfile              Perl_my_tmpfile
109 #define vmstrnenv               Perl_vmstrnenv            
110 #if !defined(PERL_IMPLICIT_CONTEXT)
111 #define my_getenv_len           Perl_my_getenv_len
112 #define vmssetenv               Perl_vmssetenv
113 #define my_trnlnm               Perl_my_trnlnm
114 #define my_setenv               Perl_my_setenv
115 #define my_getenv               Perl_my_getenv
116 #define tounixspec              Perl_tounixspec
117 #define tounixspec_ts           Perl_tounixspec_ts
118 #define tovmsspec               Perl_tovmsspec
119 #define tovmsspec_ts            Perl_tovmsspec_ts
120 #define tounixpath              Perl_tounixpath
121 #define tounixpath_ts           Perl_tounixpath_ts
122 #define tovmspath               Perl_tovmspath
123 #define tovmspath_ts            Perl_tovmspath_ts
124 #define do_rmdir                Perl_do_rmdir
125 #define fileify_dirspec         Perl_fileify_dirspec
126 #define fileify_dirspec_ts      Perl_fileify_dirspec_ts
127 #define pathify_dirspec         Perl_pathify_dirspec
128 #define pathify_dirspec_ts      Perl_pathify_dirspec_ts
129 #define trim_unixpath           Perl_trim_unixpath
130 #define opendir                 Perl_opendir
131 #define rmscopy                 Perl_rmscopy
132 #define my_mkdir                Perl_my_mkdir
133 #define vms_do_aexec            Perl_vms_do_aexec
134 #define vms_do_exec             Perl_vms_do_exec
135 #define my_waitpid              Perl_my_waitpid
136 #define my_crypt                Perl_my_crypt
137 #define kill_file               Perl_kill_file
138 #define my_utime                Perl_my_utime
139 #define my_chdir                Perl_my_chdir
140 #define do_aspawn               Perl_do_aspawn
141 #define seekdir                 Perl_seekdir
142 #define my_gmtime               Perl_my_gmtime
143 #define my_localtime            Perl_my_localtime
144 #define my_time                 Perl_my_time
145 #define do_spawn                Perl_do_spawn
146 #define flex_fstat              Perl_flex_fstat
147 #define flex_stat               Perl_flex_stat
148 #define flex_lstat              Perl_flex_lstat
149 #define cando_by_name           Perl_cando_by_name
150 #define my_getpwnam             Perl_my_getpwnam
151 #define my_getpwuid             Perl_my_getpwuid
152 #define my_flush                Perl_my_flush
153 #define readdir                 Perl_readdir
154 #define readdir_r               Perl_readdir_r
155 #else
156 #define my_getenv_len(a,b,c)    Perl_my_getenv_len(aTHX_ a,b,c)
157 #define vmssetenv(a,b,c)        Perl_vmssetenv(aTHX_ a,b,c)
158 #define my_trnlnm(a,b,c)        Perl_my_trnlnm(aTHX_ a,b,c)
159 #define my_setenv(a,b)          Perl_my_setenv(aTHX_ a,b)
160 #define my_getenv(a,b)          Perl_my_getenv(aTHX_ a,b)
161 #define tounixspec(a,b)         Perl_tounixspec(aTHX_ a,b)
162 #define tounixspec_ts(a,b)      Perl_tounixspec_ts(aTHX_ a,b)
163 #define tovmsspec(a,b)          Perl_tovmsspec(aTHX_ a,b)
164 #define tovmsspec_t(a,b)        Perl_tovmsspec_ts(aTHX_ a,b)
165 #define tounixpath(a,b)         Perl_tounixpath(aTHX_ a,b)
166 #define tounixpath_ts(a,b)      Perl_tounixpath_ts(aTHX_ a,b)
167 #define tovmspath(a,b)          Perl_tovmspath(aTHX_ a,b)
168 #define tovmspath_ts(a,b)       Perl_tovmspath_ts(aTHX_ a,b)
169 #define do_rmdir(a)             Perl_do_rmdir(aTHX_ a)
170 #define fileify_dirspec(a,b)    Perl_fileify_dirspec(aTHX_ a,b)
171 #define fileify_dirspec_ts(a,b) Perl_fileify_dirspec_ts(aTHX_ a,b)
172 #define pathify_dirspec         Perl_pathify_dirspec
173 #define pathify_dirspec_ts      Perl_pathify_dirspec_ts
174 #define rmsexpand(a,b,c,d)      Perl_rmsexpand(aTHX_ a,b,c,d)
175 #define rmsexpand_ts(a,b,c,d)   Perl_rmsexpand_ts(aTHX_ a,b,c,d)
176 #define trim_unixpath(a,b,c)    Perl_trim_unixpath(aTHX_ a,b,c)
177 #define opendir(a)              Perl_opendir(aTHX_ a)
178 #define rmscopy(a,b,c)          Perl_rmscopy(aTHX_ a,b,c)
179 #define my_mkdir(a,b)           Perl_my_mkdir(aTHX_ a,b)
180 #define vms_do_aexec(a,b,c)     Perl_vms_do_aexec(aTHX_ a,b,c)
181 #define vms_do_exec(a)          Perl_vms_do_exec(aTHX_ a)
182 #define my_waitpid(a,b,c)       Perl_my_waitpid(aTHX_ a,b,c)
183 #define my_crypt(a,b)           Perl_my_crypt(aTHX_ a,b)
184 #define kill_file(a)            Perl_kill_file(aTHX_ a)
185 #define my_utime(a,b)           Perl_my_utime(aTHX_ a,b)
186 #define my_chdir(a)             Perl_my_chdir(aTHX_ a)
187 #define do_aspawn(a,b,c)        Perl_do_aspawn(aTHX_ a,b,c)
188 #define seekdir(a,b)            Perl_seekdir(aTHX_ a,b)
189 #define my_gmtime(a)            Perl_my_gmtime(aTHX_ a)
190 #define my_localtime(a)         Perl_my_localtime(aTHX_ a)
191 #define my_time(a)              Perl_my_time(aTHX_ a)
192 #define do_spawn(a)             Perl_do_spawn(aTHX_ a)
193 #define flex_fstat(a,b)         Perl_flex_fstat(aTHX_ a,b)
194 #define cando_by_name(a,b,c)    Perl_cando_by_name(aTHX_ a,b,c)
195 #define flex_stat(a,b)          Perl_flex_stat(aTHX_ a,b)
196 #define my_getpwnam(a)          Perl_my_getpwnam(aTHX_ a)
197 #define my_getpwuid(a)          Perl_my_getpwuid(aTHX_ a)
198 #define my_flush(a)             Perl_my_flush(aTHX_ a)
199 #define readdir(a)              Perl_readdir(aTHX_ a)
200 #define readdir_r(a,b,c)        Perl_readdir_r(aTHX_ a,b,c)
201 #endif
202 #define my_gconvert             Perl_my_gconvert
203 #define telldir                 Perl_telldir
204 #define closedir                Perl_closedir
205 #define vmsreaddirversions      Perl_vmsreaddirversions
206 #define my_sigemptyset        Perl_my_sigemptyset
207 #define my_sigfillset         Perl_my_sigfillset
208 #define my_sigaddset          Perl_my_sigaddset
209 #define my_sigdelset          Perl_my_sigdelset
210 #define my_sigismember        Perl_my_sigismember
211 #define my_sigprocmask        Perl_my_sigprocmask
212 #define my_vfork                Perl_my_vfork
213 #define my_fdopen               Perl_my_fdopen
214 #define my_fclose               Perl_my_fclose
215 #define my_fwrite               Perl_my_fwrite
216 #define my_getpwent()           Perl_my_getpwent(aTHX)
217 #define my_endpwent()           Perl_my_endpwent(aTHX)
218 #define my_getlogin             Perl_my_getlogin
219 #define init_os_extras          Perl_init_os_extras
220 #define vms_realpath(a, b)      Perl_vms_realpath(aTHX_ a,b)
221 #define vms_case_tolerant(a)    Perl_vms_case_tolerant(a)
222
223 /* Delete if at all possible, changing protections if necessary. */
224 #define unlink kill_file
225
226 /* 
227  * Intercept calls to fork, so we know whether subsequent calls to
228  * exec should be handled in VMSish or Unixish style.
229  */
230 #define fork my_vfork
231 #ifndef DONT_MASK_RTL_CALLS     /* #defined in vms.c so we see real vfork */
232 #  ifdef vfork
233 #    undef vfork
234 #  endif
235 #  define vfork my_vfork
236 #endif
237
238 /*
239  * Toss in a shim to tmpfile which creates a plain temp file if the
240  * RMS tmp mechanism won't work (e.g. if someone is relying on ACLs
241  * from a specific directory to permit creation of files).
242  */
243 #ifndef DONT_MASK_RTL_CALLS
244 #  define tmpfile Perl_my_tmpfile
245 #endif
246
247
248 /* BIG_TIME:
249  *      This symbol is defined if Time_t is an unsigned type on this system.
250  */
251 #define BIG_TIME
252
253 /* ACME_MESS:
254  *      This symbol, if defined, indicates that error messages should be 
255  *      should be generated in a format that allows the use of the Acme
256  *      GUI/editor's autofind feature.
257  */
258 #undef ACME_MESS        /**/
259
260 /* ALTERNATE_SHEBANG:
261  *      This symbol, if defined, contains a "magic" string which may be used
262  *      as the first line of a Perl program designed to be executed directly
263  *      by name, instead of the standard Unix #!.  If ALTERNATE_SHEBANG
264  *      begins with a character other then #, then Perl will only treat
265  *      it as a command line if if finds the string "perl" in the first
266  *      word; otherwise it's treated as the first line of code in the script.
267  *      (IOW, Perl won't hand off to another interpreter via an alternate
268  *      shebang sequence that might be legal Perl code.)
269  */
270 #define ALTERNATE_SHEBANG "$"
271
272 /* Lower case entry points for these are missing in some earlier RTLs 
273  * so we borrow the defines and declares from errno.h and upcase them.
274  */
275 #if defined(VMS_WE_ARE_CASE_SENSITIVE) && (__DECC_VER < 50500000)
276 #  define errno      (*CMA$TIS_ERRNO_GET_ADDR())
277 #  define vaxc$errno (*CMA$TIS_VMSERRNO_GET_ADDR())
278    int *CMA$TIS_ERRNO_GET_ADDR     (void);   /* UNIX style error code        */
279    int *CMA$TIS_VMSERRNO_GET_ADDR  (void);   /* VMS error (errno == EVMSERR) */
280 #endif
281
282 /* Macros to set errno using the VAX thread-safe calls, if present */
283 #if (defined(__DECC) || defined(__DECCXX)) && !defined(__ALPHA)
284 #  define set_errno(v)      (cma$tis_errno_set_value(v))
285    void cma$tis_errno_set_value(int __value);  /* missing in some errno.h */
286 #  define set_vaxc_errno(v) (vaxc$errno = (v))
287 #else
288 #  define set_errno(v)      (errno = (v))
289 #  define set_vaxc_errno(v) (vaxc$errno = (v))
290 #endif
291
292 /* Support for 'vmsish' behaviors enabled with C<use vmsish> pragma */
293
294 #define COMPLEX_STATUS  1       /* We track both "POSIX" and VMS values */
295
296 #define HINT_V_VMSISH           24
297 #define HINT_M_VMSISH_STATUS    0x40000000 /* system, $? return VMS status */
298 #define HINT_M_VMSISH_TIME      0x80000000 /* times are local, not UTC */
299 #define NATIVE_HINTS            (PL_hints >> HINT_V_VMSISH)  /* used in op.c */
300
301 #define TEST_VMSISH(h)  (PL_curcop->op_private & ((h) >> HINT_V_VMSISH))
302 #define VMSISH_STATUS   TEST_VMSISH(HINT_M_VMSISH_STATUS)
303 #define VMSISH_TIME     TEST_VMSISH(HINT_M_VMSISH_TIME)
304
305 /* VMS-specific data storage */
306
307 #define HAVE_INTERP_INTERN
308 struct interp_intern {
309     int    hushed;
310     int    posix_exit;
311     double inv_rand_max;
312 };
313 #define VMSISH_HUSHED     (PL_sys_intern.hushed)
314 #define MY_INV_RAND_MAX   (PL_sys_intern.inv_rand_max)
315 #define MY_POSIX_EXIT   (PL_sys_intern.posix_exit)
316
317 /* Flags for vmstrnenv() */
318 #define PERL__TRNENV_SECURE 0x01
319 #define PERL__TRNENV_JOIN_SEARCHLIST 0x02
320
321 /* Handy way to vet calls to VMS system services and RTL routines. */
322 #define _ckvmssts(call) STMT_START { register unsigned long int __ckvms_sts; \
323   if (!((__ckvms_sts=(call))&1)) { \
324   set_errno(EVMSERR); set_vaxc_errno(__ckvms_sts); \
325   Perl_croak(aTHX_ "Fatal VMS error (status=%d) at %s, line %d", \
326   __ckvms_sts,__FILE__,__LINE__); } } STMT_END
327
328 /* Same thing, but don't call back to Perl's croak(); useful for errors
329  * occurring during startup, before Perl's state is initialized */
330 #define _ckvmssts_noperl(call) STMT_START { register unsigned long int __ckvms_sts; \
331   if (!((__ckvms_sts=(call))&1)) { \
332   set_errno(EVMSERR); set_vaxc_errno(__ckvms_sts); \
333   fprintf(stderr,"Fatal VMS error (status=%d) at %s, line %d", \
334   __ckvms_sts,__FILE__,__LINE__); lib$signal(__ckvms_sts); } } STMT_END
335
336 #ifdef VMS_DO_SOCKETS
337 #include "sockadapt.h"
338 #define PERL_SOCK_SYSREAD_IS_RECV
339 #define PERL_SOCK_SYSWRITE_IS_SEND
340 #endif
341
342 #if __CRTL_VER < 70000000
343 #define BIT_BUCKET "_NLA0:"
344 #else
345 #define BIT_BUCKET "/dev/null"
346 #endif
347 #define PERL_SYS_INIT(c,v)      MALLOC_CHECK_TAINT2(*c,*v) vms_image_init((c),(v)); MALLOC_INIT
348 #define PERL_SYS_TERM()         OP_REFCNT_TERM; MALLOC_TERM
349 #define dXSUB_SYS
350 #define HAS_KILL
351 #define HAS_WAIT
352
353 #define PERL_FS_VER_FMT         "%d_%d_%d"
354 /* Temporary; we need to add support for this to Configure.Com */
355 #ifdef PERL_INC_VERSION_LIST
356 #  undef PERL_INC_VERSION_LIST
357 #endif
358
359 /* VMS:
360  *      This symbol, if defined, indicates that the program is running under
361  *      VMS.  It's a symbol automagically defined by all VMS C compilers I've seen.
362  * Just in case, however . . . */
363 /* Note that code really should be using __VMS to comply with ANSI */
364 #ifndef VMS
365 #define VMS             /**/
366 #endif
367
368 /* HAS_IOCTL:
369  *      This symbol, if defined, indicates that the ioctl() routine is
370  *      available to set I/O characteristics
371  */
372 #if defined(__CRTL_VER) && __CRTL_VER >= 70000000
373 #define HAS_IOCTL               /**/
374 #else
375 #undef  HAS_IOCTL               /**/
376 #endif
377  
378 /* HAS_UTIME:
379  *      This symbol, if defined, indicates that the routine utime() is
380  *      available to update the access and modification times of files.
381  */
382 #define HAS_UTIME               /**/
383
384 /* HAS_GROUP
385  *      This symbol, if defined, indicates that the getgrnam() and
386  *      getgrgid() routines are available to get group entries.
387  *      The getgrent() has a separate definition, HAS_GETGRENT.
388  */
389 #undef HAS_GROUP                /**/
390
391 /* HAS_PASSWD
392  *      This symbol, if defined, indicates that the getpwnam() and
393  *      getpwuid() routines are available to get password entries.
394  *      The getpwent() has a separate definition, HAS_GETPWENT.
395  */
396 #define HAS_PASSWD              /**/
397
398 #define HAS_KILL
399 #define HAS_WAIT
400   
401 /* USEMYBINMODE
402  *      This symbol, if defined, indicates that the program should
403  *      use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
404  *      that a file is in "binary" mode -- that is, that no translation
405  *      of bytes occurs on read or write operations.
406  */
407 #undef USEMYBINMODE
408
409 /* Stat_t:
410  *      This symbol holds the type used to declare buffers for information
411  *      returned by stat().  It's usually just struct stat.  It may be necessary
412  *      to include <sys/stat.h> and <sys/types.h> to get any typedef'ed
413  *      information.
414  */
415 /* VMS:
416  * We need this typedef to point to the new type even if DONT_MASK_RTL_CALLS
417  * is in effect, since Perl's thread.h embeds one of these structs in its
418  * thread data struct, and our struct mystat is a different size from the
419  * regular struct stat (cf. note above about having to pad struct to work
420  * around bug in compiler.)
421  * It's OK to pass one of these to the RTL's stat(), though, since the
422  * fields it fills are the same in each struct.
423  */
424 #define Stat_t struct mystat
425
426 /* USE_STAT_RDEV:
427 *       This symbol is defined if this system has a stat structure declaring
428 *       st_rdev
429 *       VMS: Field exists in POSIXish version of struct stat(), but is not used.
430 *
431 *  No definition of what value an operating system or file system should
432 *  put in the st_rdev field has been found by me so far.  Examination of
433 *  LINUX source code indicates that the value is both very platform and
434 *  file system specific, with many filesystems just putting 1 or 0 in it.
435 *  J. Malmberg.
436 */
437 #undef USE_STAT_RDEV            /**/
438
439 /*
440  * fwrite1() should be a routine with the same calling sequence as fwrite(),
441  * but which outputs all of the bytes requested as a single stream (unlike
442  * fwrite() itself, which on some systems outputs several distinct records
443  * if the number_of_items parameter is >1).
444  */
445 #define fwrite1 my_fwrite
446
447
448 #ifndef DONT_MASK_RTL_CALLS
449 #  define fwrite my_fwrite     /* for PerlSIO_fwrite */
450 #  define fdopen my_fdopen
451 #  define fclose my_fclose
452 #endif
453
454
455 /* By default, flush data all the way to disk, not just to RMS buffers */
456 #define Fflush(fp) my_flush(fp)
457
458 /* Use our own rmdir() */
459 #ifndef DONT_MASK_RTL_CALLS
460 #define rmdir(name) do_rmdir(name)
461 #endif
462
463 /* Assorted fiddling with sigs . . . */
464 # include <signal.h>
465 #define ABORT() abort()
466
467 /* Used with our my_utime() routine in vms.c */
468 struct utimbuf {
469   time_t actime;
470   time_t modtime;
471 };
472 #define utime my_utime
473
474 /* This is what times() returns, but <times.h> calls it tbuffer_t on VMS
475  * prior to v7.0.  We check the DECC manifest to see whether it's already
476  * done this for us, relying on the fact that perl.h #includes <time.h>
477  * before it #includes "vmsish.h".
478  */
479
480 #ifndef __TMS
481   struct tms {
482     clock_t tms_utime;    /* user time */
483     clock_t tms_stime;    /* system time - always 0 on VMS */
484     clock_t tms_cutime;   /* user time, children */
485     clock_t tms_cstime;   /* system time, children - always 0 on VMS */
486   };
487 #else
488    /* The new headers change the times() prototype to tms from tbuffer */
489 #  define tbuffer_t struct tms
490 #endif
491
492 /* Substitute our own routines for gmtime(), localtime(), and time(),
493  * which allow us to implement the vmsish 'time' pragma, and work
494  * around absence of system-level UTC support on old versions of VMS.
495  */
496 #define gmtime(t) my_gmtime(t)
497 #define localtime(t) my_localtime(t)
498 #define time(t) my_time(t)
499
500 /* If we're using an older version of VMS whose Unix signal emulation
501  * isn't very POSIXish, then roll our own.
502  */
503 #if __VMS_VER < 70000000 || __DECC_VER < 50200000
504 #  define HOMEGROWN_POSIX_SIGNALS
505 #endif
506 #ifdef HOMEGROWN_POSIX_SIGNALS
507 #  define sigemptyset(t) my_sigemptyset(t)
508 #  define sigfillset(t) my_sigfillset(t)
509 #  define sigaddset(t, u) my_sigaddset(t, u)
510 #  define sigdelset(t, u) my_sigdelset(t, u)
511 #  define sigismember(t, u) my_sigismember(t, u)
512 #  define sigprocmask(t, u, v) my_sigprocmask(t, u, v)
513 #  ifndef _SIGSET_T
514    typedef int sigset_t;
515 #  endif
516    /* The tools for sigprocmask() are there, just not the routine itself */
517 #  ifndef SIG_UNBLOCK
518 #    define SIG_UNBLOCK 1
519 #  endif
520 #  ifndef SIG_BLOCK
521 #    define SIG_BLOCK 2
522 #  endif
523 #  ifndef SIG_SETMASK
524 #    define SIG_SETMASK 3
525 #  endif
526 #  define sigaction sigvec
527 #  define sa_flags sv_onstack
528 #  define sa_handler sv_handler
529 #  define sa_mask sv_mask
530 #  define sigsuspend(set) sigpause(*set)
531 #  define sigpending(a) (not_here("sigpending"),0)
532 #else
533 /*
534  * The C RTL's sigaction fails to check for invalid signal numbers so we 
535  * help it out a bit.
536  */
537 #  ifndef DONT_MASK_RTL_CALLS
538 #    define sigaction(a,b,c) Perl_my_sigaction(aTHX_ a,b,c)
539 #  endif
540 #endif
541 #ifdef KILL_BY_SIGPRC
542 #  define kill  Perl_my_kill
543 #endif
544
545
546 /* VMS doesn't use a real sys_nerr, but we need this when scanning for error
547  * messages in text strings . . .
548  */
549
550 #define sys_nerr EVMSERR  /* EVMSERR is as high as we can go. */
551
552 /* Look up new %ENV values on the fly */
553 #define DYNAMIC_ENV_FETCH 1
554   /* Special getenv function for retrieving %ENV elements. */
555 #define ENVgetenv(v) my_getenv(v,FALSE)
556 #define ENVgetenv_len(v,l) my_getenv_len(v,l,FALSE)
557
558
559 /* Thin jacket around cuserid() to match Unix' calling sequence */
560 #define getlogin my_getlogin
561
562 /* Ditto for sys$hash_password() . . . */
563 #define crypt(a,b)  Perl_my_crypt(aTHX_ a,b)
564
565 /* Tweak arg to mkdir & chdir first, so we can tolerate trailing /. */
566 #define Mkdir(dir,mode) Perl_my_mkdir(aTHX_ (dir),(mode))
567 #define Chdir(dir) my_chdir((dir))
568
569 /* Use our own stat() clones, which handle Unix-style directory names */
570 #define Stat(name,bufptr) flex_stat(name,bufptr)
571 #define Fstat(fd,bufptr) Perl_flex_fstat(aTHX_ fd,bufptr)
572 #ifndef DONT_MASK_RTL_CALLS
573 #define lstat(name, bufptr) Perl_flex_lstat(name, bufptr)
574 #endif
575
576 /* Setup for the dirent routines:
577  * opendir(), closedir(), readdir(), seekdir(), telldir(), and
578  * vmsreaddirversions(), and preprocessor stuff on which these depend:
579  *    Written by Rich $alz, <rsalz@bbn.com> in August, 1990.
580  *
581  */
582
583 /* Flags for the _dirdesc structure */
584 #define PERL_VMSDIR_M_VERSIONS          0x02 /* Want VMS versions */
585 #define PERL_VMSDIR_M_UNIXSPECS         0x04 /* Want UNIX specifications */
586
587
588     /* Data structure returned by READDIR(). */
589 struct dirent {
590     char        d_name[256];            /* File name            */
591     int         d_namlen;               /* Length of d_name */
592     int         vms_verscount;          /* Number of versions   */
593     int         vms_versions[20];       /* Version numbers      */
594 };
595
596     /* Handle returned by opendir(), used by the other routines.  You
597      * are not supposed to care what's inside this structure. */
598 typedef struct _dirdesc {
599     long                        context;
600     int                         flags;
601     unsigned long int           count;
602     char                        *pattern;
603     struct dirent               entry;
604     struct dsc$descriptor_s     pat;
605     void                        *mutex;
606 } DIR;
607
608
609 #define rewinddir(dirp)         seekdir((dirp), 0)
610
611 /* used for our emulation of getpw* */
612 struct passwd {
613         char    *pw_name;    /* Username */
614         char    *pw_passwd;
615         Uid_t   pw_uid;      /* UIC member number */
616         Gid_t   pw_gid;      /* UIC group  number */
617         char    *pw_comment; /* Default device/directory (Unix-style) */
618         char    *pw_gecos;   /* Owner */
619         char    *pw_dir;     /* Default device/directory (VMS-style) */
620         char    *pw_shell;   /* Default CLI name (eg. DCL) */
621 };
622 #define pw_unixdir pw_comment  /* Default device/directory (Unix-style) */
623 #define getpwnam my_getpwnam
624 #define getpwuid my_getpwuid
625 #define getpwent my_getpwent
626 #define endpwent my_endpwent
627 #define setpwent my_endpwent
628
629 /* Our own stat_t substitute, since we play with st_dev and st_ino -
630  * we want atomic types so Unix-bound code which compares these fields
631  * for two files will work most of the time under VMS.
632  * N.B. 1. The st_ino hack assumes that sizeof(unsigned short[3]) ==
633  * sizeof(unsigned) + sizeof(unsigned short).  We can't use a union type
634  * to map the unsigned int we want and the unsigned short[3] the CRTL
635  * returns into the same member, since gcc has different ideas than DECC
636  * and VAXC about sizing union types.
637  * N.B. 2. The routine cando() in vms.c assumes that &stat.st_ino is the
638  * address of a FID.
639  */
640 /* First, grab the system types, so we don't clobber them later */
641 #include <stat.h>
642 /* Since we've got to match the size of the CRTL's stat_t, we need
643  * to mimic DECC's alignment settings.
644  *
645  * The simplest thing is to just put a wrapper around the stat structure
646  * supplied by the CRTL and use #defines to redirect references to the
647  * members to the real names.
648  */
649
650 #if defined(__DECC) || defined(__DECCXX)
651 #  pragma __member_alignment __save
652 #  pragma member_alignment
653 #endif
654
655 typedef unsigned mydev_t;
656 #ifndef _LARGEFILE
657 typedef unsigned myino_t;
658 #else
659 typedef __ino64_t myino_t;
660 #endif
661
662 struct mystat
663 {
664     struct stat crtl_stat;
665     myino_t st_ino;
666 #ifndef _LARGEFILE
667     unsigned rvn; /* FID (num,seq,rvn) + pad */
668 #endif
669     mydev_t st_dev;
670     char st_devnam[256]; /* Cache the (short) VMS name */
671 };
672
673 #define st_mode crtl_stat.st_mode
674 #define st_nlink crtl_stat.st_nlink
675 #define st_uid crtl_stat.st_uid
676 #define st_gid crtl_stat.st_gid
677 #define st_rdev crtl_stat.st_rdev
678 #define st_size crtl_stat.st_size
679 #define st_atime crtl_stat.st_atime
680 #define st_mtime crtl_stat.st_mtime
681 #define st_ctime crtl_stat.st_ctime
682 #define st_fab_rfm crtl_stat.st_fab_rfm
683 #define st_fab_rat crtl_stat.st_fab_rat
684 #define st_fab_fsz crtl_stat.st_fab_fsz
685 #define st_fab_mrs crtl_stat.st_fab_mrs
686
687 #ifdef _USE_STD_STAT
688 #define VMS_INO_T_COMPARE(__a, __b) (__a != __b)
689 #define VMS_INO_T_COPY(__a, __b) a = b
690 #else
691 #define VMS_INO_T_COMPARE(__a, __b) memcmp(&__a, &__b, 6)
692 #define VMS_INO_T_COPY(__a, __b) memcpy(&__a, &__b, 6)
693 #endif
694
695 #if defined(__DECC) || defined(__DECCXX)
696 #  pragma __member_alignment __restore
697 #endif
698
699 /*
700  * DEC C previous to 6.0 corrupts the behavior of the /prefix
701  * qualifier with the extern prefix pragma.  This provisional
702  * hack circumvents this prefix pragma problem in previous 
703  * precompilers.
704  */
705 #if defined(__VMS_VER) && __VMS_VER >= 70000000
706 #  if defined(VMS_WE_ARE_CASE_SENSITIVE) && (__DECC_VER < 60000000)
707 #    pragma __extern_prefix save
708 #    pragma __extern_prefix ""  /* set to empty to prevent prefixing */
709 #    define geteuid decc$__unix_geteuid
710 #    define getuid decc$__unix_getuid
711 #    define stat(__p1,__p2)   decc$__utc_stat(__p1,__p2)
712 #    define fstat(__p1,__p2)  decc$__utc_fstat(__p1,__p2)
713 #    pragma __extern_prefix restore
714 #  endif
715 #endif
716
717 #ifndef DONT_MASK_RTL_CALLS  /* defined for vms.c so we can see RTL calls */
718 #  ifdef stat
719 #    undef stat
720 #  endif
721 #  define stat mystat
722 #  define dev_t mydev_t
723 #  define ino_t myino_t
724 #endif
725 /* Cons up a 'delete' bit for testing access */
726 #define S_IDUSR (S_IWUSR | S_IXUSR)
727 #define S_IDGRP (S_IWGRP | S_IXGRP)
728 #define S_IDOTH (S_IWOTH | S_IXOTH)
729
730
731 /* Prototypes for functions unique to vms.c.  Don't include replacements
732  * for routines in the mainline source files excluded by #ifndef VMS;
733  * their prototypes are already in proto.h.
734  *
735  * In order to keep Gen_ShrFls.Pl happy, functions which are to be made
736  * available to images linked to PerlShr.Exe must be declared between the
737  * __VMS_PROTOTYPES__ and __VMS_SEPYTOTORP__ lines, and must be in the form
738  *    <data type><TAB>name<WHITESPACE>(<prototype args>);
739  */
740
741 #ifdef NO_PERL_TYPEDEFS
742   /* We don't have Perl typedefs available (e.g. when building a2p), so
743      we fake them here.  N.B.  There is *no* guarantee that the faked
744      prototypes will actually match the real routines.  If you want to
745      call Perl routines, include perl.h to get the real typedefs.  */
746 #  ifndef bool
747 #    define bool int
748 #    define __MY_BOOL_TYPE_FAKE
749 #  endif
750 #  ifndef I32
751 #    define I32  int
752 #    define __MY_I32_TYPE_FAKE
753 #  endif
754 #  ifndef SV
755 #    define SV   void   /* Since we only see SV * in prototypes */
756 #    define __MY_SV_TYPE_FAKE
757 #  endif
758 #endif
759
760 void    prime_env_iter (void);
761 void    init_os_extras (void);
762 int     Perl_vms_status_to_unix(int vms_status, int child_flag);
763 int     Perl_unix_status_to_vms(int unix_status);
764 /* prototype section start marker; `typedef' passes through cpp */
765 typedef char  __VMS_PROTOTYPES__;
766 int     Perl_vmstrnenv (const char *, char *, unsigned long int, struct dsc$descriptor_s **, unsigned long int);
767 char *  Perl_vms_realpath (pTHX_ const char *, char *);
768 #if !defined(PERL_IMPLICIT_CONTEXT)
769 int     Perl_vms_case_tolerant(void);
770 char *  Perl_my_getenv (const char *, bool);
771 int     Perl_my_trnlnm (const char *, char *, unsigned long int);
772 char *  Perl_tounixspec (const char *, char *);
773 char *  Perl_tounixspec_ts (const char *, char *);
774 char *  Perl_tovmsspec (const char *, char *);
775 char *  Perl_tovmsspec_ts (const char *, char *);
776 char *  Perl_tounixpath (const char *, char *);
777 char *  Perl_tounixpath_ts (const char *, char *);
778 char *  Perl_tovmspath (const char *, char *);
779 char *  Perl_tovmspath_ts (const char *, char *);
780 int     Perl_do_rmdir (const char *);
781 char *  Perl_fileify_dirspec (const char *, char *);
782 char *  Perl_fileify_dirspec_ts (const char *, char *);
783 char *  Perl_pathify_dirspec (const char *, char *);
784 char *  Perl_pathify_dirspec_ts (const char *, char *);
785 char *  Perl_rmsexpand (const char *, char *, const char *, unsigned);
786 char *  Perl_rmsexpand_ts (const char *, char *, const char *, unsigned);
787 int     Perl_trim_unixpath (char *, const char*, int);
788 DIR  * Perl_opendir (const char *);
789 int     Perl_rmscopy (const char *, const char *, int);
790 int     Perl_my_mkdir (const char *, Mode_t);
791 bool    Perl_vms_do_aexec (SV *, SV **, SV **);
792 #else
793 char *  Perl_my_getenv (pTHX_ const char *, bool);
794 int     Perl_my_trnlnm (pTHX_ const char *, char *, unsigned long int);
795 char *  Perl_tounixspec (pTHX_ const char *, char *);
796 char *  Perl_tounixspec_ts (pTHX_ const char *, char *);
797 char *  Perl_tovmsspec (pTHX_ const char *, char *);
798 char *  Perl_tovmsspec_ts (pTHX_ const char *, char *);
799 char *  Perl_tounixpath (pTHX_ const char *, char *);
800 char *  Perl_tounixpath_ts (pTHX_ const char *, char *);
801 char *  Perl_tovmspath (pTHX_ const char *, char *);
802 char *  Perl_tovmspath_ts (pTHX_ const char *, char *);
803 int     Perl_do_rmdir (pTHX_ const char *);
804 char *  Perl_fileify_dirspec (pTHX_ const char *, char *);
805 char *  Perl_fileify_dirspec_ts (pTHX_ const char *, char *);
806 char *  Perl_pathify_dirspec (pTHX_ const char *, char *);
807 char *  Perl_pathify_dirspec_ts (pTHX_ const char *, char *);
808 char *  Perl_rmsexpand (pTHX_ const char *, char *, const char *, unsigned);
809 char *  Perl_rmsexpand_ts (pTHX_ const char *, char *, const char *, unsigned);
810 int     Perl_trim_unixpath (pTHX_ char *, const char*, int);
811 DIR * Perl_opendir (pTHX_ const char *);
812 int     Perl_rmscopy (pTHX_ const char *, const char *, int);
813 int     Perl_my_mkdir (pTHX_ const char *, Mode_t);
814 bool    Perl_vms_do_aexec (pTHX_ SV *, SV **, SV **);
815 #endif
816 int     Perl_vms_case_tolerant(void);
817 char *  Perl_my_getenv_len (pTHX_ const char *, unsigned long *, bool);
818 int     Perl_vmssetenv (pTHX_ const char *, const char *, struct dsc$descriptor_s **);
819 void    Perl_vmssetuserlnm(pTHX_ const char *name, const char *eqv);
820 char *  Perl_my_crypt (pTHX_ const char *, const char *);
821 Pid_t   Perl_my_waitpid (pTHX_ Pid_t, int *, int);
822 char *  my_gconvert (double, int, int, char *);
823 int     Perl_kill_file (pTHX_ const char *);
824 int     Perl_my_chdir (pTHX_ const char *);
825 FILE *  Perl_my_tmpfile (void);
826 #ifndef HOMEGROWN_POSIX_SIGNALS
827 int     Perl_my_sigaction (pTHX_ int, const struct sigaction*, struct sigaction*);
828 #endif
829 #ifdef KILL_BY_SIGPRC
830 unsigned int    Perl_sig_to_vmscondition (int);
831 int     Perl_my_kill (int, int);
832 void    Perl_csighandler_init (void);
833 #endif
834 int     Perl_my_utime (pTHX_ const char *, const struct utimbuf *);
835 void    Perl_vms_image_init (int *, char ***);
836 struct dirent * Perl_readdir (pTHX_ DIR *);
837 int     Perl_readdir_r(pTHX_ DIR *, struct dirent *, struct dirent **);
838 long    Perl_telldir (DIR *);
839 void    Perl_seekdir (pTHX_ DIR *, long);
840 void    Perl_closedir (DIR *);
841 void    vmsreaddirversions (DIR *, int);
842 struct tm *     Perl_my_gmtime (pTHX_ const time_t *);
843 struct tm *     Perl_my_localtime (pTHX_ const time_t *);
844 time_t  Perl_my_time (pTHX_ time_t *);
845 #ifdef HOMEGROWN_POSIX_SIGNALS
846 int     my_sigemptyset (sigset_t *);
847 int     my_sigfillset  (sigset_t *);
848 int     my_sigaddset   (sigset_t *, int);
849 int     my_sigdelset   (sigset_t *, int);
850 int     my_sigismember (sigset_t *, int);
851 int     my_sigprocmask (int, sigset_t *, sigset_t *);
852 #endif
853 I32     Perl_cando_by_name (pTHX_ I32, bool, const char *);
854 int     Perl_flex_fstat (pTHX_ int, Stat_t *);
855 int     Perl_flex_lstat (pTHX_ const char *, Stat_t *);
856 int     Perl_flex_stat (pTHX_ const char *, Stat_t *);
857 int     my_vfork (void);
858 bool    Perl_vms_do_exec (pTHX_ const char *);
859 unsigned long int       Perl_do_aspawn (pTHX_ void *, void **, void **);
860 unsigned long int       Perl_do_spawn (pTHX_ const char *);
861 FILE *  my_fdopen (int, const char *);
862 int     my_fclose (FILE *);
863 int    my_fwrite (const void *, size_t, size_t, FILE *);
864 int     Perl_my_flush (pTHX_ FILE *);
865 struct passwd * Perl_my_getpwnam (pTHX_ const char *name);
866 struct passwd * Perl_my_getpwuid (pTHX_ Uid_t uid);
867 void    Perl_my_endpwent (pTHX);
868 char *  my_getlogin (void);
869 typedef char __VMS_SEPYTOTORP__;
870 /* prototype section end marker; `typedef' passes through cpp */
871
872 #ifdef NO_PERL_TYPEDEFS  /* We'll try not to scramble later files */
873 #  ifdef __MY_BOOL_TYPE_FAKE
874 #    undef bool
875 #    undef __MY_BOOL_TYPE_FAKE
876 #  endif
877 #  ifdef __MY_I32_TYPE_FAKE
878 #    undef I32
879 #    undef __MY_I32_TYPE_FAKE
880 #  endif
881 #  ifdef __MY_SV_TYPE_FAKE
882 #    undef SV
883 #    undef __MY_SV_TYPE_FAKE
884 #  endif
885 #endif
886
887 #ifndef VMS_DO_SOCKETS
888 /* This relies on tricks in perl.h to pick up that these manifest constants
889  * are undefined and set up conversion routines.  It will then redefine
890  * these manifest constants, so the actual values will match config.h
891  */
892 #undef HAS_HTONS
893 #undef HAS_NTOHS
894 #undef HAS_HTONL
895 #undef HAS_NTOHL
896 #endif
897
898 /* The C RTL manual says to undef the macro for DEC C 5.2 and lower. */
899 #if defined(fileno) && defined(__DECC_VER) && __DECC_VER < 50300000
900 #  undef fileno 
901 #endif 
902
903 #define NO_ENVIRON_ARRAY
904
905 /* RMSEXPAND options */
906 #define PERL_RMSEXPAND_M_VMS            0x02 /* Force output to VMS format */
907 #define PERL_RMSEXPAND_M_LONG           0x04 /* Expand to long name format */
908 #define PERL_RMSEXPAND_M_SYMLINK        0x20 /* Use symbolic link, not target */
909
910 #endif  /* __vmsish_h_included */