vms_decc_init.c 4.8 KB

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