Skip to content

Commit 385ab50

Browse files
aruthaneCyberShadow
authored andcommitted
Add OPENSSL_Applink
1 parent c315767 commit 385ab50

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed

C/applink.c

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

deimos/openssl/applink.d

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
module deimos.openssl.applink;
2+
import core.stdc.stdio;
3+
import std.stdio : _fileno, _setmode, _O_BINARY;
4+
import core.sys.posix.fcntl;
5+
import core.sys.posix.unistd;
6+
import core.stdc.stdio;
7+
8+
enum APPLINK_STDIN =1;
9+
enum APPLINK_STDOUT =2;
10+
enum APPLINK_STDERR =3;
11+
enum APPLINK_FPRINTF =4;
12+
enum APPLINK_FGETS =5;
13+
enum APPLINK_FREAD =6;
14+
enum APPLINK_FWRITE =7;
15+
enum APPLINK_FSETMOD =8;
16+
enum APPLINK_FEOF =9;
17+
enum APPLINK_FCLOSE =10; /* should not be used */
18+
19+
enum APPLINK_FOPEN =11; /* solely for completeness */
20+
enum APPLINK_FSEEK =12;
21+
enum APPLINK_FTELL =13;
22+
enum APPLINK_FFLUSH =14;
23+
enum APPLINK_FERROR =15;
24+
enum APPLINK_CLEARERR =16;
25+
enum APPLINK_FILENO =17; /* to be used with below */
26+
27+
enum APPLINK_OPEN =18; /* formally can't be used, as flags can vary */
28+
enum APPLINK_READ =19;
29+
enum APPLINK_WRITE =20;
30+
enum APPLINK_LSEEK =21;
31+
enum APPLINK_CLOSE =22;
32+
enum APPLINK_MAX =22; /* always same as last macro */
33+
34+
enum _O_TEXT = 0x4000;
35+
36+
extern(C)
37+
{
38+
void *app_stdin()
39+
{
40+
return cast(void*)stdin;
41+
}
42+
43+
void *app_stdout()
44+
{
45+
return cast(void*)stdout;
46+
}
47+
48+
void *app_stderr()
49+
{
50+
return cast(void*)stderr;
51+
}
52+
53+
int app_feof(FILE *fp)
54+
{
55+
return feof(fp);
56+
}
57+
58+
int app_ferror(FILE *fp)
59+
{
60+
return ferror(fp);
61+
}
62+
63+
void app_clearerr(FILE *fp)
64+
{
65+
clearerr(fp);
66+
}
67+
68+
int app_fileno(FILE *fp)
69+
{
70+
return _fileno(fp);
71+
}
72+
73+
int app_fsetmod(FILE *fp, char mod)
74+
{
75+
return _setmode (_fileno(fp),mod=='b'?_O_BINARY:_O_TEXT);
76+
}
77+
78+
__gshared bool once = true;
79+
__gshared void*[APPLINK_MAX+1] OPENSSL_ApplinkTable = cast(void*)APPLINK_MAX;
80+
81+
export void** OPENSSL_Applink()
82+
{
83+
if (once)
84+
{
85+
OPENSSL_ApplinkTable[APPLINK_STDIN] = &app_stdin;
86+
OPENSSL_ApplinkTable[APPLINK_STDOUT] = &app_stdout;
87+
OPENSSL_ApplinkTable[APPLINK_STDERR] = &app_stderr;
88+
OPENSSL_ApplinkTable[APPLINK_FPRINTF] = &fprintf;
89+
OPENSSL_ApplinkTable[APPLINK_FGETS] = &fgets;
90+
OPENSSL_ApplinkTable[APPLINK_FREAD] = &fread;
91+
OPENSSL_ApplinkTable[APPLINK_FWRITE] = &fwrite;
92+
OPENSSL_ApplinkTable[APPLINK_FSETMOD] = &app_fsetmod;
93+
OPENSSL_ApplinkTable[APPLINK_FEOF] = &app_feof;
94+
OPENSSL_ApplinkTable[APPLINK_FCLOSE] = &fclose;
95+
96+
OPENSSL_ApplinkTable[APPLINK_FOPEN] = &fopen;
97+
OPENSSL_ApplinkTable[APPLINK_FSEEK] = &fseek;
98+
OPENSSL_ApplinkTable[APPLINK_FTELL] = &ftell;
99+
OPENSSL_ApplinkTable[APPLINK_FFLUSH] = &fflush;
100+
OPENSSL_ApplinkTable[APPLINK_FERROR] = &app_ferror;
101+
OPENSSL_ApplinkTable[APPLINK_CLEARERR] = &app_clearerr;
102+
OPENSSL_ApplinkTable[APPLINK_FILENO] = &app_fileno;
103+
104+
OPENSSL_ApplinkTable[APPLINK_OPEN] = &fopen;
105+
OPENSSL_ApplinkTable[APPLINK_READ] = &fread;
106+
OPENSSL_ApplinkTable[APPLINK_WRITE] = &fwrite;
107+
OPENSSL_ApplinkTable[APPLINK_LSEEK] = &fseek;
108+
OPENSSL_ApplinkTable[APPLINK_CLOSE] = &fclose;
109+
110+
once = false;
111+
}
112+
113+
return OPENSSL_ApplinkTable.ptr;
114+
}
115+
}

0 commit comments

Comments
 (0)