diff options
Diffstat (limited to 'src/crypto/bio/file.c')
-rw-r--r-- | src/crypto/bio/file.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/crypto/bio/file.c b/src/crypto/bio/file.c index 2d3ccfe..7f57aad 100644 --- a/src/crypto/bio/file.c +++ b/src/crypto/bio/file.c @@ -88,7 +88,7 @@ #define BIO_FP_APPEND 0x08 static FILE *open_file(const char *filename, const char *mode) { -#if defined(OPENSSL_WINDOWS) && defined(CP_UTF8) +#if defined(_WIN32) && defined(CP_UTF8) int sz, len_0 = (int)strlen(filename) + 1; DWORD flags; @@ -133,9 +133,9 @@ BIO *BIO_new_file(const char *filename, const char *mode) { ERR_add_error_data(5, "fopen('", filename, "','", mode, "')"); if (errno == ENOENT) { - OPENSSL_PUT_ERROR(BIO, BIO_R_NO_SUCH_FILE); + OPENSSL_PUT_ERROR(BIO, BIO_new_file, BIO_R_NO_SUCH_FILE); } else { - OPENSSL_PUT_ERROR(BIO, BIO_R_SYS_LIB); + OPENSSL_PUT_ERROR(BIO, BIO_new_file, BIO_R_SYS_LIB); } return NULL; } @@ -182,19 +182,20 @@ static int file_free(BIO *bio) { } static int file_read(BIO *b, char *out, int outl) { + int ret = 0; + if (!b->init) { return 0; } - size_t ret = fread(out, 1, outl, (FILE *)b->ptr); + ret = fread(out, 1, outl, (FILE *)b->ptr); if (ret == 0 && ferror((FILE *)b->ptr)) { OPENSSL_PUT_SYSTEM_ERROR(fread); - OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB); - return -1; + OPENSSL_PUT_ERROR(BIO, file_read, ERR_R_SYS_LIB); + ret = -1; } - /* fread reads at most |outl| bytes, so |ret| fits in an int. */ - return (int)ret; + return ret; } static int file_write(BIO *b, const char *in, int inl) { @@ -252,7 +253,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) { } else if (num & BIO_FP_READ) { BUF_strlcpy(p, "r", sizeof(p)); } else { - OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE); + OPENSSL_PUT_ERROR(BIO, file_ctrl, BIO_R_BAD_FOPEN_MODE); ret = 0; break; } @@ -260,7 +261,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) { if (fp == NULL) { OPENSSL_PUT_SYSTEM_ERROR(fopen); ERR_add_error_data(5, "fopen('", ptr, "','", p, "')"); - OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB); + OPENSSL_PUT_ERROR(BIO, file_ctrl, ERR_R_SYS_LIB); ret = 0; break; } |