2
0

applink.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #define APPLINK_STDIN 1
  2. #define APPLINK_STDOUT 2
  3. #define APPLINK_STDERR 3
  4. #define APPLINK_FPRINTF 4
  5. #define APPLINK_FGETS 5
  6. #define APPLINK_FREAD 6
  7. #define APPLINK_FWRITE 7
  8. #define APPLINK_FSETMOD 8
  9. #define APPLINK_FEOF 9
  10. #define APPLINK_FCLOSE 10 /* should not be used */
  11. #define APPLINK_FOPEN 11 /* solely for completeness */
  12. #define APPLINK_FSEEK 12
  13. #define APPLINK_FTELL 13
  14. #define APPLINK_FFLUSH 14
  15. #define APPLINK_FERROR 15
  16. #define APPLINK_CLEARERR 16
  17. #define APPLINK_FILENO 17 /* to be used with below */
  18. #define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */
  19. #define APPLINK_READ 19
  20. #define APPLINK_WRITE 20
  21. #define APPLINK_LSEEK 21
  22. #define APPLINK_CLOSE 22
  23. #define APPLINK_MAX 22 /* always same as last macro */
  24. #ifndef APPMACROS_ONLY
  25. # include <stdio.h>
  26. # include <io.h>
  27. # include <fcntl.h>
  28. static void *app_stdin(void)
  29. {
  30. return stdin;
  31. }
  32. static void *app_stdout(void)
  33. {
  34. return stdout;
  35. }
  36. static void *app_stderr(void)
  37. {
  38. return stderr;
  39. }
  40. static int app_feof(FILE *fp)
  41. {
  42. return feof(fp);
  43. }
  44. static int app_ferror(FILE *fp)
  45. {
  46. return ferror(fp);
  47. }
  48. static void app_clearerr(FILE *fp)
  49. {
  50. clearerr(fp);
  51. }
  52. static int app_fileno(FILE *fp)
  53. {
  54. return _fileno(fp);
  55. }
  56. static int app_fsetmod(FILE *fp, char mod)
  57. {
  58. return _setmode(_fileno(fp), mod == 'b' ? _O_BINARY : _O_TEXT);
  59. }
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. __declspec(dllexport)
  64. void **
  65. # if defined(__BORLANDC__)
  66. /*
  67. * __stdcall appears to be the only way to get the name
  68. * decoration right with Borland C. Otherwise it works
  69. * purely incidentally, as we pass no parameters.
  70. */
  71. __stdcall
  72. # else
  73. __cdecl
  74. # endif
  75. OPENSSL_Applink(void)
  76. {
  77. static int once = 1;
  78. static void *OPENSSL_ApplinkTable[APPLINK_MAX + 1] =
  79. { (void *)APPLINK_MAX };
  80. if (once) {
  81. OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin;
  82. OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout;
  83. OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr;
  84. OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf;
  85. OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets;
  86. OPENSSL_ApplinkTable[APPLINK_FREAD] = fread;
  87. OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite;
  88. OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod;
  89. OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof;
  90. OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose;
  91. OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen;
  92. OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek;
  93. OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell;
  94. OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush;
  95. OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror;
  96. OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr;
  97. OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno;
  98. OPENSSL_ApplinkTable[APPLINK_OPEN] = _open;
  99. OPENSSL_ApplinkTable[APPLINK_READ] = _read;
  100. OPENSSL_ApplinkTable[APPLINK_WRITE] = _write;
  101. OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek;
  102. OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close;
  103. once = 0;
  104. }
  105. return OPENSSL_ApplinkTable;
  106. }
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif