curl_crtl_init.c
Go to the documentation of this file.
00001 /* File: curl_crtl_init.c
00002  *
00003  * This file makes sure that the DECC Unix settings are correct for
00004  * the mode the the program is run in.
00005  *
00006  * The CRTL has not been initialized at the time that these routines
00007  * are called, so many routines can not be called.
00008  *
00009  * This is a module that provides a LIB$INITIALIZE routine that
00010  * will turn on some CRTL features that are not enabled by default.
00011  *
00012  * The CRTL features can also be turned on via logical names, but that
00013  * impacts all programs and some aren't ready, willing, or able to handle
00014  * those settings.
00015  *
00016  * On VMS versions that are too old to use the feature setting API, this
00017  * module falls back to using logical names.
00018  *
00019  * Copyright 2013, John Malmberg
00020  *
00021  * Permission to use, copy, modify, and/or distribute this software for any
00022  * purpose with or without fee is hereby granted, provided that the above
00023  * copyright notice and this permission notice appear in all copies.
00024  *
00025  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00026  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00027  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00028  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00029  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00030  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00031  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00032  *
00033  */
00034 
00035 /* Unix headers */
00036 #include <stdio.h>
00037 #include <string.h>
00038 
00039 /* VMS specific headers */
00040 #include <descrip.h>
00041 #include <lnmdef.h>
00042 #include <stsdef.h>
00043 
00044 #pragma member_alignment save
00045 #pragma nomember_alignment longword
00046 #pragma message save
00047 #pragma message disable misalgndmem
00048 struct itmlst_3 {
00049   unsigned short int buflen;
00050   unsigned short int itmcode;
00051   void *bufadr;
00052   unsigned short int *retlen;
00053 };
00054 #pragma message restore
00055 #pragma member_alignment restore
00056 
00057 #ifdef __VAX
00058 #define ENABLE "ENABLE"
00059 #define DISABLE "DISABLE"
00060 #else
00061 
00062 #define ENABLE TRUE
00063 #define DISABLE 0
00064 int   decc$feature_get_index (const char *name);
00065 int   decc$feature_set_value (int index, int mode, int value);
00066 #endif
00067 
00068 int   SYS$TRNLNM(
00069     const unsigned long * attr,
00070     const struct dsc$descriptor_s * table_dsc,
00071     struct dsc$descriptor_s * name_dsc,
00072     const unsigned char * acmode,
00073     const struct itmlst_3 * item_list);
00074 int   SYS$CRELNM(
00075     const unsigned long * attr,
00076     const struct dsc$descriptor_s * table_dsc,
00077     const struct dsc$descriptor_s * name_dsc,
00078     const unsigned char * acmode,
00079     const struct itmlst_3 * item_list);
00080 
00081 
00082 /* Take all the fun out of simply looking up a logical name */
00083 static int sys_trnlnm
00084    (const char * logname,
00085     char * value,
00086     int value_len)
00087 {
00088     const $DESCRIPTOR(table_dsc, "LNM$FILE_DEV");
00089     const unsigned long attr = LNM$M_CASE_BLIND;
00090     struct dsc$descriptor_s name_dsc;
00091     int status;
00092     unsigned short result;
00093     struct itmlst_3 itlst[2];
00094 
00095     itlst[0].buflen = value_len;
00096     itlst[0].itmcode = LNM$_STRING;
00097     itlst[0].bufadr = value;
00098     itlst[0].retlen = &result;
00099 
00100     itlst[1].buflen = 0;
00101     itlst[1].itmcode = 0;
00102 
00103     name_dsc.dsc$w_length = strlen(logname);
00104     name_dsc.dsc$a_pointer = (char *)logname;
00105     name_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
00106     name_dsc.dsc$b_class = DSC$K_CLASS_S;
00107 
00108     status = SYS$TRNLNM(&attr, &table_dsc, &name_dsc, 0, itlst);
00109 
00110     if ($VMS_STATUS_SUCCESS(status)) {
00111 
00112          /* Null terminate and return the string */
00113         /*--------------------------------------*/
00114         value[result] = '\0';
00115     }
00116 
00117     return status;
00118 }
00119 
00120 /* How to simply create a logical name */
00121 static int sys_crelnm
00122    (const char * logname,
00123     const char * value)
00124 {
00125     int ret_val;
00126     const char * proc_table = "LNM$PROCESS_TABLE";
00127     struct dsc$descriptor_s proc_table_dsc;
00128     struct dsc$descriptor_s logname_dsc;
00129     struct itmlst_3 item_list[2];
00130 
00131     proc_table_dsc.dsc$a_pointer = (char *) proc_table;
00132     proc_table_dsc.dsc$w_length = strlen(proc_table);
00133     proc_table_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
00134     proc_table_dsc.dsc$b_class = DSC$K_CLASS_S;
00135 
00136     logname_dsc.dsc$a_pointer = (char *) logname;
00137     logname_dsc.dsc$w_length = strlen(logname);
00138     logname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
00139     logname_dsc.dsc$b_class = DSC$K_CLASS_S;
00140 
00141     item_list[0].buflen = strlen(value);
00142     item_list[0].itmcode = LNM$_STRING;
00143     item_list[0].bufadr = (char *)value;
00144     item_list[0].retlen = NULL;
00145 
00146     item_list[1].buflen = 0;
00147     item_list[1].itmcode = 0;
00148 
00149     ret_val = SYS$CRELNM(NULL, &proc_table_dsc, &logname_dsc, NULL, item_list);
00150 
00151     return ret_val;
00152 }
00153 
00154 
00155  /* Start of DECC RTL Feature handling */
00156 
00157 /*
00158 ** Sets default value for a feature
00159 */
00160 #ifdef __VAX
00161 static void set_feature_default(const char *name, const char *value)
00162 {
00163     sys_crelnm(name, value);
00164 }
00165 #else
00166 static void set_feature_default(const char *name, int value)
00167 {
00168     int index;
00169 
00170     index = decc$feature_get_index(name);
00171 
00172     if (index > 0)
00173         decc$feature_set_value (index, 0, value);
00174 }
00175 #endif
00176 
00177 static void set_features(void)
00178 {
00179     int status;
00180     char unix_shell_name[255];
00181     int use_unix_settings = 1;
00182 
00183     status = sys_trnlnm("GNV$UNIX_SHELL",
00184                         unix_shell_name, sizeof unix_shell_name -1);
00185     if (!$VMS_STATUS_SUCCESS(status)) {
00186         unix_shell_name[0] = 0;
00187         use_unix_settings = 0;
00188     }
00189 
00190     /* ACCESS should check ACLs or it is lying. */
00191     set_feature_default("DECC$ACL_ACCESS_CHECK", ENABLE);
00192 
00193     /* We always want the new parse style */
00194     set_feature_default ("DECC$ARGV_PARSE_STYLE" , ENABLE);
00195 
00196 
00197     /* Unless we are in POSIX compliant mode, we want the old POSIX root
00198      * enabled.
00199      */
00200     set_feature_default("DECC$DISABLE_POSIX_ROOT", DISABLE);
00201 
00202     /* EFS charset, means UTF-8 support */
00203     /* VTF-7 support is controlled by a feature setting called UTF8 */
00204     set_feature_default ("DECC$EFS_CHARSET", ENABLE);
00205     set_feature_default ("DECC$EFS_CASE_PRESERVE", ENABLE);
00206 
00207     /* Support timestamps when available */
00208     set_feature_default ("DECC$EFS_FILE_TIMESTAMPS", ENABLE);
00209 
00210     /* Cache environment variables - performance improvements */
00211     set_feature_default ("DECC$ENABLE_GETENV_CACHE", ENABLE);
00212 
00213     /* Start out with new file attribute inheritance */
00214 #ifdef __VAX
00215     set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", "2");
00216 #else
00217     set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", 2);
00218 #endif
00219 
00220     /* Don't display trailing dot after files without type */
00221     set_feature_default ("DECC$READDIR_DROPDOTNOTYPE", ENABLE);
00222 
00223     /* For standard output channels buffer output until terminator */
00224     /* Gets rid of output logs with single character lines in them. */
00225     set_feature_default ("DECC$STDIO_CTX_EOL", ENABLE);
00226 
00227     /* Fix mv aa.bb aa  */
00228     set_feature_default ("DECC$RENAME_NO_INHERIT", ENABLE);
00229 
00230     if (use_unix_settings) {
00231 
00232         /* POSIX requires that open files be able to be removed */
00233         set_feature_default ("DECC$ALLOW_REMOVE_OPEN_FILES", ENABLE);
00234 
00235         /* Default to outputting Unix filenames in VMS routines */
00236         set_feature_default ("DECC$FILENAME_UNIX_ONLY", ENABLE);
00237         /* FILENAME_UNIX_ONLY Implicitly sets */
00238         /* decc$disable_to_vms_logname_translation */
00239 
00240         set_feature_default ("DECC$FILE_PERMISSION_UNIX", ENABLE);
00241 
00242         set_feature_default ("DECC$FILE_SHARING", ENABLE);
00243 
00244         set_feature_default ("DECC$FILE_OWNER_UNIX", ENABLE);
00245         set_feature_default ("DECC$POSIX_SEEK_STREAM_FILE", ENABLE);
00246 
00247     } else {
00248         set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE);
00249     }
00250 
00251     /* When reporting Unix filenames, glob the same way */
00252     set_feature_default ("DECC$GLOB_UNIX_STYLE", ENABLE);
00253 
00254     /* The VMS version numbers on Unix filenames is incompatible with most */
00255     /* ported packages. */
00256     set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE);
00257 
00258     /* The VMS version numbers on Unix filenames is incompatible with most */
00259     /* ported packages. */
00260     set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE);
00261 
00262     /* Set strtol to proper behavior */
00263     set_feature_default("DECC$STRTOL_ERANGE", ENABLE);
00264 
00265     /* Commented here to prevent future bugs:  A program or user should */
00266     /* never ever enable DECC$POSIX_STYLE_UID. */
00267     /* It will probably break all code that accesses UIDs */
00268     /*  do_not_set_default ("DECC$POSIX_STYLE_UID", TRUE); */
00269 }
00270 
00271 
00272 /* Some boilerplate to force this to be a proper LIB$INITIALIZE section */
00273 
00274 #pragma nostandard
00275 #pragma extern_model save
00276 #ifdef __VAX
00277 #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic
00278 #else
00279 #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long
00280 #    if __INITIAL_POINTER_SIZE
00281 #        pragma __pointer_size __save
00282 #        pragma __pointer_size 32
00283 #    else
00284 #        pragma __required_pointer_size __save
00285 #        pragma __required_pointer_size 32
00286 #    endif
00287 #endif
00288 /* Set our contribution to the LIB$INITIALIZE array */
00289 void (* const iniarray[])(void) = {set_features, } ;
00290 #ifndef __VAX
00291 #    if __INITIAL_POINTER_SIZE
00292 #        pragma __pointer_size __restore
00293 #    else
00294 #        pragma __required_pointer_size __restore
00295 #    endif
00296 #endif
00297 
00298 
00299 /*
00300 ** Force a reference to LIB$INITIALIZE to ensure it
00301 ** exists in the image.
00302 */
00303 int LIB$INITIALIZE(void);
00304 #ifdef __DECC
00305 #pragma extern_model strict_refdef
00306 #endif
00307     int lib_init_ref = (int) LIB$INITIALIZE;
00308 #ifdef __DECC
00309 #pragma extern_model restore
00310 #pragma standard
00311 #endif


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02