Change to use $^O and &Cwd:cwd
[p5sagit/p5-mst-13.2.git] / vms / vmsish.h
CommitLineData
a0d0e21e 1/* vmsish.h
2 *
3 * VMS-specific C header file for perl5.
4 *
e518068a 5 * Last revised: 01-Oct-1995 by Charles Bailey bailey@genetics.upenn.edu
c07a80fd 6 * Version: 5.1.6
a0d0e21e 7 */
8
9#ifndef __vmsish_h_included
10#define __vmsish_h_included
11
12#include <descrip.h> /* for dirent struct definitions */
748a9306 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
4633a7c4 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
e518068a 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
748a9306 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)
4633a7c4 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 */
a0d0e21e 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
748a9306 58#endif
a0d0e21e 59#include <processes.h> /* for vfork() */
60#include <unixio.h>
a0d0e21e 61#include <unixlib.h>
62#include <file.h> /* it's not <sys/file.h>, so don't use I_SYS_FILE */
748a9306 63#define unlink kill_file
64
e518068a 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
748a9306 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. */
e518068a 82#define _ckvmssts(call) do { register unsigned long int __ckvms_sts; \
748a9306 83 if (!((__ckvms_sts=(call))&1)) { \
84 set_errno(EVMSERR); set_vaxc_errno(__ckvms_sts); \
e518068a 85 croak("Fatal VMS error (status=%d) at %s, line %d", \
86 __ckvms_sts,__FILE__,__LINE__); } } while (0);
a0d0e21e 87
88#ifdef VMS_DO_SOCKETS
89#include "sockadapt.h"
90#endif
91
c07a80fd 92#define BIT_BUCKET "_NLA0:"
93#define PERL_SYS_INIT(c,v) getredirection((c),(v))
a0d0e21e 94#define HAS_KILL
95#define HAS_WAIT
96
e518068a 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
a0d0e21e 108 */
e518068a 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 /**/
a0d0e21e 116
e518068a 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
a0d0e21e 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
748a9306 149/* Used with our my_utime() routine in vms.c */
150struct utimbuf {
151 time_t actime;
152 time_t modtime;
153};
154#define utime my_utime
155
a0d0e21e 156/* This is what times() returns, but <times.h> calls it tbuffer_t on VMS */
157
158struct 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
e518068a 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
a0d0e21e 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
c07a80fd 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
a0d0e21e 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
a5f75d66 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
a0d0e21e 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(). */
202struct 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. */
211typedef 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
748a9306 222/* used for our emulation of getpw* */
223struct 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
c07a80fd 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.
748a9306 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
265struct mystat
266{
267 char *st_devnam; /* pointer to device name */
c07a80fd 268 unsigned st_ino; /* hack - CRTL uses unsigned short[3] for */
269 unsigned short rvn; /* FID (num,seq,rvn) */
748a9306 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};
748a9306 284#define stat mystat
285typedef unsigned mydev_t;
286#define dev_t mydev_t
c07a80fd 287typedef unsigned myino_t;
748a9306 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)
a0d0e21e 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 */
c07a80fd 309/* prototype section start marker; `typedef' passes through cpp */
310typedef char __VMS_PROTOTYPES__;
311int my_trnlnm _((char *, char *, unsigned long int));
a0d0e21e 312char * my_getenv _((char *));
c07a80fd 313char * my_crypt _((const char *, const char *));
a0d0e21e 314unsigned long int waitpid _((unsigned long int, int *, int));
a0d0e21e 315char * my_gconvert _((double, int, int, char *));
316int do_rmdir _((char *));
317int kill_file _((char *));
748a9306 318int my_utime _((char *, struct utimbuf *));
a0d0e21e 319char * fileify_dirspec _((char *, char *));
320char * fileify_dirspec_ts _((char *, char *));
321char * pathify_dirspec _((char *, char *));
322char * pathify_dirspec_ts _((char *, char *));
323char * tounixspec _((char *, char *));
324char * tounixspec_ts _((char *, char *));
325char * tovmsspec _((char *, char *));
326char * tovmsspec_ts _((char *, char *));
327char * tounixpath _((char *, char *));
328char * tounixpath_ts _((char *, char *));
329char * tovmspath _((char *, char *));
330char * tovmspath_ts _((char *, char *));
331void getredirection _(());
332DIR * opendir _((char *));
333struct dirent * readdir _((DIR *));
334long telldir _((DIR *));
335void seekdir _((DIR *, long));
336void closedir _((DIR *));
337void vmsreaddirversions _((DIR *, int));
338void getredirection _((int *, char ***));
e518068a 339struct tm *my_gmtime _((const time_t *));
748a9306 340I32 cando_by_name _((I32, I32, char *));
341int flex_fstat _((int, struct stat *));
342int flex_stat _((char *, struct stat *));
a0d0e21e 343int trim_unixpath _((char *, char*));
748a9306 344bool vms_do_aexec _((SV *, SV **, SV **));
a0d0e21e 345bool vms_do_exec _((char *));
748a9306 346unsigned long int do_aspawn _((SV *, SV **, SV **));
a0d0e21e 347unsigned long int do_spawn _((char *));
348int my_fwrite _((void *, size_t, size_t, FILE *));
748a9306 349struct passwd * my_getpwnam _((char *name));
350struct passwd * my_getpwuid _((Uid_t uid));
351struct passwd * my_getpwent _(());
352void my_endpwent _(());
c07a80fd 353char * my_getlogin _(());
a5f75d66 354int rmscopy _((char *, char *));
748a9306 355void init_os_extras _(());
c07a80fd 356typedef char __VMS_SEPYTOTORP__;
357/* prototype section end marker; `typedef' passes through cpp */
a0d0e21e 358
359#ifndef VMS_DO_SOCKETS
748a9306 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
a0d0e21e 368#endif
369
482b294c 370#define TMPPATH "sys$scratch:perl-eXXXXXX"
371
a0d0e21e 372#endif /* __vmsish_h_included */