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