curl_crtl_init.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* File: curl_crtl_init.c
  2. *
  3. * This file makes sure that the DECC Unix settings are correct for
  4. * the mode the the program is run in.
  5. *
  6. * The CRTL has not been initialized at the time that these routines
  7. * are called, so many routines can not be called.
  8. *
  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.
  11. *
  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
  14. * those settings.
  15. *
  16. * On VMS versions that are too old to use the feature setting API, this
  17. * module falls back to using logical names.
  18. *
  19. * Copyright 2013, John Malmberg
  20. *
  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.
  24. *
  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.
  32. *
  33. */
  34. /* Unix headers */
  35. #include <stdio.h>
  36. #include <string.h>
  37. /* VMS specific headers */
  38. #include <descrip.h>
  39. #include <lnmdef.h>
  40. #include <stsdef.h>
  41. #pragma member_alignment save
  42. #pragma nomember_alignment longword
  43. #pragma message save
  44. #pragma message disable misalgndmem
  45. struct itmlst_3 {
  46. unsigned short int buflen;
  47. unsigned short int itmcode;
  48. void *bufadr;
  49. unsigned short int *retlen;
  50. };
  51. #pragma message restore
  52. #pragma member_alignment restore
  53. #ifdef __VAX
  54. #define ENABLE "ENABLE"
  55. #define DISABLE "DISABLE"
  56. #else
  57. #define ENABLE TRUE
  58. #define DISABLE 0
  59. int decc$feature_get_index (const char *name);
  60. int decc$feature_set_value (int index, int mode, int value);
  61. #endif
  62. int SYS$TRNLNM(
  63. const unsigned long * attr,
  64. const struct dsc$descriptor_s * table_dsc,
  65. struct dsc$descriptor_s * name_dsc,
  66. const unsigned char * acmode,
  67. const struct itmlst_3 * item_list);
  68. int SYS$CRELNM(
  69. const unsigned long * attr,
  70. const struct dsc$descriptor_s * table_dsc,
  71. const struct dsc$descriptor_s * name_dsc,
  72. const unsigned char * acmode,
  73. const struct itmlst_3 * item_list);
  74. /* Take all the fun out of simply looking up a logical name */
  75. static int sys_trnlnm
  76. (const char * logname,
  77. char * value,
  78. int value_len)
  79. {
  80. const $DESCRIPTOR(table_dsc, "LNM$FILE_DEV");
  81. const unsigned long attr = LNM$M_CASE_BLIND;
  82. struct dsc$descriptor_s name_dsc;
  83. int status;
  84. unsigned short result;
  85. struct itmlst_3 itlst[2];
  86. itlst[0].buflen = value_len;
  87. itlst[0].itmcode = LNM$_STRING;
  88. itlst[0].bufadr = value;
  89. itlst[0].retlen = &result;
  90. itlst[1].buflen = 0;
  91. itlst[1].itmcode = 0;
  92. name_dsc.dsc$w_length = strlen(logname);
  93. name_dsc.dsc$a_pointer = (char *)logname;
  94. name_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  95. name_dsc.dsc$b_class = DSC$K_CLASS_S;
  96. status = SYS$TRNLNM(&attr, &table_dsc, &name_dsc, 0, itlst);
  97. if ($VMS_STATUS_SUCCESS(status)) {
  98. /* Null terminate and return the string */
  99. /*--------------------------------------*/
  100. value[result] = '\0';
  101. }
  102. return status;
  103. }
  104. /* How to simply create a logical name */
  105. static int sys_crelnm
  106. (const char * logname,
  107. const char * value)
  108. {
  109. int ret_val;
  110. const char * proc_table = "LNM$PROCESS_TABLE";
  111. struct dsc$descriptor_s proc_table_dsc;
  112. struct dsc$descriptor_s logname_dsc;
  113. struct itmlst_3 item_list[2];
  114. proc_table_dsc.dsc$a_pointer = (char *) proc_table;
  115. proc_table_dsc.dsc$w_length = strlen(proc_table);
  116. proc_table_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  117. proc_table_dsc.dsc$b_class = DSC$K_CLASS_S;
  118. logname_dsc.dsc$a_pointer = (char *) logname;
  119. logname_dsc.dsc$w_length = strlen(logname);
  120. logname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
  121. logname_dsc.dsc$b_class = DSC$K_CLASS_S;
  122. item_list[0].buflen = strlen(value);
  123. item_list[0].itmcode = LNM$_STRING;
  124. item_list[0].bufadr = (char *)value;
  125. item_list[0].retlen = NULL;
  126. item_list[1].buflen = 0;
  127. item_list[1].itmcode = 0;
  128. ret_val = SYS$CRELNM(NULL, &proc_table_dsc, &logname_dsc, NULL, item_list);
  129. return ret_val;
  130. }
  131. /* Start of DECC RTL Feature handling */
  132. /*
  133. ** Sets default value for a feature
  134. */
  135. #ifdef __VAX
  136. static void set_feature_default(const char *name, const char *value)
  137. {
  138. sys_crelnm(name, value);
  139. }
  140. #else
  141. static void set_feature_default(const char *name, int value)
  142. {
  143. int index;
  144. index = decc$feature_get_index(name);
  145. if (index > 0)
  146. decc$feature_set_value (index, 0, value);
  147. }
  148. #endif
  149. static void set_features(void)
  150. {
  151. int status;
  152. char unix_shell_name[255];
  153. int use_unix_settings = 1;
  154. status = sys_trnlnm("GNV$UNIX_SHELL",
  155. unix_shell_name, sizeof unix_shell_name -1);
  156. if (!$VMS_STATUS_SUCCESS(status)) {
  157. use_unix_settings = 0;
  158. }
  159. /* ACCESS should check ACLs or it is lying. */
  160. set_feature_default("DECC$ACL_ACCESS_CHECK", ENABLE);
  161. /* We always want the new parse style */
  162. set_feature_default ("DECC$ARGV_PARSE_STYLE" , ENABLE);
  163. /* Unless we are in POSIX compliant mode, we want the old POSIX root
  164. * enabled.
  165. */
  166. set_feature_default("DECC$DISABLE_POSIX_ROOT", DISABLE);
  167. /* EFS charset, means UTF-8 support */
  168. /* VTF-7 support is controlled by a feature setting called UTF8 */
  169. set_feature_default ("DECC$EFS_CHARSET", ENABLE);
  170. set_feature_default ("DECC$EFS_CASE_PRESERVE", ENABLE);
  171. /* Support timestamps when available */
  172. set_feature_default ("DECC$EFS_FILE_TIMESTAMPS", ENABLE);
  173. /* Cache environment variables - performance improvements */
  174. set_feature_default ("DECC$ENABLE_GETENV_CACHE", ENABLE);
  175. /* Start out with new file attribute inheritance */
  176. #ifdef __VAX
  177. set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", "2");
  178. #else
  179. set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", 2);
  180. #endif
  181. /* Don't display trailing dot after files without type */
  182. set_feature_default ("DECC$READDIR_DROPDOTNOTYPE", ENABLE);
  183. /* For standard output channels buffer output until terminator */
  184. /* Gets rid of output logs with single character lines in them. */
  185. set_feature_default ("DECC$STDIO_CTX_EOL", ENABLE);
  186. /* Fix mv aa.bb aa */
  187. set_feature_default ("DECC$RENAME_NO_INHERIT", ENABLE);
  188. if (use_unix_settings) {
  189. /* POSIX requires that open files be able to be removed */
  190. set_feature_default ("DECC$ALLOW_REMOVE_OPEN_FILES", ENABLE);
  191. /* Default to outputting Unix filenames in VMS routines */
  192. set_feature_default ("DECC$FILENAME_UNIX_ONLY", ENABLE);
  193. /* FILENAME_UNIX_ONLY Implicitly sets */
  194. /* decc$disable_to_vms_logname_translation */
  195. set_feature_default ("DECC$FILE_PERMISSION_UNIX", ENABLE);
  196. set_feature_default ("DECC$FILE_SHARING", ENABLE);
  197. set_feature_default ("DECC$FILE_OWNER_UNIX", ENABLE);
  198. set_feature_default ("DECC$POSIX_SEEK_STREAM_FILE", ENABLE);
  199. } else {
  200. set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE);
  201. }
  202. /* When reporting Unix filenames, glob the same way */
  203. set_feature_default ("DECC$GLOB_UNIX_STYLE", ENABLE);
  204. /* The VMS version numbers on Unix filenames is incompatible with most */
  205. /* ported packages. */
  206. set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE);
  207. /* The VMS version numbers on Unix filenames is incompatible with most */
  208. /* ported packages. */
  209. set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE);
  210. /* Set strtol to proper behavior */
  211. set_feature_default("DECC$STRTOL_ERANGE", ENABLE);
  212. /* Commented here to prevent future bugs: A program or user should */
  213. /* never ever enable DECC$POSIX_STYLE_UID. */
  214. /* It will probably break all code that accesses UIDs */
  215. /* do_not_set_default ("DECC$POSIX_STYLE_UID", TRUE); */
  216. }
  217. /* Some boilerplate to force this to be a proper LIB$INITIALIZE section */
  218. #pragma nostandard
  219. #pragma extern_model save
  220. #ifdef __VAX
  221. #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic
  222. #else
  223. #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long
  224. # if __INITIAL_POINTER_SIZE
  225. # pragma __pointer_size __save
  226. # pragma __pointer_size 32
  227. # else
  228. # pragma __required_pointer_size __save
  229. # pragma __required_pointer_size 32
  230. # endif
  231. #endif
  232. /* Set our contribution to the LIB$INITIALIZE array */
  233. void (* const iniarray[])(void) = {set_features, } ;
  234. #ifndef __VAX
  235. # if __INITIAL_POINTER_SIZE
  236. # pragma __pointer_size __restore
  237. # else
  238. # pragma __required_pointer_size __restore
  239. # endif
  240. #endif
  241. /*
  242. ** Force a reference to LIB$INITIALIZE to ensure it
  243. ** exists in the image.
  244. */
  245. int LIB$INITIALIZE(void);
  246. #ifdef __DECC
  247. #pragma extern_model strict_refdef
  248. #endif
  249. int lib_init_ref = (int) LIB$INITIALIZE;
  250. #ifdef __DECC
  251. #pragma extern_model restore
  252. #pragma standard
  253. #endif