Commit | Line | Data |
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 */ |
150 | struct 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 | |
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 | |
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 | |
192 | /* Setup for the dirent routines: |
193 | * opendir(), closedir(), readdir(), seekdir(), telldir(), and |
194 | * vmsreaddirversions(), and preprocessor stuff on which these depend: |
195 | * Written by Rich $alz, <rsalz@bbn.com> in August, 1990. |
196 | * This code has no copyright. |
197 | */ |
198 | /* Data structure returned by READDIR(). */ |
199 | struct dirent { |
200 | char d_name[256]; /* File name */ |
201 | int d_namlen; /* Length of d_name */ |
202 | int vms_verscount; /* Number of versions */ |
203 | int vms_versions[20]; /* Version numbers */ |
204 | }; |
205 | |
206 | /* Handle returned by opendir(), used by the other routines. You |
207 | * are not supposed to care what's inside this structure. */ |
208 | typedef struct _dirdesc { |
209 | long context; |
210 | int vms_wantversions; |
211 | unsigned long int count; |
212 | char *pattern; |
213 | struct dirent entry; |
214 | struct dsc$descriptor_s pat; |
215 | } DIR; |
216 | |
217 | #define rewinddir(dirp) seekdir((dirp), 0) |
218 | |
748a9306 |
219 | /* used for our emulation of getpw* */ |
220 | struct passwd { |
221 | char *pw_name; /* Username */ |
222 | char *pw_passwd; |
223 | Uid_t pw_uid; /* UIC member number */ |
224 | Gid_t pw_gid; /* UIC group number */ |
225 | char *pw_comment; /* Default device/directory (Unix-style) */ |
226 | char *pw_gecos; /* Owner */ |
227 | char *pw_dir; /* Default device/directory (VMS-style) */ |
228 | char *pw_shell; /* Default CLI name (eg. DCL) */ |
229 | }; |
230 | #define pw_unixdir pw_comment /* Default device/directory (Unix-style) */ |
231 | #define getpwnam my_getpwnam |
232 | #define getpwuid my_getpwuid |
233 | #define getpwent my_getpwent |
234 | #define endpwent my_endpwent |
235 | #define setpwent my_endpwent |
236 | |
237 | /* Our own stat_t substitute, since we play with st_dev and st_ino - |
238 | * we want atomic types so Unix-bound code which compares these fields |
c07a80fd |
239 | * for two files will work most of the time under VMS. |
240 | * N.B. 1. The st_ino hack assumes that sizeof(unsigned short[3]) == |
241 | * sizeof(unsigned) + sizeof(unsigned short). We can't use a union type |
242 | * to map the unsigned int we want and the unsigned short[3] the CRTL |
243 | * returns into the same member, since gcc has different ideas than DECC |
244 | * and VAXC about sizing union types. |
245 | * N.B 2. The routine cando() in vms.c assumes that &stat.st_ino is the |
246 | * address of a FID. |
748a9306 |
247 | */ |
248 | /* First, grab the system types, so we don't clobber them later */ |
249 | #include <stat.h> |
250 | /* Since we've got to match the size of the CRTL's stat_t, we need |
251 | * to mimic DECC's alignment settings. |
252 | */ |
253 | #if defined(__DECC) || defined(__DECCXX) |
254 | # pragma __member_alignment __save |
255 | # pragma __nomember_alignment |
256 | #endif |
257 | #if defined(__DECC) |
258 | # pragma __message __save |
259 | # pragma __message disable (__MISALGNDSTRCT) |
260 | # pragma __message disable (__MISALGNDMEM) |
261 | #endif |
262 | struct mystat |
263 | { |
264 | char *st_devnam; /* pointer to device name */ |
c07a80fd |
265 | unsigned st_ino; /* hack - CRTL uses unsigned short[3] for */ |
266 | unsigned short rvn; /* FID (num,seq,rvn) */ |
748a9306 |
267 | unsigned short st_mode; /* file "mode" i.e. prot, dir, reg, etc. */ |
268 | int st_nlink; /* for compatibility - not really used */ |
269 | unsigned st_uid; /* from ACP - QIO uic field */ |
270 | unsigned short st_gid; /* group number extracted from st_uid */ |
271 | dev_t st_rdev; /* for compatibility - always zero */ |
272 | off_t st_size; /* file size in bytes */ |
273 | unsigned st_atime; /* file access time; always same as st_mtime */ |
274 | unsigned st_mtime; /* last modification time */ |
275 | unsigned st_ctime; /* file creation time */ |
276 | char st_fab_rfm; /* record format */ |
277 | char st_fab_rat; /* record attributes */ |
278 | char st_fab_fsz; /* fixed header size */ |
279 | unsigned st_dev; /* encoded device name */ |
280 | }; |
748a9306 |
281 | #define stat mystat |
282 | typedef unsigned mydev_t; |
283 | #define dev_t mydev_t |
c07a80fd |
284 | typedef unsigned myino_t; |
748a9306 |
285 | #define ino_t myino_t |
286 | #if defined(__DECC) || defined(__DECCXX) |
287 | # pragma __member_alignment __restore |
288 | #endif |
289 | #if defined(__DECC) |
290 | # pragma __message __restore |
291 | #endif |
292 | /* Cons up a 'delete' bit for testing access */ |
293 | #define S_IDUSR (S_IWUSR | S_IXUSR) |
294 | #define S_IDGRP (S_IWGRP | S_IXGRP) |
295 | #define S_IDOTH (S_IWOTH | S_IXOTH) |
a0d0e21e |
296 | |
297 | /* Prototypes for functions unique to vms.c. Don't include replacements |
298 | * for routines in the mainline source files excluded by #ifndef VMS; |
299 | * their prototypes are already in proto.h. |
300 | * |
301 | * In order to keep Gen_ShrFls.Pl happy, functions which are to be made |
302 | * available to images linked to PerlShr.Exe must be declared between the |
303 | * __VMS_PROTOTYPES__ and __VMS_SEPYTOTORP__ lines, and must be in the form |
304 | * <data type><TAB>name<WHITESPACE>_((<prototype args>)); |
305 | */ |
c07a80fd |
306 | /* prototype section start marker; `typedef' passes through cpp */ |
307 | typedef char __VMS_PROTOTYPES__; |
308 | int my_trnlnm _((char *, char *, unsigned long int)); |
a0d0e21e |
309 | char * my_getenv _((char *)); |
c07a80fd |
310 | char * my_crypt _((const char *, const char *)); |
a0d0e21e |
311 | unsigned long int waitpid _((unsigned long int, int *, int)); |
a0d0e21e |
312 | char * my_gconvert _((double, int, int, char *)); |
313 | int do_rmdir _((char *)); |
314 | int kill_file _((char *)); |
748a9306 |
315 | int my_utime _((char *, struct utimbuf *)); |
a0d0e21e |
316 | char * fileify_dirspec _((char *, char *)); |
317 | char * fileify_dirspec_ts _((char *, char *)); |
318 | char * pathify_dirspec _((char *, char *)); |
319 | char * pathify_dirspec_ts _((char *, char *)); |
320 | char * tounixspec _((char *, char *)); |
321 | char * tounixspec_ts _((char *, char *)); |
322 | char * tovmsspec _((char *, char *)); |
323 | char * tovmsspec_ts _((char *, char *)); |
324 | char * tounixpath _((char *, char *)); |
325 | char * tounixpath_ts _((char *, char *)); |
326 | char * tovmspath _((char *, char *)); |
327 | char * tovmspath_ts _((char *, char *)); |
328 | void getredirection _(()); |
329 | DIR * opendir _((char *)); |
330 | struct dirent * readdir _((DIR *)); |
331 | long telldir _((DIR *)); |
332 | void seekdir _((DIR *, long)); |
333 | void closedir _((DIR *)); |
334 | void vmsreaddirversions _((DIR *, int)); |
335 | void getredirection _((int *, char ***)); |
e518068a |
336 | struct tm *my_gmtime _((const time_t *)); |
748a9306 |
337 | I32 cando_by_name _((I32, I32, char *)); |
338 | int flex_fstat _((int, struct stat *)); |
339 | int flex_stat _((char *, struct stat *)); |
a0d0e21e |
340 | int trim_unixpath _((char *, char*)); |
748a9306 |
341 | bool vms_do_aexec _((SV *, SV **, SV **)); |
a0d0e21e |
342 | bool vms_do_exec _((char *)); |
748a9306 |
343 | unsigned long int do_aspawn _((SV *, SV **, SV **)); |
a0d0e21e |
344 | unsigned long int do_spawn _((char *)); |
345 | int my_fwrite _((void *, size_t, size_t, FILE *)); |
748a9306 |
346 | struct passwd * my_getpwnam _((char *name)); |
347 | struct passwd * my_getpwuid _((Uid_t uid)); |
348 | struct passwd * my_getpwent _(()); |
349 | void my_endpwent _(()); |
c07a80fd |
350 | char * my_getlogin _(()); |
748a9306 |
351 | void init_os_extras _(()); |
c07a80fd |
352 | typedef char __VMS_SEPYTOTORP__; |
353 | /* prototype section end marker; `typedef' passes through cpp */ |
a0d0e21e |
354 | |
355 | #ifndef VMS_DO_SOCKETS |
748a9306 |
356 | /* This relies on tricks in perl.h to pick up that these manifest constants |
357 | * are undefined and set up conversion routines. It will then redefine |
358 | * these manifest constants, so the actual values will match config.h |
359 | */ |
360 | #undef HAS_HTONS |
361 | #undef HAS_NTOHS |
362 | #undef HAS_HTONL |
363 | #undef HAS_NTOHL |
a0d0e21e |
364 | #endif |
365 | |
366 | #endif /* __vmsish_h_included */ |