diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_file.c')
| -rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 91 |
1 files changed, 35 insertions, 56 deletions
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 1484cf849e..8b3ff278d9 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
| @@ -68,29 +68,18 @@ | |||
| 68 | #include <stdio.h> | 68 | #include <stdio.h> |
| 69 | #include <errno.h> | 69 | #include <errno.h> |
| 70 | #include "cryptlib.h" | 70 | #include "cryptlib.h" |
| 71 | #include "bio.h" | 71 | #include <openssl/bio.h> |
| 72 | #include "err.h" | 72 | #include <openssl/err.h> |
| 73 | 73 | ||
| 74 | #if !defined(NO_STDIO) | 74 | #if !defined(OPENSSL_NO_STDIO) |
| 75 | 75 | ||
| 76 | #ifndef NOPROTO | 76 | static int MS_CALLBACK file_write(BIO *h, const char *buf, int num); |
| 77 | static int MS_CALLBACK file_write(BIO *h,char *buf,int num); | 77 | static int MS_CALLBACK file_read(BIO *h, char *buf, int size); |
| 78 | static int MS_CALLBACK file_read(BIO *h,char *buf,int size); | 78 | static int MS_CALLBACK file_puts(BIO *h, const char *str); |
| 79 | static int MS_CALLBACK file_puts(BIO *h,char *str); | 79 | static int MS_CALLBACK file_gets(BIO *h, char *str, int size); |
| 80 | static int MS_CALLBACK file_gets(BIO *h,char *str,int size); | 80 | static long MS_CALLBACK file_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
| 81 | static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2); | ||
| 82 | static int MS_CALLBACK file_new(BIO *h); | 81 | static int MS_CALLBACK file_new(BIO *h); |
| 83 | static int MS_CALLBACK file_free(BIO *data); | 82 | static int MS_CALLBACK file_free(BIO *data); |
| 84 | #else | ||
| 85 | static int MS_CALLBACK file_write(); | ||
| 86 | static int MS_CALLBACK file_read(); | ||
| 87 | static int MS_CALLBACK file_puts(); | ||
| 88 | static int MS_CALLBACK file_gets(); | ||
| 89 | static long MS_CALLBACK file_ctrl(); | ||
| 90 | static int MS_CALLBACK file_new(); | ||
| 91 | static int MS_CALLBACK file_free(); | ||
| 92 | #endif | ||
| 93 | |||
| 94 | static BIO_METHOD methods_filep= | 83 | static BIO_METHOD methods_filep= |
| 95 | { | 84 | { |
| 96 | BIO_TYPE_FILE, | 85 | BIO_TYPE_FILE, |
| @@ -102,11 +91,10 @@ static BIO_METHOD methods_filep= | |||
| 102 | file_ctrl, | 91 | file_ctrl, |
| 103 | file_new, | 92 | file_new, |
| 104 | file_free, | 93 | file_free, |
| 94 | NULL, | ||
| 105 | }; | 95 | }; |
| 106 | 96 | ||
| 107 | BIO *BIO_new_file(filename,mode) | 97 | BIO *BIO_new_file(const char *filename, const char *mode) |
| 108 | char *filename; | ||
| 109 | char *mode; | ||
| 110 | { | 98 | { |
| 111 | BIO *ret; | 99 | BIO *ret; |
| 112 | FILE *file; | 100 | FILE *file; |
| @@ -115,7 +103,10 @@ char *mode; | |||
| 115 | { | 103 | { |
| 116 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); | 104 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); |
| 117 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); | 105 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); |
| 118 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | 106 | if (errno == ENOENT) |
| 107 | BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE); | ||
| 108 | else | ||
| 109 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | ||
| 119 | return(NULL); | 110 | return(NULL); |
| 120 | } | 111 | } |
| 121 | if ((ret=BIO_new(BIO_s_file_internal())) == NULL) | 112 | if ((ret=BIO_new(BIO_s_file_internal())) == NULL) |
| @@ -125,9 +116,7 @@ char *mode; | |||
| 125 | return(ret); | 116 | return(ret); |
| 126 | } | 117 | } |
| 127 | 118 | ||
| 128 | BIO *BIO_new_fp(stream,close_flag) | 119 | BIO *BIO_new_fp(FILE *stream, int close_flag) |
| 129 | FILE *stream; | ||
| 130 | int close_flag; | ||
| 131 | { | 120 | { |
| 132 | BIO *ret; | 121 | BIO *ret; |
| 133 | 122 | ||
| @@ -138,13 +127,12 @@ int close_flag; | |||
| 138 | return(ret); | 127 | return(ret); |
| 139 | } | 128 | } |
| 140 | 129 | ||
| 141 | BIO_METHOD *BIO_s_file() | 130 | BIO_METHOD *BIO_s_file(void) |
| 142 | { | 131 | { |
| 143 | return(&methods_filep); | 132 | return(&methods_filep); |
| 144 | } | 133 | } |
| 145 | 134 | ||
| 146 | static int MS_CALLBACK file_new(bi) | 135 | static int MS_CALLBACK file_new(BIO *bi) |
| 147 | BIO *bi; | ||
| 148 | { | 136 | { |
| 149 | bi->init=0; | 137 | bi->init=0; |
| 150 | bi->num=0; | 138 | bi->num=0; |
| @@ -152,8 +140,7 @@ BIO *bi; | |||
| 152 | return(1); | 140 | return(1); |
| 153 | } | 141 | } |
| 154 | 142 | ||
| 155 | static int MS_CALLBACK file_free(a) | 143 | static int MS_CALLBACK file_free(BIO *a) |
| 156 | BIO *a; | ||
| 157 | { | 144 | { |
| 158 | if (a == NULL) return(0); | 145 | if (a == NULL) return(0); |
| 159 | if (a->shutdown) | 146 | if (a->shutdown) |
| @@ -168,10 +155,7 @@ BIO *a; | |||
| 168 | return(1); | 155 | return(1); |
| 169 | } | 156 | } |
| 170 | 157 | ||
| 171 | static int MS_CALLBACK file_read(b,out,outl) | 158 | static int MS_CALLBACK file_read(BIO *b, char *out, int outl) |
| 172 | BIO *b; | ||
| 173 | char *out; | ||
| 174 | int outl; | ||
| 175 | { | 159 | { |
| 176 | int ret=0; | 160 | int ret=0; |
| 177 | 161 | ||
| @@ -182,10 +166,7 @@ int outl; | |||
| 182 | return(ret); | 166 | return(ret); |
| 183 | } | 167 | } |
| 184 | 168 | ||
| 185 | static int MS_CALLBACK file_write(b,in,inl) | 169 | static int MS_CALLBACK file_write(BIO *b, const char *in, int inl) |
| 186 | BIO *b; | ||
| 187 | char *in; | ||
| 188 | int inl; | ||
| 189 | { | 170 | { |
| 190 | int ret=0; | 171 | int ret=0; |
| 191 | 172 | ||
| @@ -194,18 +175,14 @@ int inl; | |||
| 194 | if (fwrite(in,(int)inl,1,(FILE *)b->ptr)) | 175 | if (fwrite(in,(int)inl,1,(FILE *)b->ptr)) |
| 195 | ret=inl; | 176 | ret=inl; |
| 196 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ | 177 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ |
| 197 | /* acording to Tim Hudson <tjh@cryptsoft.com>, the commented | 178 | /* according to Tim Hudson <tjh@cryptsoft.com>, the commented |
| 198 | * out version above can cause 'inl' write calls under | 179 | * out version above can cause 'inl' write calls under |
| 199 | * some stupid stdio implementations (VMS) */ | 180 | * some stupid stdio implementations (VMS) */ |
| 200 | } | 181 | } |
| 201 | return(ret); | 182 | return(ret); |
| 202 | } | 183 | } |
| 203 | 184 | ||
| 204 | static long MS_CALLBACK file_ctrl(b,cmd,num,ptr) | 185 | static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) |
| 205 | BIO *b; | ||
| 206 | int cmd; | ||
| 207 | long num; | ||
| 208 | char *ptr; | ||
| 209 | { | 186 | { |
| 210 | long ret=1; | 187 | long ret=1; |
| 211 | FILE *fp=(FILE *)b->ptr; | 188 | FILE *fp=(FILE *)b->ptr; |
| @@ -214,26 +191,33 @@ char *ptr; | |||
| 214 | 191 | ||
| 215 | switch (cmd) | 192 | switch (cmd) |
| 216 | { | 193 | { |
| 194 | case BIO_C_FILE_SEEK: | ||
| 217 | case BIO_CTRL_RESET: | 195 | case BIO_CTRL_RESET: |
| 218 | ret=(long)fseek(fp,num,0); | 196 | ret=(long)fseek(fp,num,0); |
| 219 | break; | 197 | break; |
| 220 | case BIO_CTRL_EOF: | 198 | case BIO_CTRL_EOF: |
| 221 | ret=(long)feof(fp); | 199 | ret=(long)feof(fp); |
| 222 | break; | 200 | break; |
| 201 | case BIO_C_FILE_TELL: | ||
| 223 | case BIO_CTRL_INFO: | 202 | case BIO_CTRL_INFO: |
| 224 | ret=ftell(fp); | 203 | ret=ftell(fp); |
| 225 | break; | 204 | break; |
| 226 | case BIO_C_SET_FILE_PTR: | 205 | case BIO_C_SET_FILE_PTR: |
| 227 | file_free(b); | 206 | file_free(b); |
| 228 | b->shutdown=(int)num; | 207 | b->shutdown=(int)num&BIO_CLOSE; |
| 229 | b->ptr=(char *)ptr; | 208 | b->ptr=(char *)ptr; |
| 230 | b->init=1; | 209 | b->init=1; |
| 231 | #if defined(MSDOS) || defined(WINDOWS) | 210 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) |
| 232 | /* Set correct text/binary mode */ | 211 | /* Set correct text/binary mode */ |
| 233 | if (num & BIO_FP_TEXT) | 212 | if (num & BIO_FP_TEXT) |
| 234 | _setmode(fileno((FILE *)ptr),_O_TEXT); | 213 | _setmode(fileno((FILE *)ptr),_O_TEXT); |
| 235 | else | 214 | else |
| 236 | _setmode(fileno((FILE *)ptr),_O_BINARY); | 215 | _setmode(fileno((FILE *)ptr),_O_BINARY); |
| 216 | #elif defined(OPENSSL_SYS_OS2) | ||
| 217 | if (num & BIO_FP_TEXT) | ||
| 218 | setmode(fileno((FILE *)ptr), O_TEXT); | ||
| 219 | else | ||
| 220 | setmode(fileno((FILE *)ptr), O_BINARY); | ||
| 237 | #endif | 221 | #endif |
| 238 | break; | 222 | break; |
| 239 | case BIO_C_SET_FILENAME: | 223 | case BIO_C_SET_FILENAME: |
| @@ -257,7 +241,7 @@ char *ptr; | |||
| 257 | ret=0; | 241 | ret=0; |
| 258 | break; | 242 | break; |
| 259 | } | 243 | } |
| 260 | #if defined(MSDOS) || defined(WINDOWS) | 244 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) |
| 261 | if (!(num & BIO_FP_TEXT)) | 245 | if (!(num & BIO_FP_TEXT)) |
| 262 | strcat(p,"b"); | 246 | strcat(p,"b"); |
| 263 | else | 247 | else |
| @@ -307,10 +291,7 @@ char *ptr; | |||
| 307 | return(ret); | 291 | return(ret); |
| 308 | } | 292 | } |
| 309 | 293 | ||
| 310 | static int MS_CALLBACK file_gets(bp,buf,size) | 294 | static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size) |
| 311 | BIO *bp; | ||
| 312 | char *buf; | ||
| 313 | int size; | ||
| 314 | { | 295 | { |
| 315 | int ret=0; | 296 | int ret=0; |
| 316 | 297 | ||
| @@ -321,9 +302,7 @@ int size; | |||
| 321 | return(ret); | 302 | return(ret); |
| 322 | } | 303 | } |
| 323 | 304 | ||
| 324 | static int MS_CALLBACK file_puts(bp,str) | 305 | static int MS_CALLBACK file_puts(BIO *bp, const char *str) |
| 325 | BIO *bp; | ||
| 326 | char *str; | ||
| 327 | { | 306 | { |
| 328 | int n,ret; | 307 | int n,ret; |
| 329 | 308 | ||
| @@ -332,7 +311,7 @@ char *str; | |||
| 332 | return(ret); | 311 | return(ret); |
| 333 | } | 312 | } |
| 334 | 313 | ||
| 335 | #endif /* NO_STDIO */ | 314 | #endif /* OPENSSL_NO_STDIO */ |
| 336 | 315 | ||
| 337 | #endif /* HEADER_BSS_FILE_C */ | 316 | #endif /* HEADER_BSS_FILE_C */ |
| 338 | 317 | ||
