1 /* File: curl_crtl_init.c
3 * This file makes sure that the DECC Unix settings are correct for
4 * the mode the the program is run in.
6 * The CRTL has not been initialized at the time that these routines
7 * are called, so many routines can not be called.
9 * This is a module that provides a LIB$INITIALIZE routine that
10 * will turn on some CRTL features that are not enabled by default.
12 * The CRTL features can also be turned on via logical names, but that
13 * impacts all programs and some aren't ready, willing, or able to handle
16 * On VMS versions that are too old to use the feature setting API, this
17 * module falls back to using logical names.
19 * Copyright 2013, John Malmberg
21 * Permission to use, copy, modify, and/or distribute this software for any
22 * purpose with or without fee is hereby granted, provided that the above
23 * copyright notice and this permission notice appear in all copies.
25 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
26 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
28 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
31 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
39 /* VMS specific headers */
44 #pragma member_alignment save
45 #pragma nomember_alignment longword
47 #pragma message disable misalgndmem
49 unsigned short int buflen;
50 unsigned short int itmcode;
52 unsigned short int *retlen;
54 #pragma message restore
55 #pragma member_alignment restore
58 #define ENABLE "ENABLE"
59 #define DISABLE "DISABLE"
64 int decc$feature_get_index (const char *name);
65 int decc$feature_set_value (int index, int mode, int value);
69 const unsigned long * attr,
70 const struct dsc$descriptor_s * table_dsc,
71 struct dsc$descriptor_s * name_dsc,
72 const unsigned char * acmode,
73 const struct itmlst_3 * item_list);
75 const unsigned long * attr,
76 const struct dsc$descriptor_s * table_dsc,
77 const struct dsc$descriptor_s * name_dsc,
78 const unsigned char * acmode,
79 const struct itmlst_3 * item_list);
82 /* Take all the fun out of simply looking up a logical name */
84 (const char * logname,
88 const $DESCRIPTOR(table_dsc, "LNM$FILE_DEV");
89 const unsigned long attr = LNM$M_CASE_BLIND;
90 struct dsc$descriptor_s name_dsc;
92 unsigned short result;
93 struct itmlst_3 itlst[2];
95 itlst[0].buflen = value_len;
96 itlst[0].itmcode = LNM$_STRING;
97 itlst[0].bufadr = value;
98 itlst[0].retlen = &result;
101 itlst[1].itmcode = 0;
103 name_dsc.dsc$w_length = strlen(logname);
104 name_dsc.dsc$a_pointer = (char *)logname;
105 name_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
106 name_dsc.dsc$b_class = DSC$K_CLASS_S;
108 status = SYS$TRNLNM(&attr, &table_dsc, &name_dsc, 0, itlst);
110 if ($VMS_STATUS_SUCCESS(status)) {
112 /* Null terminate and return the string */
113 /*--------------------------------------*/
114 value[result] = '\0';
120 /* How to simply create a logical name */
121 static int sys_crelnm
122 (const char * logname,
126 const char * proc_table = "LNM$PROCESS_TABLE";
127 struct dsc$descriptor_s proc_table_dsc;
128 struct dsc$descriptor_s logname_dsc;
129 struct itmlst_3 item_list[2];
131 proc_table_dsc.dsc$a_pointer = (char *) proc_table;
132 proc_table_dsc.dsc$w_length = strlen(proc_table);
133 proc_table_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
134 proc_table_dsc.dsc$b_class = DSC$K_CLASS_S;
136 logname_dsc.dsc$a_pointer = (char *) logname;
137 logname_dsc.dsc$w_length = strlen(logname);
138 logname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
139 logname_dsc.dsc$b_class = DSC$K_CLASS_S;
141 item_list[0].buflen = strlen(value);
142 item_list[0].itmcode = LNM$_STRING;
143 item_list[0].bufadr = (char *)value;
144 item_list[0].retlen = NULL;
146 item_list[1].buflen = 0;
147 item_list[1].itmcode = 0;
149 ret_val = SYS$CRELNM(NULL, &proc_table_dsc, &logname_dsc, NULL, item_list);
155 /* Start of DECC RTL Feature handling */
158 ** Sets default value for a feature
161 static void set_feature_default(const char *name, const char *value)
163 sys_crelnm(name, value);
166 static void set_feature_default(const char *name, int value)
170 index = decc$feature_get_index(name);
173 decc$feature_set_value (index, 0, value);
177 static void set_features(void)
180 char unix_shell_name[255];
181 int use_unix_settings = 1;
183 status = sys_trnlnm("GNV$UNIX_SHELL",
184 unix_shell_name, sizeof unix_shell_name -1);
185 if (!$VMS_STATUS_SUCCESS(status)) {
186 unix_shell_name[0] = 0;
187 use_unix_settings = 0;
190 /* ACCESS should check ACLs or it is lying. */
191 set_feature_default("DECC$ACL_ACCESS_CHECK", ENABLE);
193 /* We always want the new parse style */
194 set_feature_default ("DECC$ARGV_PARSE_STYLE" , ENABLE);
197 /* Unless we are in POSIX compliant mode, we want the old POSIX root
200 set_feature_default("DECC$DISABLE_POSIX_ROOT", DISABLE);
202 /* EFS charset, means UTF-8 support */
203 /* VTF-7 support is controlled by a feature setting called UTF8 */
204 set_feature_default ("DECC$EFS_CHARSET", ENABLE);
205 set_feature_default ("DECC$EFS_CASE_PRESERVE", ENABLE);
207 /* Support timestamps when available */
208 set_feature_default ("DECC$EFS_FILE_TIMESTAMPS", ENABLE);
210 /* Cache environment variables - performance improvements */
211 set_feature_default ("DECC$ENABLE_GETENV_CACHE", ENABLE);
213 /* Start out with new file attribute inheritance */
215 set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", "2");
217 set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", 2);
220 /* Don't display trailing dot after files without type */
221 set_feature_default ("DECC$READDIR_DROPDOTNOTYPE", ENABLE);
223 /* For standard output channels buffer output until terminator */
224 /* Gets rid of output logs with single character lines in them. */
225 set_feature_default ("DECC$STDIO_CTX_EOL", ENABLE);
227 /* Fix mv aa.bb aa */
228 set_feature_default ("DECC$RENAME_NO_INHERIT", ENABLE);
230 if (use_unix_settings) {
232 /* POSIX requires that open files be able to be removed */
233 set_feature_default ("DECC$ALLOW_REMOVE_OPEN_FILES", ENABLE);
235 /* Default to outputting Unix filenames in VMS routines */
236 set_feature_default ("DECC$FILENAME_UNIX_ONLY", ENABLE);
237 /* FILENAME_UNIX_ONLY Implicitly sets */
238 /* decc$disable_to_vms_logname_translation */
240 set_feature_default ("DECC$FILE_PERMISSION_UNIX", ENABLE);
242 set_feature_default ("DECC$FILE_SHARING", ENABLE);
244 set_feature_default ("DECC$FILE_OWNER_UNIX", ENABLE);
245 set_feature_default ("DECC$POSIX_SEEK_STREAM_FILE", ENABLE);
248 set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE);
251 /* When reporting Unix filenames, glob the same way */
252 set_feature_default ("DECC$GLOB_UNIX_STYLE", ENABLE);
254 /* The VMS version numbers on Unix filenames is incompatible with most */
255 /* ported packages. */
256 set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE);
258 /* The VMS version numbers on Unix filenames is incompatible with most */
259 /* ported packages. */
260 set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE);
262 /* Set strtol to proper behavior */
263 set_feature_default("DECC$STRTOL_ERANGE", ENABLE);
265 /* Commented here to prevent future bugs: A program or user should */
266 /* never ever enable DECC$POSIX_STYLE_UID. */
267 /* It will probably break all code that accesses UIDs */
268 /* do_not_set_default ("DECC$POSIX_STYLE_UID", TRUE); */
272 /* Some boilerplate to force this to be a proper LIB$INITIALIZE section */
275 #pragma extern_model save
277 #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic
279 #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long
280 # if __INITIAL_POINTER_SIZE
281 # pragma __pointer_size __save
282 # pragma __pointer_size 32
284 # pragma __required_pointer_size __save
285 # pragma __required_pointer_size 32
288 /* Set our contribution to the LIB$INITIALIZE array */
289 void (* const iniarray[])(void) = {set_features, } ;
291 # if __INITIAL_POINTER_SIZE
292 # pragma __pointer_size __restore
294 # pragma __required_pointer_size __restore
300 ** Force a reference to LIB$INITIALIZE to ensure it
301 ** exists in the image.
303 int LIB$INITIALIZE(void);
305 #pragma extern_model strict_refdef
307 int lib_init_ref = (int) LIB$INITIALIZE;
309 #pragma extern_model restore