155714Skris/* crypto/bio/bss_file.c */ 255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 8296341Sdelphij * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15296341Sdelphij * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 22296341Sdelphij * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 37296341Sdelphij * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40296341Sdelphij * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 52296341Sdelphij * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 5855714Skris 59296341Sdelphij/*- 60296341Sdelphij * 03-Dec-1997 rdenny@dc3.com Fix bug preventing use of stdin/stdout 61296341Sdelphij * with binary data (e.g. asn1parse -inform DER < xxx) under 62296341Sdelphij * Windows 6355714Skris */ 6455714Skris 6555714Skris#ifndef HEADER_BSS_FILE_C 66296341Sdelphij# define HEADER_BSS_FILE_C 6755714Skris 68296341Sdelphij# if defined(__linux) || defined(__sun) || defined(__hpux) 69296341Sdelphij/* 70296341Sdelphij * Following definition aliases fopen to fopen64 on above mentioned 71296341Sdelphij * platforms. This makes it possible to open and sequentially access files 72296341Sdelphij * larger than 2GB from 32-bit application. It does not allow to traverse 73296341Sdelphij * them beyond 2GB with fseek/ftell, but on the other hand *no* 32-bit 74296341Sdelphij * platform permits that, not with fseek/ftell. Not to mention that breaking 75296341Sdelphij * 2GB limit for seeking would require surgery to *our* API. But sequential 76296341Sdelphij * access suffices for practical cases when you can run into large files, 77296341Sdelphij * such as fingerprinting, so we can let API alone. For reference, the list 78296341Sdelphij * of 32-bit platforms which allow for sequential access of large files 79296341Sdelphij * without extra "magic" comprise *BSD, Darwin, IRIX... 80160814Ssimon */ 81296341Sdelphij# ifndef _FILE_OFFSET_BITS 82296341Sdelphij# define _FILE_OFFSET_BITS 64 83296341Sdelphij# endif 84296341Sdelphij# endif 85160814Ssimon 86296341Sdelphij# include <stdio.h> 87296341Sdelphij# include <errno.h> 88296341Sdelphij# include "cryptlib.h" 89296341Sdelphij# include "bio_lcl.h" 90296341Sdelphij# include <openssl/err.h> 9155714Skris 92296341Sdelphij# if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) 93296341Sdelphij# include <nwfileio.h> 94296341Sdelphij# endif 95194206Ssimon 96296341Sdelphij# if !defined(OPENSSL_NO_STDIO) 9755714Skris 9868651Skrisstatic int MS_CALLBACK file_write(BIO *h, const char *buf, int num); 9968651Skrisstatic int MS_CALLBACK file_read(BIO *h, char *buf, int size); 10068651Skrisstatic int MS_CALLBACK file_puts(BIO *h, const char *str); 10168651Skrisstatic int MS_CALLBACK file_gets(BIO *h, char *str, int size); 10268651Skrisstatic long MS_CALLBACK file_ctrl(BIO *h, int cmd, long arg1, void *arg2); 10355714Skrisstatic int MS_CALLBACK file_new(BIO *h); 10455714Skrisstatic int MS_CALLBACK file_free(BIO *data); 105296341Sdelphijstatic BIO_METHOD methods_filep = { 106296341Sdelphij BIO_TYPE_FILE, 107296341Sdelphij "FILE pointer", 108296341Sdelphij file_write, 109296341Sdelphij file_read, 110296341Sdelphij file_puts, 111296341Sdelphij file_gets, 112296341Sdelphij file_ctrl, 113296341Sdelphij file_new, 114296341Sdelphij file_free, 115296341Sdelphij NULL, 116296341Sdelphij}; 11755714Skris 11855714SkrisBIO *BIO_new_file(const char *filename, const char *mode) 119296341Sdelphij{ 120296341Sdelphij BIO *ret; 121296341Sdelphij FILE *file = NULL; 12255714Skris 123296341Sdelphij# if defined(_WIN32) && defined(CP_UTF8) 124296341Sdelphij int sz, len_0 = (int)strlen(filename) + 1; 125296341Sdelphij DWORD flags; 126238405Sjkim 127296341Sdelphij /* 128296341Sdelphij * Basically there are three cases to cover: a) filename is 129296341Sdelphij * pure ASCII string; b) actual UTF-8 encoded string and 130296341Sdelphij * c) locale-ized string, i.e. one containing 8-bit 131296341Sdelphij * characters that are meaningful in current system locale. 132296341Sdelphij * If filename is pure ASCII or real UTF-8 encoded string, 133296341Sdelphij * MultiByteToWideChar succeeds and _wfopen works. If 134296341Sdelphij * filename is locale-ized string, chances are that 135296341Sdelphij * MultiByteToWideChar fails reporting 136296341Sdelphij * ERROR_NO_UNICODE_TRANSLATION, in which case we fall 137296341Sdelphij * back to fopen... 138296341Sdelphij */ 139296341Sdelphij if ((sz = MultiByteToWideChar(CP_UTF8, (flags = MB_ERR_INVALID_CHARS), 140296341Sdelphij filename, len_0, NULL, 0)) > 0 || 141296341Sdelphij (GetLastError() == ERROR_INVALID_FLAGS && 142296341Sdelphij (sz = MultiByteToWideChar(CP_UTF8, (flags = 0), 143296341Sdelphij filename, len_0, NULL, 0)) > 0) 144296341Sdelphij ) { 145296341Sdelphij WCHAR wmode[8]; 146296341Sdelphij WCHAR *wfilename = _alloca(sz * sizeof(WCHAR)); 147238405Sjkim 148296341Sdelphij if (MultiByteToWideChar(CP_UTF8, flags, 149296341Sdelphij filename, len_0, wfilename, sz) && 150296341Sdelphij MultiByteToWideChar(CP_UTF8, 0, mode, strlen(mode) + 1, 151296341Sdelphij wmode, sizeof(wmode) / sizeof(wmode[0])) && 152296341Sdelphij (file = _wfopen(wfilename, wmode)) == NULL && 153296341Sdelphij (errno == ENOENT || errno == EBADF) 154296341Sdelphij ) { 155296341Sdelphij /* 156296341Sdelphij * UTF-8 decode succeeded, but no file, filename 157296341Sdelphij * could still have been locale-ized... 158296341Sdelphij */ 159296341Sdelphij file = fopen(filename, mode); 160296341Sdelphij } 161296341Sdelphij } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) { 162296341Sdelphij file = fopen(filename, mode); 163296341Sdelphij } 164296341Sdelphij# else 165296341Sdelphij file = fopen(filename, mode); 166296341Sdelphij# endif 167296341Sdelphij if (file == NULL) { 168296341Sdelphij SYSerr(SYS_F_FOPEN, get_last_sys_error()); 169296341Sdelphij ERR_add_error_data(5, "fopen('", filename, "','", mode, "')"); 170296341Sdelphij if (errno == ENOENT) 171296341Sdelphij BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE); 172296341Sdelphij else 173296341Sdelphij BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB); 174296341Sdelphij return (NULL); 175296341Sdelphij } 176296341Sdelphij if ((ret = BIO_new(BIO_s_file())) == NULL) { 177296341Sdelphij fclose(file); 178296341Sdelphij return (NULL); 179296341Sdelphij } 18055714Skris 181296341Sdelphij BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage 182296341Sdelphij * UPLINK */ 183296341Sdelphij BIO_set_fp(ret, file, BIO_CLOSE); 184296341Sdelphij return (ret); 185296341Sdelphij} 18655714Skris 18755714SkrisBIO *BIO_new_fp(FILE *stream, int close_flag) 188296341Sdelphij{ 189296341Sdelphij BIO *ret; 19055714Skris 191296341Sdelphij if ((ret = BIO_new(BIO_s_file())) == NULL) 192296341Sdelphij return (NULL); 19355714Skris 194296341Sdelphij BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for 195296341Sdelphij * documentation puposes */ 196296341Sdelphij BIO_set_fp(ret, stream, close_flag); 197296341Sdelphij return (ret); 198296341Sdelphij} 19955714Skris 20055714SkrisBIO_METHOD *BIO_s_file(void) 201296341Sdelphij{ 202296341Sdelphij return (&methods_filep); 203296341Sdelphij} 20455714Skris 20555714Skrisstatic int MS_CALLBACK file_new(BIO *bi) 206296341Sdelphij{ 207296341Sdelphij bi->init = 0; 208296341Sdelphij bi->num = 0; 209296341Sdelphij bi->ptr = NULL; 210296341Sdelphij bi->flags = BIO_FLAGS_UPLINK; /* default to UPLINK */ 211296341Sdelphij return (1); 212296341Sdelphij} 21355714Skris 21455714Skrisstatic int MS_CALLBACK file_free(BIO *a) 215296341Sdelphij{ 216296341Sdelphij if (a == NULL) 217296341Sdelphij return (0); 218296341Sdelphij if (a->shutdown) { 219296341Sdelphij if ((a->init) && (a->ptr != NULL)) { 220296341Sdelphij if (a->flags & BIO_FLAGS_UPLINK) 221296341Sdelphij UP_fclose(a->ptr); 222296341Sdelphij else 223296341Sdelphij fclose(a->ptr); 224296341Sdelphij a->ptr = NULL; 225296341Sdelphij a->flags = BIO_FLAGS_UPLINK; 226296341Sdelphij } 227296341Sdelphij a->init = 0; 228296341Sdelphij } 229296341Sdelphij return (1); 230296341Sdelphij} 231296341Sdelphij 23255714Skrisstatic int MS_CALLBACK file_read(BIO *b, char *out, int outl) 233296341Sdelphij{ 234296341Sdelphij int ret = 0; 23555714Skris 236296341Sdelphij if (b->init && (out != NULL)) { 237296341Sdelphij if (b->flags & BIO_FLAGS_UPLINK) 238296341Sdelphij ret = UP_fread(out, 1, (int)outl, b->ptr); 239296341Sdelphij else 240296341Sdelphij ret = fread(out, 1, (int)outl, (FILE *)b->ptr); 241296341Sdelphij if (ret == 0 242296341Sdelphij && (b->flags & BIO_FLAGS_UPLINK) ? UP_ferror((FILE *)b->ptr) : 243296341Sdelphij ferror((FILE *)b->ptr)) { 244296341Sdelphij SYSerr(SYS_F_FREAD, get_last_sys_error()); 245296341Sdelphij BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); 246296341Sdelphij ret = -1; 247296341Sdelphij } 248296341Sdelphij } 249296341Sdelphij return (ret); 250296341Sdelphij} 25155714Skris 25268651Skrisstatic int MS_CALLBACK file_write(BIO *b, const char *in, int inl) 253296341Sdelphij{ 254296341Sdelphij int ret = 0; 25555714Skris 256296341Sdelphij if (b->init && (in != NULL)) { 257296341Sdelphij if (b->flags & BIO_FLAGS_UPLINK) 258296341Sdelphij ret = UP_fwrite(in, (int)inl, 1, b->ptr); 259296341Sdelphij else 260296341Sdelphij ret = fwrite(in, (int)inl, 1, (FILE *)b->ptr); 261296341Sdelphij if (ret) 262296341Sdelphij ret = inl; 263296341Sdelphij /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ 264296341Sdelphij /* 265296341Sdelphij * according to Tim Hudson <tjh@cryptsoft.com>, the commented out 266296341Sdelphij * version above can cause 'inl' write calls under some stupid stdio 267296341Sdelphij * implementations (VMS) 268296341Sdelphij */ 269296341Sdelphij } 270296341Sdelphij return (ret); 271296341Sdelphij} 27255714Skris 27368651Skrisstatic long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) 274296341Sdelphij{ 275296341Sdelphij long ret = 1; 276296341Sdelphij FILE *fp = (FILE *)b->ptr; 277296341Sdelphij FILE **fpp; 278296341Sdelphij char p[4]; 27955714Skris 280296341Sdelphij switch (cmd) { 281296341Sdelphij case BIO_C_FILE_SEEK: 282296341Sdelphij case BIO_CTRL_RESET: 283296341Sdelphij if (b->flags & BIO_FLAGS_UPLINK) 284296341Sdelphij ret = (long)UP_fseek(b->ptr, num, 0); 285296341Sdelphij else 286296341Sdelphij ret = (long)fseek(fp, num, 0); 287296341Sdelphij break; 288296341Sdelphij case BIO_CTRL_EOF: 289296341Sdelphij if (b->flags & BIO_FLAGS_UPLINK) 290296341Sdelphij ret = (long)UP_feof(fp); 291296341Sdelphij else 292296341Sdelphij ret = (long)feof(fp); 293296341Sdelphij break; 294296341Sdelphij case BIO_C_FILE_TELL: 295296341Sdelphij case BIO_CTRL_INFO: 296296341Sdelphij if (b->flags & BIO_FLAGS_UPLINK) 297296341Sdelphij ret = UP_ftell(b->ptr); 298296341Sdelphij else 299296341Sdelphij ret = ftell(fp); 300296341Sdelphij break; 301296341Sdelphij case BIO_C_SET_FILE_PTR: 302296341Sdelphij file_free(b); 303296341Sdelphij b->shutdown = (int)num & BIO_CLOSE; 304296341Sdelphij b->ptr = ptr; 305296341Sdelphij b->init = 1; 306296341Sdelphij# if BIO_FLAGS_UPLINK!=0 307296341Sdelphij# if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES) 308296341Sdelphij# define _IOB_ENTRIES 20 309296341Sdelphij# endif 310296341Sdelphij# if defined(_IOB_ENTRIES) 311296341Sdelphij /* Safety net to catch purely internal BIO_set_fp calls */ 312296341Sdelphij if ((size_t)ptr >= (size_t)stdin && 313296341Sdelphij (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES)) 314296341Sdelphij BIO_clear_flags(b, BIO_FLAGS_UPLINK); 315296341Sdelphij# endif 316296341Sdelphij# endif 317296341Sdelphij# ifdef UP_fsetmod 318296341Sdelphij if (b->flags & BIO_FLAGS_UPLINK) 319296341Sdelphij UP_fsetmod(b->ptr, (char)((num & BIO_FP_TEXT) ? 't' : 'b')); 320296341Sdelphij else 321296341Sdelphij# endif 322296341Sdelphij { 323296341Sdelphij# if defined(OPENSSL_SYS_WINDOWS) 324296341Sdelphij int fd = _fileno((FILE *)ptr); 325296341Sdelphij if (num & BIO_FP_TEXT) 326296341Sdelphij _setmode(fd, _O_TEXT); 327296341Sdelphij else 328296341Sdelphij _setmode(fd, _O_BINARY); 329296341Sdelphij# elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) 330296341Sdelphij int fd = fileno((FILE *)ptr); 331296341Sdelphij /* Under CLib there are differences in file modes */ 332296341Sdelphij if (num & BIO_FP_TEXT) 333296341Sdelphij setmode(fd, O_TEXT); 334296341Sdelphij else 335296341Sdelphij setmode(fd, O_BINARY); 336296341Sdelphij# elif defined(OPENSSL_SYS_MSDOS) 337296341Sdelphij int fd = fileno((FILE *)ptr); 338296341Sdelphij /* Set correct text/binary mode */ 339296341Sdelphij if (num & BIO_FP_TEXT) 340296341Sdelphij _setmode(fd, _O_TEXT); 341296341Sdelphij /* Dangerous to set stdin/stdout to raw (unless redirected) */ 342296341Sdelphij else { 343296341Sdelphij if (fd == STDIN_FILENO || fd == STDOUT_FILENO) { 344296341Sdelphij if (isatty(fd) <= 0) 345296341Sdelphij _setmode(fd, _O_BINARY); 346296341Sdelphij } else 347296341Sdelphij _setmode(fd, _O_BINARY); 348296341Sdelphij } 349296341Sdelphij# elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) 350296341Sdelphij int fd = fileno((FILE *)ptr); 351296341Sdelphij if (num & BIO_FP_TEXT) 352296341Sdelphij setmode(fd, O_TEXT); 353296341Sdelphij else 354296341Sdelphij setmode(fd, O_BINARY); 355296341Sdelphij# endif 356296341Sdelphij } 357296341Sdelphij break; 358296341Sdelphij case BIO_C_SET_FILENAME: 359296341Sdelphij file_free(b); 360296341Sdelphij b->shutdown = (int)num & BIO_CLOSE; 361296341Sdelphij if (num & BIO_FP_APPEND) { 362296341Sdelphij if (num & BIO_FP_READ) 363296341Sdelphij BUF_strlcpy(p, "a+", sizeof p); 364296341Sdelphij else 365296341Sdelphij BUF_strlcpy(p, "a", sizeof p); 366296341Sdelphij } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) 367296341Sdelphij BUF_strlcpy(p, "r+", sizeof p); 368296341Sdelphij else if (num & BIO_FP_WRITE) 369296341Sdelphij BUF_strlcpy(p, "w", sizeof p); 370296341Sdelphij else if (num & BIO_FP_READ) 371296341Sdelphij BUF_strlcpy(p, "r", sizeof p); 372296341Sdelphij else { 373296341Sdelphij BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE); 374296341Sdelphij ret = 0; 375296341Sdelphij break; 376296341Sdelphij } 377296341Sdelphij# if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) 378296341Sdelphij if (!(num & BIO_FP_TEXT)) 379296341Sdelphij strcat(p, "b"); 380296341Sdelphij else 381296341Sdelphij strcat(p, "t"); 382296341Sdelphij# endif 383296341Sdelphij# if defined(OPENSSL_SYS_NETWARE) 384296341Sdelphij if (!(num & BIO_FP_TEXT)) 385296341Sdelphij strcat(p, "b"); 386296341Sdelphij else 387296341Sdelphij strcat(p, "t"); 388296341Sdelphij# endif 389296341Sdelphij fp = fopen(ptr, p); 390296341Sdelphij if (fp == NULL) { 391296341Sdelphij SYSerr(SYS_F_FOPEN, get_last_sys_error()); 392296341Sdelphij ERR_add_error_data(5, "fopen('", ptr, "','", p, "')"); 393296341Sdelphij BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB); 394296341Sdelphij ret = 0; 395296341Sdelphij break; 396296341Sdelphij } 397296341Sdelphij b->ptr = fp; 398296341Sdelphij b->init = 1; 399296341Sdelphij BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage 400296341Sdelphij * UPLINK */ 401296341Sdelphij break; 402296341Sdelphij case BIO_C_GET_FILE_PTR: 403296341Sdelphij /* the ptr parameter is actually a FILE ** in this case. */ 404296341Sdelphij if (ptr != NULL) { 405296341Sdelphij fpp = (FILE **)ptr; 406296341Sdelphij *fpp = (FILE *)b->ptr; 407296341Sdelphij } 408296341Sdelphij break; 409296341Sdelphij case BIO_CTRL_GET_CLOSE: 410296341Sdelphij ret = (long)b->shutdown; 411296341Sdelphij break; 412296341Sdelphij case BIO_CTRL_SET_CLOSE: 413296341Sdelphij b->shutdown = (int)num; 414296341Sdelphij break; 415296341Sdelphij case BIO_CTRL_FLUSH: 416296341Sdelphij if (b->flags & BIO_FLAGS_UPLINK) 417296341Sdelphij UP_fflush(b->ptr); 418296341Sdelphij else 419296341Sdelphij fflush((FILE *)b->ptr); 420296341Sdelphij break; 421296341Sdelphij case BIO_CTRL_DUP: 422296341Sdelphij ret = 1; 423296341Sdelphij break; 42455714Skris 425296341Sdelphij case BIO_CTRL_WPENDING: 426296341Sdelphij case BIO_CTRL_PENDING: 427296341Sdelphij case BIO_CTRL_PUSH: 428296341Sdelphij case BIO_CTRL_POP: 429296341Sdelphij default: 430296341Sdelphij ret = 0; 431296341Sdelphij break; 432296341Sdelphij } 433296341Sdelphij return (ret); 434296341Sdelphij} 43555714Skris 43655714Skrisstatic int MS_CALLBACK file_gets(BIO *bp, char *buf, int size) 437296341Sdelphij{ 438296341Sdelphij int ret = 0; 43955714Skris 440296341Sdelphij buf[0] = '\0'; 441296341Sdelphij if (bp->flags & BIO_FLAGS_UPLINK) { 442296341Sdelphij if (!UP_fgets(buf, size, bp->ptr)) 443296341Sdelphij goto err; 444296341Sdelphij } else { 445296341Sdelphij if (!fgets(buf, size, (FILE *)bp->ptr)) 446296341Sdelphij goto err; 447296341Sdelphij } 448296341Sdelphij if (buf[0] != '\0') 449296341Sdelphij ret = strlen(buf); 450296341Sdelphij err: 451296341Sdelphij return (ret); 452296341Sdelphij} 45355714Skris 45468651Skrisstatic int MS_CALLBACK file_puts(BIO *bp, const char *str) 455296341Sdelphij{ 456296341Sdelphij int n, ret; 45755714Skris 458296341Sdelphij n = strlen(str); 459296341Sdelphij ret = file_write(bp, str, n); 460296341Sdelphij return (ret); 461296341Sdelphij} 46255714Skris 463296341Sdelphij# endif /* OPENSSL_NO_STDIO */ 46455714Skris 465296341Sdelphij#endif /* HEADER_BSS_FILE_C */ 466