curl_crtl_init.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. unix_shell_name[0] = 0;
  158. use_unix_settings = 0;
  159. }
  160. /* ACCESS should check ACLs or it is lying. */
  161. set_feature_default("DECC$ACL_ACCESS_CHECK", ENABLE);
  162. /* We always want the new parse style */
  163. set_feature_default ("DECC$ARGV_PARSE_STYLE" , ENABLE);
  164. /* Unless we are in POSIX compliant mode, we want the old POSIX root
  165. * enabled.
  166. */
  167. set_feature_default("DECC$DISABLE_POSIX_ROOT", DISABLE);
  168. /* EFS charset, means UTF-8 support */
  169. /* VTF-7 support is controlled by a feature setting called UTF8 */
  170. set_feature_default ("DECC$EFS_CHARSET", ENABLE);
  171. set_feature_default ("DECC$EFS_CASE_PRESERVE", ENABLE);
  172. /* Support timestamps when available */
  173. set_feature_default ("DECC$EFS_FILE_TIMESTAMPS", ENABLE);
  174. /* Cache environment variables - performance improvements */
  175. set_feature_default ("DECC$ENABLE_GETENV_CACHE", ENABLE);
  176. /* Start out with new file attribute inheritance */
  177. #ifdef __VAX
  178. set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", "2");
  179. #else
  180. set_feature_default ("DECC$EXEC_FILEATTR_INHERITANCE", 2);
  181. #endif
  182. /* Don't display trailing dot after files without type */
  183. set_feature_default ("DECC$READDIR_DROPDOTNOTYPE", ENABLE);
  184. /* For standard output channels buffer output until terminator */
  185. /* Gets rid of output logs with single character lines in them. */
  186. set_feature_default ("DECC$STDIO_CTX_EOL", ENABLE);
  187. /* Fix mv aa.bb aa */
  188. set_feature_default ("DECC$RENAME_NO_INHERIT", ENABLE);
  189. if (use_unix_settings) {
  190. /* POSIX requires that open files be able to be removed */
  191. set_feature_default ("DECC$ALLOW_REMOVE_OPEN_FILES", ENABLE);
  192. /* Default to outputting Unix filenames in VMS routines */
  193. set_feature_default ("DECC$FILENAME_UNIX_ONLY", ENABLE);
  194. /* FILENAME_UNIX_ONLY Implicitly sets */
  195. /* decc$disable_to_vms_logname_translation */
  196. set_feature_default ("DECC$FILE_PERMISSION_UNIX", ENABLE);
  197. set_feature_default ("DECC$FILE_SHARING", ENABLE);
  198. set_feature_default ("DECC$FILE_OWNER_UNIX", ENABLE);
  199. set_feature_default ("DECC$POSIX_SEEK_STREAM_FILE", ENABLE);
  200. } else {
  201. set_feature_default("DECC$FILENAME_UNIX_REPORT", ENABLE);
  202. }
  203. /* When reporting Unix filenames, glob the same way */
  204. set_feature_default ("DECC$GLOB_UNIX_STYLE", ENABLE);
  205. /* The VMS version numbers on Unix filenames is incompatible with most */
  206. /* ported packages. */
  207. set_feature_default("DECC$FILENAME_UNIX_NO_VERSION", ENABLE);
  208. /* The VMS version numbers on Unix filenames is incompatible with most */
  209. /* ported packages. */
  210. set_feature_default("DECC$UNIX_PATH_BEFORE_LOGNAME", ENABLE);
  211. /* Set strtol to proper behavior */
  212. set_feature_default("DECC$STRTOL_ERANGE", ENABLE);
  213. /* Commented here to prevent future bugs: A program or user should */
  214. /* never ever enable DECC$POSIX_STYLE_UID. */
  215. /* It will probably break all code that accesses UIDs */
  216. /* do_not_set_default ("DECC$POSIX_STYLE_UID", TRUE); */
  217. }
  218. /* Some boilerplate to force this to be a proper LIB$INITIALIZE section */
  219. #pragma nostandard
  220. #pragma extern_model save
  221. #ifdef __VAX
  222. #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic
  223. #else
  224. #pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long
  225. # if __INITIAL_POINTER_SIZE
  226. # pragma __pointer_size __save
  227. # pragma __pointer_size 32
  228. # else
  229. # pragma __required_pointer_size __save
  230. # pragma __required_pointer_size 32
  231. # endif
  232. #endif
  233. /* Set our contribution to the LIB$INITIALIZE array */
  234. void (* const iniarray[])(void) = {set_features, } ;
  235. #ifndef __VAX
  236. # if __INITIAL_POINTER_SIZE
  237. # pragma __pointer_size __restore
  238. # else
  239. # pragma __required_pointer_size __restore
  240. # endif
  241. #endif
  242. /*
  243. ** Force a reference to LIB$INITIALIZE to ensure it
  244. ** exists in the image.
  245. */
  246. int LIB$INITIALIZE(void);
  247. #ifdef __DECC
  248. #pragma extern_model strict_refdef
  249. #endif
  250. int lib_init_ref = (int) LIB$INITIALIZE;
  251. #ifdef __DECC
  252. #pragma extern_model restore
  253. #pragma standard
  254. #endif