summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bss_fd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio/bss_fd.c')
-rw-r--r--src/lib/libcrypto/bio/bss_fd.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c
index 5e3e187de6..4c229bf641 100644
--- a/src/lib/libcrypto/bio/bss_fd.c
+++ b/src/lib/libcrypto/bio/bss_fd.c
@@ -60,7 +60,19 @@
60#include <errno.h> 60#include <errno.h>
61#define USE_SOCKETS 61#define USE_SOCKETS
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include <openssl/bio.h> 63/*
64 * As for unconditional usage of "UPLINK" interface in this module.
65 * Trouble is that unlike Unix file descriptors [which are indexes
66 * in kernel-side per-process table], corresponding descriptors on
67 * platforms which require "UPLINK" interface seem to be indexes
68 * in a user-land, non-global table. Well, in fact they are indexes
69 * in stdio _iob[], and recall that _iob[] was the very reason why
70 * "UPLINK" interface was introduced in first place. But one way on
71 * another. Neither libcrypto or libssl use this BIO meaning that
72 * file descriptors can only be provided by application. Therefore
73 * "UPLINK" calls are due...
74 */
75#include "bio_lcl.h"
64 76
65static int fd_write(BIO *h, const char *buf, int num); 77static int fd_write(BIO *h, const char *buf, int num);
66static int fd_read(BIO *h, char *buf, int size); 78static int fd_read(BIO *h, char *buf, int size);
@@ -100,9 +112,9 @@ BIO *BIO_new_fd(int fd,int close_flag)
100static int fd_new(BIO *bi) 112static int fd_new(BIO *bi)
101 { 113 {
102 bi->init=0; 114 bi->init=0;
103 bi->num=0; 115 bi->num=-1;
104 bi->ptr=NULL; 116 bi->ptr=NULL;
105 bi->flags=0; 117 bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */
106 return(1); 118 return(1);
107 } 119 }
108 120
@@ -113,10 +125,10 @@ static int fd_free(BIO *a)
113 { 125 {
114 if (a->init) 126 if (a->init)
115 { 127 {
116 close(a->num); 128 UP_close(a->num);
117 } 129 }
118 a->init=0; 130 a->init=0;
119 a->flags=0; 131 a->flags=BIO_FLAGS_UPLINK;
120 } 132 }
121 return(1); 133 return(1);
122 } 134 }
@@ -128,7 +140,7 @@ static int fd_read(BIO *b, char *out,int outl)
128 if (out != NULL) 140 if (out != NULL)
129 { 141 {
130 clear_sys_error(); 142 clear_sys_error();
131 ret=read(b->num,out,outl); 143 ret=UP_read(b->num,out,outl);
132 BIO_clear_retry_flags(b); 144 BIO_clear_retry_flags(b);
133 if (ret <= 0) 145 if (ret <= 0)
134 { 146 {
@@ -143,7 +155,7 @@ static int fd_write(BIO *b, const char *in, int inl)
143 { 155 {
144 int ret; 156 int ret;
145 clear_sys_error(); 157 clear_sys_error();
146 ret=write(b->num,in,inl); 158 ret=UP_write(b->num,in,inl);
147 BIO_clear_retry_flags(b); 159 BIO_clear_retry_flags(b);
148 if (ret <= 0) 160 if (ret <= 0)
149 { 161 {
@@ -163,11 +175,11 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
163 case BIO_CTRL_RESET: 175 case BIO_CTRL_RESET:
164 num=0; 176 num=0;
165 case BIO_C_FILE_SEEK: 177 case BIO_C_FILE_SEEK:
166 ret=(long)lseek(b->num,num,0); 178 ret=(long)UP_lseek(b->num,num,0);
167 break; 179 break;
168 case BIO_C_FILE_TELL: 180 case BIO_C_FILE_TELL:
169 case BIO_CTRL_INFO: 181 case BIO_CTRL_INFO:
170 ret=(long)lseek(b->num,0,1); 182 ret=(long)UP_lseek(b->num,0,1);
171 break; 183 break;
172 case BIO_C_SET_FD: 184 case BIO_C_SET_FD:
173 fd_free(b); 185 fd_free(b);