vms_decc_init.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #if defined( __VMS) && !defined( OPENSSL_NO_DECC_INIT) && \
  10. defined( __DECC) && !defined( __VAX) && (__CRTL_VER >= 70301000)
  11. # define USE_DECC_INIT 1
  12. #endif
  13. #ifdef USE_DECC_INIT
  14. /*
  15. * ----------------------------------------------------------------------
  16. * decc_init() On non-VAX systems, uses LIB$INITIALIZE to set a collection
  17. * of C RTL features without using the DECC$* logical name method.
  18. * ----------------------------------------------------------------------
  19. */
  20. # include <stdio.h>
  21. # include <stdlib.h>
  22. # include <unixlib.h>
  23. /* Global storage. */
  24. /* Flag to sense if decc_init() was called. */
  25. int decc_init_done = -1;
  26. /* Structure to hold a DECC$* feature name and its desired value. */
  27. typedef struct {
  28. char *name;
  29. int value;
  30. } decc_feat_t;
  31. /*
  32. * Array of DECC$* feature names and their desired values. Note:
  33. * DECC$ARGV_PARSE_STYLE is the urgent one.
  34. */
  35. decc_feat_t decc_feat_array[] = {
  36. /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
  37. {"DECC$ARGV_PARSE_STYLE", 1},
  38. /* Preserve case for file names on ODS5 disks. */
  39. {"DECC$EFS_CASE_PRESERVE", 1},
  40. /*
  41. * Enable multiple dots (and most characters) in ODS5 file names, while
  42. * preserving VMS-ness of ";version".
  43. */
  44. {"DECC$EFS_CHARSET", 1},
  45. /* List terminator. */
  46. {(char *)NULL, 0}
  47. };
  48. /* LIB$INITIALIZE initialization function. */
  49. static void decc_init(void)
  50. {
  51. char *openssl_debug_decc_init;
  52. int verbose = 0;
  53. int feat_index;
  54. int feat_value;
  55. int feat_value_max;
  56. int feat_value_min;
  57. int i;
  58. int sts;
  59. /* Get debug option. */
  60. openssl_debug_decc_init = getenv("OPENSSL_DEBUG_DECC_INIT");
  61. if (openssl_debug_decc_init != NULL) {
  62. verbose = strtol(openssl_debug_decc_init, NULL, 10);
  63. if (verbose <= 0) {
  64. verbose = 1;
  65. }
  66. }
  67. /* Set the global flag to indicate that LIB$INITIALIZE worked. */
  68. decc_init_done = 1;
  69. /* Loop through all items in the decc_feat_array[]. */
  70. for (i = 0; decc_feat_array[i].name != NULL; i++) {
  71. /* Get the feature index. */
  72. feat_index = decc$feature_get_index(decc_feat_array[i].name);
  73. if (feat_index >= 0) {
  74. /* Valid item. Collect its properties. */
  75. feat_value = decc$feature_get_value(feat_index, 1);
  76. feat_value_min = decc$feature_get_value(feat_index, 2);
  77. feat_value_max = decc$feature_get_value(feat_index, 3);
  78. /* Check the validity of our desired value. */
  79. if ((decc_feat_array[i].value >= feat_value_min) &&
  80. (decc_feat_array[i].value <= feat_value_max)) {
  81. /* Valid value. Set it if necessary. */
  82. if (feat_value != decc_feat_array[i].value) {
  83. sts = decc$feature_set_value(feat_index,
  84. 1, decc_feat_array[i].value);
  85. if (verbose > 1) {
  86. fprintf(stderr, " %s = %d, sts = %d.\n",
  87. decc_feat_array[i].name,
  88. decc_feat_array[i].value, sts);
  89. }
  90. }
  91. } else {
  92. /* Invalid DECC feature value. */
  93. fprintf(stderr,
  94. " INVALID DECC$FEATURE VALUE, %d: %d <= %s <= %d.\n",
  95. feat_value,
  96. feat_value_min, decc_feat_array[i].name,
  97. feat_value_max);
  98. }
  99. } else {
  100. /* Invalid DECC feature name. */
  101. fprintf(stderr,
  102. " UNKNOWN DECC$FEATURE: %s.\n", decc_feat_array[i].name);
  103. }
  104. }
  105. if (verbose > 0) {
  106. fprintf(stderr, " DECC_INIT complete.\n");
  107. }
  108. }
  109. /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
  110. # pragma nostandard
  111. /*
  112. * Establish the LIB$INITIALIZE PSECTs, with proper alignment and other
  113. * attributes. Note that "nopic" is significant only on VAX.
  114. */
  115. # pragma extern_model save
  116. # if __INITIAL_POINTER_SIZE == 64
  117. # define PSECT_ALIGN 3
  118. # else
  119. # define PSECT_ALIGN 2
  120. # endif
  121. # pragma extern_model strict_refdef "LIB$INITIALIZ" PSECT_ALIGN, nopic, nowrt
  122. const int spare[8] = { 0 };
  123. # pragma extern_model strict_refdef "LIB$INITIALIZE" PSECT_ALIGN, nopic, nowrt
  124. void (*const x_decc_init) () = decc_init;
  125. # pragma extern_model restore
  126. /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
  127. # pragma extern_model save
  128. int LIB$INITIALIZE(void);
  129. # pragma extern_model strict_refdef
  130. int dmy_lib$initialize = (int)LIB$INITIALIZE;
  131. # pragma extern_model restore
  132. # pragma standard
  133. #else /* def USE_DECC_INIT */
  134. /* Dummy code to avoid a %CC-W-EMPTYFILE complaint. */
  135. int decc_init_dummy(void);
  136. #endif /* def USE_DECC_INIT */