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