]> git.ipfire.org Git - thirdparty/openssl.git/blame - ms/applink.c
Copyright year updates
[thirdparty/openssl.git] / ms / applink.c
CommitLineData
44c8a5e2 1/*
da1c088f 2 * Copyright 2004-2023 The OpenSSL Project Authors. All Rights Reserved.
44c8a5e2 3 *
c7fcbc09 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
44c8a5e2
RS
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
0f113f3e
MC
10#define APPLINK_STDIN 1
11#define APPLINK_STDOUT 2
12#define APPLINK_STDERR 3
13#define APPLINK_FPRINTF 4
14#define APPLINK_FGETS 5
15#define APPLINK_FREAD 6
16#define APPLINK_FWRITE 7
17#define APPLINK_FSETMOD 8
18#define APPLINK_FEOF 9
19#define APPLINK_FCLOSE 10 /* should not be used */
20
21#define APPLINK_FOPEN 11 /* solely for completeness */
22#define APPLINK_FSEEK 12
23#define APPLINK_FTELL 13
24#define APPLINK_FFLUSH 14
25#define APPLINK_FERROR 15
ea1b02db 26#define APPLINK_CLEARERR 16
0f113f3e 27#define APPLINK_FILENO 17 /* to be used with below */
ea1b02db 28
0f113f3e
MC
29#define APPLINK_OPEN 18 /* formally can't be used, as flags can vary */
30#define APPLINK_READ 19
31#define APPLINK_WRITE 20
32#define APPLINK_LSEEK 21
33#define APPLINK_CLOSE 22
34#define APPLINK_MAX 22 /* always same as last macro */
3fc378aa
AP
35
36#ifndef APPMACROS_ONLY
fafb7d30
WI
37
38/*
39 * Normally, do not define APPLINK_NO_INCLUDES. Define it if you are using
40 * symbol preprocessing and do not want the preprocessing to affect the
41 * following included header files. You will need to put these
42 * include lines somewhere in the file that is including applink.c.
43 */
bdb1f6b7
WI
44# ifndef APPLINK_NO_INCLUDES
45# include <stdio.h>
46# include <io.h>
47# include <fcntl.h>
48# endif
0f113f3e 49
daf98015
TI
50# ifdef __BORLANDC__
51 /* _lseek in <io.h> is a function-like macro so we can't take its address */
52# undef _lseek
53# define _lseek lseek
54# endif
55
0f113f3e
MC
56static void *app_stdin(void)
57{
58 return stdin;
59}
60
61static void *app_stdout(void)
62{
63 return stdout;
64}
65
66static void *app_stderr(void)
67{
68 return stderr;
69}
70
71static int app_feof(FILE *fp)
72{
73 return feof(fp);
74}
75
76static int app_ferror(FILE *fp)
77{
78 return ferror(fp);
79}
80
81static void app_clearerr(FILE *fp)
82{
83 clearerr(fp);
84}
85
86static int app_fileno(FILE *fp)
87{
88 return _fileno(fp);
89}
90
91static int app_fsetmod(FILE *fp, char mod)
92{
93 return _setmode(_fileno(fp), mod == 'b' ? _O_BINARY : _O_TEXT);
94}
3fc378aa 95
2c730f6f
AP
96#ifdef __cplusplus
97extern "C" {
98#endif
99
100__declspec(dllexport)
101void **
9c1215a3
RS
102# if defined(__BORLANDC__)
103/*
104 * __stdcall appears to be the only way to get the name
105 * decoration right with Borland C. Otherwise it works
106 * purely incidentally, as we pass no parameters.
107 */
108__stdcall
109# else
110__cdecl
111# endif
2c730f6f 112OPENSSL_Applink(void)
0f113f3e
MC
113{
114 static int once = 1;
115 static void *OPENSSL_ApplinkTable[APPLINK_MAX + 1] =
116 { (void *)APPLINK_MAX };
117
118 if (once) {
119 OPENSSL_ApplinkTable[APPLINK_STDIN] = app_stdin;
120 OPENSSL_ApplinkTable[APPLINK_STDOUT] = app_stdout;
121 OPENSSL_ApplinkTable[APPLINK_STDERR] = app_stderr;
122 OPENSSL_ApplinkTable[APPLINK_FPRINTF] = fprintf;
123 OPENSSL_ApplinkTable[APPLINK_FGETS] = fgets;
124 OPENSSL_ApplinkTable[APPLINK_FREAD] = fread;
125 OPENSSL_ApplinkTable[APPLINK_FWRITE] = fwrite;
126 OPENSSL_ApplinkTable[APPLINK_FSETMOD] = app_fsetmod;
127 OPENSSL_ApplinkTable[APPLINK_FEOF] = app_feof;
128 OPENSSL_ApplinkTable[APPLINK_FCLOSE] = fclose;
129
130 OPENSSL_ApplinkTable[APPLINK_FOPEN] = fopen;
131 OPENSSL_ApplinkTable[APPLINK_FSEEK] = fseek;
132 OPENSSL_ApplinkTable[APPLINK_FTELL] = ftell;
133 OPENSSL_ApplinkTable[APPLINK_FFLUSH] = fflush;
134 OPENSSL_ApplinkTable[APPLINK_FERROR] = app_ferror;
135 OPENSSL_ApplinkTable[APPLINK_CLEARERR] = app_clearerr;
136 OPENSSL_ApplinkTable[APPLINK_FILENO] = app_fileno;
137
138 OPENSSL_ApplinkTable[APPLINK_OPEN] = _open;
139 OPENSSL_ApplinkTable[APPLINK_READ] = _read;
140 OPENSSL_ApplinkTable[APPLINK_WRITE] = _write;
141 OPENSSL_ApplinkTable[APPLINK_LSEEK] = _lseek;
142 OPENSSL_ApplinkTable[APPLINK_CLOSE] = _close;
143
144 once = 0;
3fc378aa
AP
145 }
146
0f113f3e 147 return OPENSSL_ApplinkTable;
3fc378aa 148}
2c730f6f
AP
149
150#ifdef __cplusplus
151}
152#endif
3fc378aa 153#endif