applink.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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) { return stdin; }
  29. static void *app_stdout(void) { return stdout; }
  30. static void *app_stderr(void) { return stderr; }
  31. static int app_feof(FILE *fp) { return feof(fp); }
  32. static int app_ferror(FILE *fp) { return ferror(fp); }
  33. static void app_clearerr(FILE *fp) { clearerr(fp); }
  34. static int app_fileno(FILE *fp) { return _fileno(fp); }
  35. static int app_fsetmod(FILE *fp,char mod)
  36. { return _setmode (_fileno(fp),mod=='b'?_O_BINARY:_O_TEXT); }
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. __declspec(dllexport)
  41. void **
  42. #if defined(__BORLANDC__)
  43. __stdcall /* __stdcall appears to be the only way to get the name
  44. * decoration right with Borland C. Otherwise it works
  45. * purely incidentally, as we pass no parameters. */
  46. #else
  47. __cdecl
  48. #endif
  49. OPENSSL_Applink(void)
  50. { static int once=1;
  51. static void *OPENSSL_ApplinkTable[APPLINK_MAX+1]={(void *)APPLINK_MAX};
  52. if (once)
  53. { OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin;
  54. OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout;
  55. OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr;
  56. OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf;
  57. OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets;
  58. OPENSSL_ApplinkTable[APPLINK_FREAD] = fread;
  59. OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite;
  60. OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod;
  61. OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof;
  62. OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose;
  63. OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen;
  64. OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek;
  65. OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell;
  66. OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush;
  67. OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror;
  68. OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr;
  69. OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno;
  70. OPENSSL_ApplinkTable[APPLINK_OPEN] = _open;
  71. OPENSSL_ApplinkTable[APPLINK_READ] = _read;
  72. OPENSSL_ApplinkTable[APPLINK_WRITE] = _write;
  73. OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek;
  74. OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close;
  75. once = 0;
  76. }
  77. return OPENSSL_ApplinkTable;
  78. }
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif