os-specific.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * $Id$
  22. ***************************************************************************/
  23. #include "setup.h"
  24. #include <curl/curl.h>
  25. #define ENABLE_CURLX_PRINTF
  26. #include "curlx.h"
  27. #include "os-specific.h"
  28. #if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
  29. # include "memdebug.h"
  30. #endif
  31. #ifdef __VMS
  32. #include "curlmsg_vms.h"
  33. void decc$__posix_exit(int __status);
  34. void decc$exit(int __status);
  35. static int vms_shell = -1;
  36. /* VMS has a DCL shell and and also has Unix shells ported to it.
  37. * When curl is running under a Unix shell, we want it to be as much
  38. * like Unix as possible.
  39. */
  40. int is_vms_shell(void)
  41. {
  42. char *shell;
  43. /* Have we checked the shell yet? */
  44. if(vms_shell >= 0)
  45. return vms_shell;
  46. shell = getenv("SHELL");
  47. /* No shell, means DCL */
  48. if(shell == NULL) {
  49. vms_shell = 1;
  50. return 1;
  51. }
  52. /* Have to make sure some one did not set shell to DCL */
  53. if(strcmp(shell, "DCL") == 0) {
  54. vms_shell = 1;
  55. return 1;
  56. }
  57. vms_shell = 0;
  58. return 0;
  59. }
  60. /*
  61. * VMS has two exit() routines. When running under a Unix style shell, then
  62. * Unix style and the __posix_exit() routine is used.
  63. *
  64. * When running under the DCL shell, then the VMS encoded codes and decc$exit()
  65. * is used.
  66. *
  67. * We can not use exit() or return a code from main() because the actual
  68. * routine called depends on both the compiler version, compile options, and
  69. * feature macro settings, and one of the exit routines is hidden at compile
  70. * time.
  71. *
  72. * Since we want Curl to work properly under the VMS DCL shell and Unix
  73. * shells under VMS, this routine should compile correctly regardless of
  74. * the settings.
  75. */
  76. void vms_special_exit(int code, int vms_show)
  77. {
  78. int vms_code;
  79. /* The Posix exit mode is only available after VMS 7.0 */
  80. #if __CRTL_VER >= 70000000
  81. if(is_vms_shell() == 0) {
  82. decc$__posix_exit(code);
  83. }
  84. #endif
  85. if(code > CURL_LAST) { /* If CURL_LAST exceeded then */
  86. vms_code = CURL_LAST; /* curlmsg.h is out of sync. */
  87. }
  88. else {
  89. vms_code = vms_cond[code] | vms_show;
  90. }
  91. decc$exit(vms_code);
  92. }
  93. #if defined(__DECC) && !defined(__VAX) && \
  94. defined(__CRTL_VER) && (__CRTL_VER >= 70301000)
  95. /*
  96. * 2004-09-19 SMS.
  97. *
  98. * decc_init()
  99. *
  100. * On non-VAX systems, use LIB$INITIALIZE to set a collection of C
  101. * RTL features without using the DECC$* logical name method, nor
  102. * requiring the user to define the corresponding logical names.
  103. */
  104. #include <unixlib.h>
  105. /* Structure to hold a DECC$* feature name and its desired value. */
  106. typedef struct {
  107. char *name;
  108. int value;
  109. } decc_feat_t;
  110. /* Array of DECC$* feature names and their desired values. */
  111. static decc_feat_t decc_feat_array[] = {
  112. /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */
  113. { "DECC$ARGV_PARSE_STYLE", 1 },
  114. /* Preserve case for file names on ODS5 disks. */
  115. { "DECC$EFS_CASE_PRESERVE", 1 },
  116. /* Enable multiple dots (and most characters) in ODS5 file names,
  117. while preserving VMS-ness of ";version". */
  118. { "DECC$EFS_CHARSET", 1 },
  119. /* List terminator. */
  120. { (char *)NULL, 0 }
  121. };
  122. /* Flag to sense if decc_init() was called. */
  123. static int decc_init_done = -1;
  124. /* LIB$INITIALIZE initialization function. */
  125. static void decc_init(void)
  126. {
  127. int feat_index;
  128. int feat_value;
  129. int feat_value_max;
  130. int feat_value_min;
  131. int i;
  132. int sts;
  133. /* Set the global flag to indicate that LIB$INITIALIZE worked. */
  134. decc_init_done = 1;
  135. /* Loop through all items in the decc_feat_array[]. */
  136. for(i = 0; decc_feat_array[i].name != NULL; i++) {
  137. /* Get the feature index. */
  138. feat_index = decc$feature_get_index( decc_feat_array[i].name);
  139. if(feat_index >= 0) {
  140. /* Valid item. Collect its properties. */
  141. feat_value = decc$feature_get_value( feat_index, 1);
  142. feat_value_min = decc$feature_get_value( feat_index, 2);
  143. feat_value_max = decc$feature_get_value( feat_index, 3);
  144. if((decc_feat_array[i].value >= feat_value_min) &&
  145. (decc_feat_array[i].value <= feat_value_max)) {
  146. /* Valid value. Set it if necessary. */
  147. if(feat_value != decc_feat_array[i].value) {
  148. sts = decc$feature_set_value( feat_index, 1,
  149. decc_feat_array[i].value);
  150. }
  151. }
  152. else {
  153. /* Invalid DECC feature value. */
  154. printf(" INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n",
  155. feat_value,
  156. feat_value_min, decc_feat_array[i].name, feat_value_max);
  157. }
  158. }
  159. else {
  160. /* Invalid DECC feature name. */
  161. printf(" UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[i].name);
  162. }
  163. }
  164. }
  165. /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */
  166. #pragma nostandard
  167. /* Establish the LIB$INITIALIZE PSECTs, with proper alignment and
  168. other attributes. Note that "nopic" is significant only on VAX. */
  169. #pragma extern_model save
  170. #pragma extern_model strict_refdef "LIB$INITIALIZ" 2, nopic, nowrt
  171. const int spare[8] = {0};
  172. #pragma extern_model strict_refdef "LIB$INITIALIZE" 2, nopic, nowrt
  173. void (*const x_decc_init)() = decc_init;
  174. #pragma extern_model restore
  175. /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */
  176. #pragma extern_model save
  177. int LIB$INITIALIZE(void);
  178. #pragma extern_model strict_refdef
  179. int dmy_lib$initialize = (int) LIB$INITIALIZE;
  180. #pragma extern_model restore
  181. #pragma standard
  182. #endif /* __DECC && !__VAX && __CRTL_VER && __CRTL_VER >= 70301000 */
  183. #endif /* __VMS */