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