Change to use $^O and &Cwd:cwd
[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: 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)
24 #endif
25
26 /* Suppress compiler warnings from DECC for VMS-specific extensions:
27  * GLOBALEXT, NOSHAREEXT: global[dr]ef declarations
28  * ADDRCONSTEXT,NEEDCONSTEXT: initialization of data with non-constant values
29  *                            (e.g. pointer fields of descriptors)
30  */
31 #ifdef __DECC
32 #  pragma message disable (GLOBALEXT,NOSHAREEXT,ADDRCONSTEXT,NEEDCONSTEXT)
33 #endif
34
35 /* DEC's C compilers and gcc use incompatible definitions of _to(upp|low)er() */
36 #ifdef _toupper
37 #  undef _toupper
38 #endif
39 #define _toupper(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) & ~040)
40 #ifdef _tolower
41 #  undef _tolower
42 #endif
43 #define _tolower(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) | 040)
44 /* DECC 1.3 has a funny definition of abs; it's fixed in DECC 4.0, so this
45  * can go away once DECC 1.3 isn't in use any more. */
46 #if defined(__ALPHA) && defined(__DECC)
47 #undef abs
48 #define abs(__x)        __ABS(__x)
49 #undef labs
50 #define labs(__x)        __LABS(__x)
51 #endif /* __ALPHA && __DECC */
52
53 /* Assorted things to look like Unix */
54 #ifdef __GNUC__
55 #ifndef _IOLBF /* gcc's stdio.h doesn't define this */
56 #define _IOLBF 1
57 #endif
58 #endif
59 #include <processes.h> /* for vfork() */
60 #include <unixio.h>
61 #include <unixlib.h>
62 #include <file.h>  /* it's not <sys/file.h>, so don't use I_SYS_FILE */
63 #define unlink kill_file
64
65 /*  The VMS C RTL has vfork() but not fork().  Both actually work in a way
66  *  that's somewhere between Unix vfork() and VMS lib$spawn(), so it's
67  *  probably not a good idea to use them much.  That said, we'll try to
68  *  use vfork() in either case.
69  */
70 #define fork vfork
71
72 /* Macros to set errno using the VAX thread-safe calls, if present */
73 #if (defined(__DECC) || defined(__DECCXX)) && !defined(__ALPHA)
74 #  define set_errno(v)      (cma$tis_errno_set_value(v))
75 #  define set_vaxc_errno(v) (vaxc$errno = (v))
76 #else
77 #  define set_errno(v)      (errno = (v))
78 #  define set_vaxc_errno(v) (vaxc$errno = (v))
79 #endif
80
81 /* Handy way to vet calls to VMS system services and RTL routines. */
82 #define _ckvmssts(call) do { register unsigned long int __ckvms_sts; \
83   if (!((__ckvms_sts=(call))&1)) { \
84   set_errno(EVMSERR); set_vaxc_errno(__ckvms_sts); \
85   croak("Fatal VMS error (status=%d) at %s, line %d", \
86   __ckvms_sts,__FILE__,__LINE__); } } while (0);
87
88 #ifdef VMS_DO_SOCKETS
89 #include "sockadapt.h"
90 #endif
91
92 #define BIT_BUCKET "_NLA0:"
93 #define PERL_SYS_INIT(c,v)  getredirection((c),(v))
94 #define HAS_KILL
95 #define HAS_WAIT
96
97 /* VMS:
98  *      This symbol, if defined, indicates that the program is running under
99  *      VMS.  It's a symbol automagically defined by all VMS C compilers I've seen.
100  * Just in case, however . . . */
101 #ifndef VMS
102 #define VMS             /**/
103 #endif
104
105 /* HAS_IOCTL:
106  *      This symbol, if defined, indicates that the ioctl() routine is
107  *      available to set I/O characteristics
108  */
109 #undef  HAS_IOCTL               /**/
110  
111 /* HAS_UTIME:
112  *      This symbol, if defined, indicates that the routine utime() is
113  *      available to update the access and modification times of files.
114  */
115 #define HAS_UTIME               /**/
116
117 /* HAS_GROUP
118  *      This symbol, if defined, indicates that the getgrnam(),
119  *      getgrgid(), and getgrent() routines are available to 
120  *      get group entries.
121  */
122 #undef HAS_GROUP                /**/
123
124 /* HAS_PASSWD
125  *      This symbol, if defined, indicates that the getpwnam(),
126  *      getpwuid(), and getpwent() routines are available to 
127  *      get password entries.
128  */
129 #define HAS_PASSWD              /**/
130
131 #define HAS_KILL
132 #define HAS_WAIT
133   
134 /*
135  * fwrite1() should be a routine with the same calling sequence as fwrite(),
136  * but which outputs all of the bytes requested as a single stream (unlike
137  * fwrite() itself, which on some systems outputs several distinct records
138  * if the number_of_items parameter is >1).
139  */
140 #define fwrite1 my_fwrite
141
142 /* Use our own rmdir() */
143 #define rmdir(name) do_rmdir(name)
144
145 /* Assorted fiddling with sigs . . . */
146 # include <signal.h>
147 #define ABORT() abort()
148
149 /* Used with our my_utime() routine in vms.c */
150 struct utimbuf {
151   time_t actime;
152   time_t modtime;
153 };
154 #define utime my_utime
155
156 /* This is what times() returns, but <times.h> calls it tbuffer_t on VMS */
157
158 struct tms {
159   clock_t tms_utime;    /* user time */
160   clock_t tms_stime;    /* system time - always 0 on VMS */
161   clock_t tms_cutime;   /* user time, children */
162   clock_t tms_cstime;   /* system time, children - always 0 on VMS */
163 };
164
165 /* Prior to VMS 7.0, the CRTL gmtime() routine was a stub which always
166  * returned NULL.  Substitute our own routine, which uses the logical
167  * SYS$TIMEZONE_DIFFERENTIAL, whcih the native UTC support routines
168  * in VMS 6.0 or later use.*
169  */
170 #define gmtime(t) my_gmtime(t)
171
172 /* VMS doesn't use a real sys_nerr, but we need this when scanning for error
173  * messages in text strings . . .
174  */
175
176 #define sys_nerr EVMSERR  /* EVMSERR is as high as we can go. */
177
178 /* Look up new %ENV values on the fly */
179 #define DYNAMIC_ENV_FETCH 1
180 #define ENV_HV_NAME "%EnV%VmS%"
181
182 /* Thin jacket around cuserid() tomatch Unix' calling sequence */
183 #define getlogin my_getlogin
184
185 /* Ditto for sys$hash_passwrod() . . . */
186 #define crypt  my_crypt
187
188 /* Use our own stat() clones, which handle Unix-style directory names */
189 #define Stat(name,bufptr) flex_stat(name,bufptr)
190 #define Fstat(fd,bufptr) flex_fstat(fd,bufptr)
191
192 /* By default, flush data all the way to disk, not just to RMS buffers */
193 #define Fflush(fp) ((fflush(fp) || fsync(fileno(fp))) ? EOF : 0)
194
195 /* Setup for the dirent routines:
196  * opendir(), closedir(), readdir(), seekdir(), telldir(), and
197  * vmsreaddirversions(), and preprocessor stuff on which these depend:
198  *    Written by Rich $alz, <rsalz@bbn.com> in August, 1990.
199  *    This code has no copyright.
200  */
201     /* Data structure returned by READDIR(). */
202 struct dirent {
203     char        d_name[256];            /* File name            */
204     int         d_namlen;                       /* Length of d_name */
205     int         vms_verscount;          /* Number of versions   */
206     int         vms_versions[20];       /* Version numbers      */
207 };
208
209     /* Handle returned by opendir(), used by the other routines.  You
210      * are not supposed to care what's inside this structure. */
211 typedef struct _dirdesc {
212     long                        context;
213     int                         vms_wantversions;
214     unsigned long int           count;
215     char                        *pattern;
216     struct dirent               entry;
217     struct dsc$descriptor_s     pat;
218 } DIR;
219
220 #define rewinddir(dirp)         seekdir((dirp), 0)
221
222 /* used for our emulation of getpw* */
223 struct passwd {
224         char    *pw_name;    /* Username */
225         char    *pw_passwd;
226         Uid_t   pw_uid;      /* UIC member number */
227         Gid_t   pw_gid;      /* UIC group  number */
228         char    *pw_comment; /* Default device/directory (Unix-style) */
229         char    *pw_gecos;   /* Owner */
230         char    *pw_dir;     /* Default device/directory (VMS-style) */
231         char    *pw_shell;   /* Default CLI name (eg. DCL) */
232 };
233 #define pw_unixdir pw_comment  /* Default device/directory (Unix-style) */
234 #define getpwnam my_getpwnam
235 #define getpwuid my_getpwuid
236 #define getpwent my_getpwent
237 #define endpwent my_endpwent
238 #define setpwent my_endpwent
239
240 /* Our own stat_t substitute, since we play with st_dev and st_ino -
241  * we want atomic types so Unix-bound code which compares these fields
242  * for two files will work most of the time under VMS.
243  * N.B. 1. The st_ino hack assumes that sizeof(unsigned short[3]) ==
244  * sizeof(unsigned) + sizeof(unsigned short).  We can't use a union type
245  * to map the unsigned int we want and the unsigned short[3] the CRTL
246  * returns into the same member, since gcc has different ideas than DECC
247  * and VAXC about sizing union types.
248  * N.B 2. The routine cando() in vms.c assumes that &stat.st_ino is the
249  * address of a FID.
250  */
251 /* First, grab the system types, so we don't clobber them later */
252 #include <stat.h>
253 /* Since we've got to match the size of the CRTL's stat_t, we need
254  * to mimic DECC's alignment settings.
255  */
256 #if defined(__DECC) || defined(__DECCXX)
257 #  pragma __member_alignment __save
258 #  pragma __nomember_alignment
259 #endif
260 #if defined(__DECC) 
261 #  pragma __message __save
262 #  pragma __message disable (__MISALGNDSTRCT)
263 #  pragma __message disable (__MISALGNDMEM)
264 #endif
265 struct mystat
266 {
267         char *st_devnam;  /* pointer to device name */
268         unsigned st_ino;    /* hack - CRTL uses unsigned short[3] for */
269         unsigned short rvn; /* FID (num,seq,rvn) */
270         unsigned short st_mode; /* file "mode" i.e. prot, dir, reg, etc. */
271         int     st_nlink;       /* for compatibility - not really used */
272         unsigned st_uid;        /* from ACP - QIO uic field */
273         unsigned short st_gid;  /* group number extracted from st_uid */
274         dev_t   st_rdev;        /* for compatibility - always zero */
275         off_t   st_size;        /* file size in bytes */
276         unsigned st_atime;      /* file access time; always same as st_mtime */
277         unsigned st_mtime;      /* last modification time */
278         unsigned st_ctime;      /* file creation time */
279         char    st_fab_rfm;     /* record format */
280         char    st_fab_rat;     /* record attributes */
281         char    st_fab_fsz;     /* fixed header size */
282         unsigned st_dev;        /* encoded device name */
283 };
284 #define stat mystat
285 typedef unsigned mydev_t;
286 #define dev_t mydev_t
287 typedef unsigned myino_t;
288 #define ino_t myino_t
289 #if defined(__DECC) || defined(__DECCXX)
290 #  pragma __member_alignment __restore
291 #endif
292 #if defined(__DECC) 
293 #  pragma __message __restore
294 #endif
295 /* Cons up a 'delete' bit for testing access */
296 #define S_IDUSR (S_IWUSR | S_IXUSR)
297 #define S_IDGRP (S_IWGRP | S_IXGRP)
298 #define S_IDOTH (S_IWOTH | S_IXOTH)
299
300 /* Prototypes for functions unique to vms.c.  Don't include replacements
301  * for routines in the mainline source files excluded by #ifndef VMS;
302  * their prototypes are already in proto.h.
303  *
304  * In order to keep Gen_ShrFls.Pl happy, functions which are to be made
305  * available to images linked to PerlShr.Exe must be declared between the
306  * __VMS_PROTOTYPES__ and __VMS_SEPYTOTORP__ lines, and must be in the form
307  *    <data type><TAB>name<WHITESPACE>_((<prototype args>));
308  */
309 /* prototype section start marker; `typedef' passes through cpp */
310 typedef char  __VMS_PROTOTYPES__;
311 int     my_trnlnm _((char *, char *, unsigned long int));
312 char *  my_getenv _((char *));
313 char *  my_crypt _((const char *, const char *));
314 unsigned long int       waitpid _((unsigned long int, int *, int));
315 char *  my_gconvert _((double, int, int, char *));
316 int     do_rmdir _((char *));
317 int     kill_file _((char *));
318 int     my_utime _((char *, struct utimbuf *));
319 char *  fileify_dirspec _((char *, char *));
320 char *  fileify_dirspec_ts _((char *, char *));
321 char *  pathify_dirspec _((char *, char *));
322 char *  pathify_dirspec_ts _((char *, char *));
323 char *  tounixspec _((char *, char *));
324 char *  tounixspec_ts _((char *, char *));
325 char *  tovmsspec _((char *, char *));
326 char *  tovmsspec_ts _((char *, char *));
327 char *  tounixpath _((char *, char *));
328 char *  tounixpath_ts _((char *, char *));
329 char *  tovmspath _((char *, char *));
330 char *  tovmspath_ts _((char *, char *));
331 void    getredirection _(());
332 DIR *   opendir _((char *));
333 struct dirent * readdir _((DIR *));
334 long    telldir _((DIR *));
335 void    seekdir _((DIR *, long));
336 void    closedir _((DIR *));
337 void    vmsreaddirversions _((DIR *, int));
338 void    getredirection _((int *, char ***));
339 struct tm *my_gmtime _((const time_t *));
340 I32     cando_by_name _((I32, I32, char *));
341 int     flex_fstat _((int, struct stat *));
342 int     flex_stat _((char *, struct stat *));
343 int     trim_unixpath _((char *, char*));
344 bool    vms_do_aexec _((SV *, SV **, SV **));
345 bool    vms_do_exec _((char *));
346 unsigned long int       do_aspawn _((SV *, SV **, SV **));
347 unsigned long int       do_spawn _((char *));
348 int     my_fwrite _((void *, size_t, size_t, FILE *));
349 struct passwd * my_getpwnam _((char *name));
350 struct passwd * my_getpwuid _((Uid_t uid));
351 struct passwd * my_getpwent _(());
352 void    my_endpwent _(());
353 char *  my_getlogin _(());
354 int     rmscopy _((char *, char *));
355 void    init_os_extras _(());
356 typedef char __VMS_SEPYTOTORP__;
357 /* prototype section end marker; `typedef' passes through cpp */
358
359 #ifndef VMS_DO_SOCKETS
360 /* This relies on tricks in perl.h to pick up that these manifest constants
361  * are undefined and set up conversion routines.  It will then redefine
362  * these manifest constants, so the actual values will match config.h
363  */
364 #undef HAS_HTONS
365 #undef HAS_NTOHS
366 #undef HAS_HTONL
367 #undef HAS_NTOHL
368 #endif
369
370 #define TMPPATH "sys$scratch:perl-eXXXXXX"
371
372 #endif  /* __vmsish_h_included */