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