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