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