Use non-deprecated methods on windows.
Use of strdup, close, lseek, read, and write prevent linking statically againt libcmt.lib. Change-Id: I04f7876ec0f03f29f000bbcc6b2ccdec844452d2 Reviewed-on: https://boringssl-review.googlesource.com/8010 Reviewed-by: David Benjamin <davidben@google.com>
This commit is contained in:
parent
e09e579603
commit
f0322b2abc
@ -74,8 +74,6 @@ elseif(MSVC)
|
||||
"C4800" # 'int' : forcing value to bool 'true' or 'false'
|
||||
# (performance warning)
|
||||
"C4820" # 'bytes' bytes padding added after construct 'member_name'
|
||||
"C4996" # 'read': The POSIX name for this item is deprecated. Instead,
|
||||
# use the ISO C++ conformant name: _read.
|
||||
"C5027" # move assignment operator was implicitly defined as deleted
|
||||
)
|
||||
set(MSVC_LEVEL4_WARNINGS_LIST
|
||||
@ -91,6 +89,7 @@ elseif(MSVC)
|
||||
add_definitions(-D_HAS_EXCEPTIONS=0)
|
||||
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
||||
add_definitions(-DNOMINMAX)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Allow use of fopen
|
||||
endif()
|
||||
|
||||
if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
|
||||
|
@ -108,20 +108,25 @@ static int bio_fd_non_fatal_error(int err) {
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
int bio_fd_should_retry(int i) {
|
||||
if (i == -1) {
|
||||
return bio_fd_non_fatal_error((int)GetLastError());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#define BORINGSSL_ERRNO (int)GetLastError()
|
||||
#define BORINGSSL_CLOSE _close
|
||||
#define BORINGSSL_LSEEK _lseek
|
||||
#define BORINGSSL_READ _read
|
||||
#define BORINGSSL_WRITE _write
|
||||
#else
|
||||
#define BORINGSSL_ERRNO errno
|
||||
#define BORINGSSL_CLOSE close
|
||||
#define BORINGSSL_LSEEK lseek
|
||||
#define BORINGSSL_READ read
|
||||
#define BORINGSSL_WRITE write
|
||||
#endif
|
||||
|
||||
int bio_fd_should_retry(int i) {
|
||||
if (i == -1) {
|
||||
return bio_fd_non_fatal_error(errno);
|
||||
return bio_fd_non_fatal_error(BORINGSSL_ERRNO);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
BIO *BIO_new_fd(int fd, int close_flag) {
|
||||
BIO *ret = BIO_new(BIO_s_fd());
|
||||
@ -145,7 +150,7 @@ static int fd_free(BIO *bio) {
|
||||
|
||||
if (bio->shutdown) {
|
||||
if (bio->init) {
|
||||
close(bio->num);
|
||||
BORINGSSL_CLOSE(bio->num);
|
||||
}
|
||||
bio->init = 0;
|
||||
}
|
||||
@ -155,7 +160,7 @@ static int fd_free(BIO *bio) {
|
||||
static int fd_read(BIO *b, char *out, int outl) {
|
||||
int ret = 0;
|
||||
|
||||
ret = read(b->num, out, outl);
|
||||
ret = BORINGSSL_READ(b->num, out, outl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
@ -167,7 +172,7 @@ static int fd_read(BIO *b, char *out, int outl) {
|
||||
}
|
||||
|
||||
static int fd_write(BIO *b, const char *in, int inl) {
|
||||
int ret = write(b->num, in, inl);
|
||||
int ret = BORINGSSL_WRITE(b->num, in, inl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
@ -188,14 +193,14 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
case BIO_C_FILE_SEEK:
|
||||
ret = 0;
|
||||
if (b->init) {
|
||||
ret = (long)lseek(b->num, num, SEEK_SET);
|
||||
ret = (long)BORINGSSL_LSEEK(b->num, num, SEEK_SET);
|
||||
}
|
||||
break;
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
ret = 0;
|
||||
if (b->init) {
|
||||
ret = (long)lseek(b->num, 0, SEEK_CUR);
|
||||
ret = (long)BORINGSSL_LSEEK(b->num, 0, SEEK_CUR);
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_FD:
|
||||
|
@ -152,7 +152,11 @@ int main(int argc, char **argv) {
|
||||
case 1:
|
||||
s = rand_string();
|
||||
lh_insert(lh, (void **)&s1, s);
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
dummy_lh_insert(&dummy_lh, &s2, _strdup(s));
|
||||
#else
|
||||
dummy_lh_insert(&dummy_lh, &s2, strdup(s));
|
||||
#endif
|
||||
|
||||
if (s1 != NULL && (s2 == NULL || strcmp(s1, s2) != 0)) {
|
||||
fprintf(stderr, "lh_insert failure\n");
|
||||
|
@ -147,8 +147,6 @@ uint32_t OPENSSL_hash32(const void *ptr, size_t len) {
|
||||
return h;
|
||||
}
|
||||
|
||||
char *OPENSSL_strdup(const char *s) { return strdup(s); }
|
||||
|
||||
size_t OPENSSL_strnlen(const char *s, size_t len) {
|
||||
size_t i;
|
||||
|
||||
@ -163,6 +161,8 @@ size_t OPENSSL_strnlen(const char *s, size_t len) {
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
|
||||
char *OPENSSL_strdup(const char *s) { return _strdup(s); }
|
||||
|
||||
int OPENSSL_strcasecmp(const char *a, const char *b) {
|
||||
return _stricmp(a, b);
|
||||
}
|
||||
@ -173,6 +173,8 @@ int OPENSSL_strncasecmp(const char *a, const char *b, size_t n) {
|
||||
|
||||
#else
|
||||
|
||||
char *OPENSSL_strdup(const char *s) { return strdup(s); }
|
||||
|
||||
int OPENSSL_strcasecmp(const char *a, const char *b) {
|
||||
return strcasecmp(a, b);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ typedef int ssize_t;
|
||||
|
||||
struct close_delete {
|
||||
void operator()(int *fd) {
|
||||
close(*fd);
|
||||
BORINGSSL_CLOSE(*fd);
|
||||
}
|
||||
};
|
||||
|
||||
@ -83,7 +83,7 @@ static const char kStdinName[] = "standard input";
|
||||
static bool OpenFile(int *out_fd, const std::string &filename) {
|
||||
*out_fd = -1;
|
||||
|
||||
int fd = open(filename.c_str(), O_RDONLY | O_BINARY);
|
||||
int fd = BORINGSSL_OPEN(filename.c_str(), O_RDONLY | O_BINARY);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Failed to open input file '%s': %s\n", filename.c_str(),
|
||||
strerror(errno));
|
||||
@ -146,7 +146,7 @@ static bool SumFile(std::string *out_hex, const EVP_MD *md,
|
||||
ssize_t n;
|
||||
|
||||
do {
|
||||
n = read(fd, buf.get(), kBufSize);
|
||||
n = BORINGSSL_READ(fd, buf.get(), kBufSize);
|
||||
} while (n == -1 && errno == EINTR);
|
||||
|
||||
if (n == 0) {
|
||||
@ -234,10 +234,10 @@ static bool Check(const CheckModeArguments &args, const EVP_MD *md,
|
||||
return false;
|
||||
}
|
||||
|
||||
file = fdopen(fd, "rb");
|
||||
file = BORINGSSL_FDOPEN(fd, "rb");
|
||||
if (!file) {
|
||||
perror("fdopen");
|
||||
close(fd);
|
||||
BORINGSSL_CLOSE(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,20 @@
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#define BORINGSSL_OPEN _open
|
||||
#define BORINGSSL_FDOPEN _fdopen
|
||||
#define BORINGSSL_CLOSE _close
|
||||
#define BORINGSSL_READ _read
|
||||
#define BORINGSSL_WRITE _write
|
||||
#else
|
||||
#define BORINGSSL_OPEN open
|
||||
#define BORINGSSL_FDOPEN fdopen
|
||||
#define BORINGSSL_CLOSE close
|
||||
#define BORINGSSL_READ read
|
||||
#define BORINGSSL_WRITE write
|
||||
#endif
|
||||
|
||||
enum ArgumentType {
|
||||
kRequiredArgument,
|
||||
kOptionalArgument,
|
||||
|
@ -64,7 +64,7 @@ bool DoPKCS12(const std::vector<std::string> &args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int fd = open(args_map["-dump"].c_str(), O_RDONLY);
|
||||
int fd = BORINGSSL_OPEN(args_map["-dump"].c_str(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
return false;
|
||||
@ -73,7 +73,7 @@ bool DoPKCS12(const std::vector<std::string> &args) {
|
||||
struct stat st;
|
||||
if (fstat(fd, &st)) {
|
||||
perror("fstat");
|
||||
close(fd);
|
||||
BORINGSSL_CLOSE(fd);
|
||||
return false;
|
||||
}
|
||||
const size_t size = st.st_size;
|
||||
@ -82,7 +82,7 @@ bool DoPKCS12(const std::vector<std::string> &args) {
|
||||
read_result_t n;
|
||||
size_t off = 0;
|
||||
do {
|
||||
n = read(fd, &contents[off], size - off);
|
||||
n = BORINGSSL_READ(fd, &contents[off], size - off);
|
||||
if (n >= 0) {
|
||||
off += static_cast<size_t>(n);
|
||||
}
|
||||
@ -90,11 +90,11 @@ bool DoPKCS12(const std::vector<std::string> &args) {
|
||||
|
||||
if (off != size) {
|
||||
perror("read");
|
||||
close(fd);
|
||||
BORINGSSL_CLOSE(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
BORINGSSL_CLOSE(fd);
|
||||
|
||||
printf("Enter password: ");
|
||||
fflush(stdout);
|
||||
@ -102,7 +102,7 @@ bool DoPKCS12(const std::vector<std::string> &args) {
|
||||
char password[256];
|
||||
off = 0;
|
||||
do {
|
||||
n = read(0, &password[off], sizeof(password) - 1 - off);
|
||||
n = BORINGSSL_READ(0, &password[off], sizeof(password) - 1 - off);
|
||||
if (n >= 0) {
|
||||
off += static_cast<size_t>(n);
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ bool TransferData(SSL *ssl, int sock) {
|
||||
ssize_t n;
|
||||
|
||||
do {
|
||||
n = read(0, buffer, sizeof(buffer));
|
||||
n = BORINGSSL_READ(0, buffer, sizeof(buffer));
|
||||
} while (n == -1 && errno == EINTR);
|
||||
|
||||
if (n == 0) {
|
||||
@ -319,7 +319,7 @@ bool TransferData(SSL *ssl, int sock) {
|
||||
|
||||
ssize_t n;
|
||||
do {
|
||||
n = write(1, buffer, ssl_ret);
|
||||
n = BORINGSSL_WRITE(1, buffer, ssl_ret);
|
||||
} while (n == -1 && errno == EINTR);
|
||||
|
||||
if (n != ssl_ret) {
|
||||
|
Loading…
Reference in New Issue
Block a user