Updated for VMS.
[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.2.b1
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 HAS_KILL
93 #define HAS_WAIT
94
95 /* VMS:
96  *      This symbol, if defined, indicates that the program is running under
97  *      VMS.  It's a symbol automagically defined by all VMS C compilers I've seen.
98  * Just in case, however . . . */
99 #ifndef VMS
100 #define VMS             /**/
101 #endif
102
103 /* HAS_IOCTL:
104  *      This symbol, if defined, indicates that the ioctl() routine is
105  *      available to set I/O characteristics
106  */
107 #undef  HAS_IOCTL               /**/
108  
109 /* HAS_UTIME:
110  *      This symbol, if defined, indicates that the routine utime() is
111  *      available to update the access and modification times of files.
112  */
113 #define HAS_UTIME               /**/
114
115 /* HAS_GROUP
116  *      This symbol, if defined, indicates that the getgrnam(),
117  *      getgrgid(), and getgrent() routines are available to 
118  *      get group entries.
119  */
120 #undef HAS_GROUP                /**/
121
122 /* HAS_PASSWD
123  *      This symbol, if defined, indicates that the getpwnam(),
124  *      getpwuid(), and getpwent() routines are available to 
125  *      get password entries.
126  */
127 #define HAS_PASSWD              /**/
128
129 #define HAS_KILL
130 #define HAS_WAIT
131   
132 /*
133  * fwrite1() should be a routine with the same calling sequence as fwrite(),
134  * but which outputs all of the bytes requested as a single stream (unlike
135  * fwrite() itself, which on some systems outputs several distinct records
136  * if the number_of_items parameter is >1).
137  */
138 #define fwrite1 my_fwrite
139
140 /* Use our own rmdir() */
141 #define rmdir(name) do_rmdir(name)
142
143 /* Assorted fiddling with sigs . . . */
144 # include <signal.h>
145 #define ABORT() abort()
146
147 /* Used with our my_utime() routine in vms.c */
148 struct utimbuf {
149   time_t actime;
150   time_t modtime;
151 };
152 #define utime my_utime
153
154 /* This is what times() returns, but <times.h> calls it tbuffer_t on VMS */
155
156 struct tms {
157   clock_t tms_utime;    /* user time */
158   clock_t tms_stime;    /* system time - always 0 on VMS */
159   clock_t tms_cutime;   /* user time, children */
160   clock_t tms_cstime;   /* system time, children - always 0 on VMS */
161 };
162
163 /* Prior to VMS 7.0, the CRTL gmtime() routine was a stub which always
164  * returned NULL.  Substitute our own routine, which uses the logical
165  * SYS$TIMEZONE_DIFFERENTIAL, whcih the native UTC support routines
166  * in VMS 6.0 or later use.*
167  */
168 #define gmtime(t) my_gmtime(t)
169
170 /* VMS doesn't use a real sys_nerr, but we need this when scanning for error
171  * messages in text strings . . .
172  */
173
174 #define sys_nerr EVMSERR  /* EVMSERR is as high as we can go. */
175
176 /* Look up new %ENV values on the fly */
177 #define DYNAMIC_ENV_FETCH 1
178 #define ENV_HV_NAME "%EnV%VmS%"
179
180 /* Use our own stat() clones, which handle Unix-style directory names */
181 #define Stat(name,bufptr) flex_stat(name,bufptr)
182 #define Fstat(fd,bufptr) flex_fstat(fd,bufptr)
183
184 /* Setup for the dirent routines:
185  * opendir(), closedir(), readdir(), seekdir(), telldir(), and
186  * vmsreaddirversions(), and preprocessor stuff on which these depend:
187  *    Written by Rich $alz, <rsalz@bbn.com> in August, 1990.
188  *    This code has no copyright.
189  */
190     /* Data structure returned by READDIR(). */
191 struct dirent {
192     char        d_name[256];            /* File name            */
193     int         d_namlen;                       /* Length of d_name */
194     int         vms_verscount;          /* Number of versions   */
195     int         vms_versions[20];       /* Version numbers      */
196 };
197
198     /* Handle returned by opendir(), used by the other routines.  You
199      * are not supposed to care what's inside this structure. */
200 typedef struct _dirdesc {
201     long                        context;
202     int                         vms_wantversions;
203     unsigned long int           count;
204     char                        *pattern;
205     struct dirent               entry;
206     struct dsc$descriptor_s     pat;
207 } DIR;
208
209 #define rewinddir(dirp)         seekdir((dirp), 0)
210
211 /* used for our emulation of getpw* */
212 struct passwd {
213         char    *pw_name;    /* Username */
214         char    *pw_passwd;
215         Uid_t   pw_uid;      /* UIC member number */
216         Gid_t   pw_gid;      /* UIC group  number */
217         char    *pw_comment; /* Default device/directory (Unix-style) */
218         char    *pw_gecos;   /* Owner */
219         char    *pw_dir;     /* Default device/directory (VMS-style) */
220         char    *pw_shell;   /* Default CLI name (eg. DCL) */
221 };
222 #define pw_unixdir pw_comment  /* Default device/directory (Unix-style) */
223 #define getpwnam my_getpwnam
224 #define getpwuid my_getpwuid
225 #define getpwent my_getpwent
226 #define endpwent my_endpwent
227 #define setpwent my_endpwent
228
229 /* Our own stat_t substitute, since we play with st_dev and st_ino -
230  * we want atomic types so Unix-bound code which compares these fields
231  * for two files will work most of the time under VMS
232  */
233 /* First, grab the system types, so we don't clobber them later */
234 #include <stat.h>
235 /* Since we've got to match the size of the CRTL's stat_t, we need
236  * to mimic DECC's alignment settings.
237  */
238 #if defined(__DECC) || defined(__DECCXX)
239 #  pragma __member_alignment __save
240 #  pragma __nomember_alignment
241 #endif
242 #if defined(__DECC) 
243 #  pragma __message __save
244 #  pragma __message disable (__MISALGNDSTRCT)
245 #  pragma __message disable (__MISALGNDMEM)
246 #endif
247 struct mystat
248 {
249         char *st_devnam;  /* pointer to device name */
250         union {
251           unsigned short fid[3];
252           unsigned long st_ino_mostly;
253         } st_inode_u;
254         unsigned short st_mode; /* file "mode" i.e. prot, dir, reg, etc. */
255         int     st_nlink;       /* for compatibility - not really used */
256         unsigned st_uid;        /* from ACP - QIO uic field */
257         unsigned short st_gid;  /* group number extracted from st_uid */
258         dev_t   st_rdev;        /* for compatibility - always zero */
259         off_t   st_size;        /* file size in bytes */
260         unsigned st_atime;      /* file access time; always same as st_mtime */
261         unsigned st_mtime;      /* last modification time */
262         unsigned st_ctime;      /* file creation time */
263         char    st_fab_rfm;     /* record format */
264         char    st_fab_rat;     /* record attributes */
265         char    st_fab_fsz;     /* fixed header size */
266         unsigned st_dev;        /* encoded device name */
267 };
268 #ifdef st_ino
269 #  undef st_ino
270 #endif
271 #define st_ino st_inode_u.st_ino_mostly
272 #define stat mystat
273 typedef unsigned mydev_t;
274 #define dev_t mydev_t
275 typedef unsigned long myino_t;
276 #define ino_t myino_t
277 #if defined(__DECC) || defined(__DECCXX)
278 #  pragma __member_alignment __restore
279 #endif
280 #if defined(__DECC) 
281 #  pragma __message __restore
282 #endif
283 /* Cons up a 'delete' bit for testing access */
284 #define S_IDUSR (S_IWUSR | S_IXUSR)
285 #define S_IDGRP (S_IWGRP | S_IXGRP)
286 #define S_IDOTH (S_IWOTH | S_IXOTH)
287
288 /* Prototypes for functions unique to vms.c.  Don't include replacements
289  * for routines in the mainline source files excluded by #ifndef VMS;
290  * their prototypes are already in proto.h.
291  *
292  * In order to keep Gen_ShrFls.Pl happy, functions which are to be made
293  * available to images linked to PerlShr.Exe must be declared between the
294  * __VMS_PROTOTYPES__ and __VMS_SEPYTOTORP__ lines, and must be in the form
295  *    <data type><TAB>name<WHITESPACE>_((<prototype args>));
296  */
297 typedef char  __VMS_PROTOTYPES__; /* prototype section start marker */
298 char *  my_getenv _((char *));
299 unsigned long int       waitpid _((unsigned long int, int *, int));
300 char *  my_gconvert _((double, int, int, char *));
301 int     do_rmdir _((char *));
302 int     kill_file _((char *));
303 int     my_utime _((char *, struct utimbuf *));
304 char *  fileify_dirspec _((char *, char *));
305 char *  fileify_dirspec_ts _((char *, char *));
306 char *  pathify_dirspec _((char *, char *));
307 char *  pathify_dirspec_ts _((char *, char *));
308 char *  tounixspec _((char *, char *));
309 char *  tounixspec_ts _((char *, char *));
310 char *  tovmsspec _((char *, char *));
311 char *  tovmsspec_ts _((char *, char *));
312 char *  tounixpath _((char *, char *));
313 char *  tounixpath_ts _((char *, char *));
314 char *  tovmspath _((char *, char *));
315 char *  tovmspath_ts _((char *, char *));
316 void    getredirection _(());
317 DIR *   opendir _((char *));
318 struct dirent * readdir _((DIR *));
319 long    telldir _((DIR *));
320 void    seekdir _((DIR *, long));
321 void    closedir _((DIR *));
322 void    vmsreaddirversions _((DIR *, int));
323 void    getredirection _((int *, char ***));
324 struct tm *my_gmtime _((const time_t *));
325 I32     cando_by_name _((I32, I32, char *));
326 int     flex_fstat _((int, struct stat *));
327 int     flex_stat _((char *, struct stat *));
328 int     trim_unixpath _((char *, char*));
329 bool    vms_do_aexec _((SV *, SV **, SV **));
330 bool    vms_do_exec _((char *));
331 unsigned long int       do_aspawn _((SV *, SV **, SV **));
332 unsigned long int       do_spawn _((char *));
333 int     my_fwrite _((void *, size_t, size_t, FILE *));
334 struct passwd * my_getpwnam _((char *name));
335 struct passwd * my_getpwuid _((Uid_t uid));
336 struct passwd * my_getpwent _(());
337 void    my_endpwent _(());
338 void    init_os_extras _(());
339 typedef char __VMS_SEPYTOTORP__; /* prototype section end marker */
340
341 #ifndef VMS_DO_SOCKETS
342 /* This relies on tricks in perl.h to pick up that these manifest constants
343  * are undefined and set up conversion routines.  It will then redefine
344  * these manifest constants, so the actual values will match config.h
345  */
346 #undef HAS_HTONS
347 #undef HAS_NTOHS
348 #undef HAS_HTONL
349 #undef HAS_NTOHL
350 #endif
351
352 #endif  /* __vmsish_h_included */