Path: blob/main/external/curl/packages/vms/curl_crtl_init.c
2066 views
/***************************************************************************1* _ _ ____ _2* Project ___| | | | _ \| |3* / __| | | | |_) | |4* | (__| |_| | _ <| |___5* \___|\___/|_| \_\_____|6*7* Copyright (C) Daniel Stenberg, <[email protected]>, et al.8*9* This software is licensed as described in the file COPYING, which10* you should have received as part of this distribution. The terms11* are also available at https://curl.se/docs/copyright.html.12*13* You may opt to use, copy, modify, merge, publish, distribute and/or sell14* copies of the Software, and permit persons to whom the Software is15* furnished to do so, under the terms of the COPYING file.16*17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY18* KIND, either express or implied.19*20* SPDX-License-Identifier: curl21*22***************************************************************************/23/* File: curl_crtl_init.c24*25* This file makes sure that the DECC Unix settings are correct for26* the mode the program is run in.27*28* The CRTL has not been initialized at the time that these routines29* are called, so many routines can not be called.30*31* This is a module that provides a LIB$INITIALIZE routine that32* will turn on some CRTL features that are not enabled by default.33*34* The CRTL features can also be turned on via logical names, but that35* impacts all programs and some aren't ready, willing, or able to handle36* those settings.37*38* On VMS versions that are too old to use the feature setting API, this39* module falls back to using logical names.40*41* Copyright (C) John Malmberg42*43* Permission to use, copy, modify, and/or distribute this software for any44* purpose with or without fee is hereby granted, provided that the above45* copyright notice and this permission notice appear in all copies.46*47* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES48* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF49* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR50* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES51* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN52* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT53* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.54*55*/5657/* Unix headers */58#include <stdio.h>59#include <string.h>6061/* VMS specific headers */62#include <descrip.h>63#include <lnmdef.h>64#include <stsdef.h>6566#pragma member_alignment save67#pragma nomember_alignment longword68#pragma message save69#pragma message disable misalgndmem70struct itmlst_3 {71unsigned short int buflen;72unsigned short int itmcode;73void *bufadr;74unsigned short int *retlen;75};76#pragma message restore77#pragma member_alignment restore7879#ifdef __VAX80#define ENABLE "ENABLE"81#define DISABLE "DISABLE"82#else8384#define ENABLE TRUE85#define DISABLE 086int decc$feature_get_index (const char *name);87int decc$feature_set_value (int index, int mode, int value);88#endif8990int SYS$TRNLNM(91const unsigned long *attr,92const struct dsc$descriptor_s *table_dsc,93struct dsc$descriptor_s *name_dsc,94const unsigned char *acmode,95const struct itmlst_3 *item_list);96int SYS$CRELNM(97const unsigned long *attr,98const struct dsc$descriptor_s *table_dsc,99const struct dsc$descriptor_s *name_dsc,100const unsigned char *acmode,101const struct itmlst_3 *item_list);102103104/* Take all the fun out of simply looking up a logical name */105static int sys_trnlnm(const char *logname,106char *value,107int value_len)108{109const $DESCRIPTOR(table_dsc, "LNM$FILE_DEV");110const unsigned long attr = LNM$M_CASE_BLIND;111struct dsc$descriptor_s name_dsc;112int status;113unsigned short result;114struct itmlst_3 itlst[2];115116itlst[0].buflen = value_len;117itlst[0].itmcode = LNM$_STRING;118itlst[0].bufadr = value;119itlst[0].retlen = &result;120121itlst[1].buflen = 0;122itlst[1].itmcode = 0;123124name_dsc.dsc$w_length = strlen(logname);125name_dsc.dsc$a_pointer = (char *)logname;126name_dsc.dsc$b_dtype = DSC$K_DTYPE_T;127name_dsc.dsc$b_class = DSC$K_CLASS_S;128129status = SYS$TRNLNM(&attr, &table_dsc, &name_dsc, 0, itlst);130131if($VMS_STATUS_SUCCESS(status)) {132133/* Null-terminate and return the string */134/*--------------------------------------*/135value[result] = '\0';136}137138return status;139}140141/* How to simply create a logical name */142static int sys_crelnm(const char *logname,143const char *value)144{145int ret_val;146const char *proc_table = "LNM$PROCESS_TABLE";147struct dsc$descriptor_s proc_table_dsc;148struct dsc$descriptor_s logname_dsc;149struct itmlst_3 item_list[2];150151proc_table_dsc.dsc$a_pointer = (char *) proc_table;152proc_table_dsc.dsc$w_length = strlen(proc_table);153proc_table_dsc.dsc$b_dtype = DSC$K_DTYPE_T;154proc_table_dsc.dsc$b_class = DSC$K_CLASS_S;155156logname_dsc.dsc$a_pointer = (char *) logname;157logname_dsc.dsc$w_length = strlen(logname);158logname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;159logname_dsc.dsc$b_class = DSC$K_CLASS_S;160161item_list[0].buflen = strlen(value);162item_list[0].itmcode = LNM$_STRING;163item_list[0].bufadr = (char *)value;164item_list[0].retlen = NULL;165166item_list[1].buflen = 0;167item_list[1].itmcode = 0;168169ret_val = SYS$CRELNM(NULL, &proc_table_dsc, &logname_dsc, NULL, item_list);170171return ret_val;172}173174175/* Start of DECC RTL Feature handling */176177/*178** Sets default value for a feature179*/180#ifdef __VAX181static void set_feature_default(const char *name, const char *value)182{183sys_crelnm(name, value);184}185#else186static void set_feature_default(const char *name, int value)187{188int index;189190index = decc$feature_get_index(name);191192if(index > 0)193decc$feature_set_value (index, 0, value);194}195#endif196197static void set_features(void)198{199int status;200char unix_shell_name[255];201int use_unix_settings = 1;202203status = sys_trnlnm("GNV$UNIX_SHELL",204unix_shell_name, sizeof(unix_shell_name) -1);205if(!$VMS_STATUS_SUCCESS(status)) {206use_unix_settings = 0;207}208209/* ACCESS should check ACLs or it is lying. */210set_feature_default("DECC$ACL_ACCESS_CHECK", ENABLE);211212/* We always want the new parse style */213set_feature_default("DECC$ARGV_PARSE_STYLE", ENABLE);214215216/* Unless we are in POSIX compliant mode, we want the old POSIX root217* enabled.218*/219set_feature_default("DECC$DISABLE_POSIX_ROOT", DISABLE);220221/* EFS charset, means UTF-8 support */222/* VTF-7 support is controlled by a feature setting called UTF8 */223set_feature_default("DECC$EFS_CHARSET", ENABLE);224set_feature_default("DECC$EFS_CASE_PRESERVE", ENABLE);225226/* Support timestamps when available */227set_feature_default("DECC$EFS_FILE_TIMESTAMPS", ENABLE);228229/* Cache environment variables - performance improvements */230set_feature_default("DECC$ENABLE_GETENV_CACHE", ENABLE);231232/* Start out with new file attribute inheritance */233#ifdef __VAX234set_feature_default("DECC$EXEC_FILEATTR_INHERITANCE", "2");235#else236set_feature_default("DECC$EXEC_FILEATTR_INHERITANCE", 2);237#endif238239/* Don't display trailing dot after files without type */240set_feature_default("DECC$READDIR_DROPDOTNOTYPE", ENABLE);241242/* For standard output channels buffer output until terminator */243/* Gets rid of output logs with single character lines in them. */244set_feature_default("DECC$STDIO_CTX_EOL", ENABLE);245246/* Fix mv aa.bb aa */247set_feature_default("DECC$RENAME_NO_INHERIT", ENABLE);248249if(use_unix_settings) {250251/* POSIX requires that open files be able to be removed */252set_feature_default("DECC$ALLOW_REMOVE_OPEN_FILES", ENABLE);253254/* Default to outputting Unix filenames in VMS routines */255set_feature_default("DECC$FILENAME_UNIX_ONLY", ENABLE);256/* FILENAME_UNIX_ONLY Implicitly sets */257/* decc$disable_to_vms_logname_translation */258259set_feature_default("DECC$FILE_PERMISSION_UNIX", ENABLE);260261set_feature_default("DECC$FILE_SHARING", ENABLE);262263set_feature_default("DECC$FILE_OWNER_UNIX", ENABLE);264set_feature_default("DECC$POSIX_SEEK_STREAM_FILE", ENABLE);265266}267else {268set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE);269}270271/* When reporting Unix filenames, glob the same way */272set_feature_default("DECC$GLOB_UNIX_STYLE", ENABLE);273274/* The VMS version numbers on Unix filenames is incompatible with most */275/* ported packages. */276set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE);277278/* The VMS version numbers on Unix filenames is incompatible with most */279/* ported packages. */280set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE);281282/* Set strtol to proper behavior */283set_feature_default("DECC$STRTOL_ERANGE", ENABLE);284285/* Commented here to prevent future bugs: A program or user should */286/* never ever enable DECC$POSIX_STYLE_UID. */287/* It will probably break all code that accesses UIDs */288/* do_not_set_default ("DECC$POSIX_STYLE_UID", TRUE); */289}290291292/* Some boilerplate to force this to be a proper LIB$INITIALIZE section */293294#pragma nostandard295#pragma extern_model save296#ifdef __VAX297#pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic298#else299#pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long300# if __INITIAL_POINTER_SIZE301# pragma __pointer_size __save302# pragma __pointer_size 32303# else304# pragma __required_pointer_size __save305# pragma __required_pointer_size 32306# endif307#endif308/* Set our contribution to the LIB$INITIALIZE array */309void (* const iniarray[])(void) = {set_features };310#ifndef __VAX311# if __INITIAL_POINTER_SIZE312# pragma __pointer_size __restore313# else314# pragma __required_pointer_size __restore315# endif316#endif317318319/*320** Force a reference to LIB$INITIALIZE to ensure it321** exists in the image.322*/323int LIB$INITIALIZE(void);324#ifdef __DECC325#pragma extern_model strict_refdef326#endif327int lib_init_ref = (int) LIB$INITIALIZE;328#ifdef __DECC329#pragma extern_model restore330#pragma standard331#endif332333334