Use posix_win.c functions on WIN32
- read() returns bytes count as 1 for crlf unless binary mode isn't specified with open(). Reported by @ulfworsoe in libressl-portable#542 - err could be WSANOTINITIALISED when WSAStartup() is not called
This commit is contained in:
parent
0e3d93fc1d
commit
856d0511d6
@ -162,7 +162,8 @@ posix_close(int fd)
|
|||||||
{
|
{
|
||||||
if (closesocket(fd) == SOCKET_ERROR) {
|
if (closesocket(fd) == SOCKET_ERROR) {
|
||||||
int err = WSAGetLastError();
|
int err = WSAGetLastError();
|
||||||
return (err == WSAENOTSOCK || err == WSAEBADF) ?
|
return (err == WSAENOTSOCK || err == WSAEBADF ||
|
||||||
|
err == WSANOTINITIALISED) ?
|
||||||
close(fd) : wsa_errno(err);
|
close(fd) : wsa_errno(err);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -174,7 +175,8 @@ posix_read(int fd, void *buf, size_t count)
|
|||||||
ssize_t rc = recv(fd, buf, count, 0);
|
ssize_t rc = recv(fd, buf, count, 0);
|
||||||
if (rc == SOCKET_ERROR) {
|
if (rc == SOCKET_ERROR) {
|
||||||
int err = WSAGetLastError();
|
int err = WSAGetLastError();
|
||||||
return (err == WSAENOTSOCK || err == WSAEBADF) ?
|
return (err == WSAENOTSOCK || err == WSAEBADF ||
|
||||||
|
err == WSANOTINITIALISED) ?
|
||||||
read(fd, buf, count) : wsa_errno(err);
|
read(fd, buf, count) : wsa_errno(err);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
@ -186,7 +188,8 @@ posix_write(int fd, const void *buf, size_t count)
|
|||||||
ssize_t rc = send(fd, buf, count, 0);
|
ssize_t rc = send(fd, buf, count, 0);
|
||||||
if (rc == SOCKET_ERROR) {
|
if (rc == SOCKET_ERROR) {
|
||||||
int err = WSAGetLastError();
|
int err = WSAGetLastError();
|
||||||
return (err == WSAENOTSOCK || err == WSAEBADF) ?
|
return (err == WSAENOTSOCK || err == WSAEBADF ||
|
||||||
|
err == WSANOTINITIALISED) ?
|
||||||
write(fd, buf, count) : wsa_errno(err);
|
write(fd, buf, count) : wsa_errno(err);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
--- tests/keypairtest.c.orig Sun Mar 18 00:31:20 2018
|
|
||||||
+++ tests/keypairtest.c Sun Mar 18 00:31:33 2018
|
|
||||||
@@ -15,6 +15,10 @@
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
+#ifdef _MSC_VER
|
|
||||||
+#define NO_REDEF_POSIX_FUNCTIONS
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <err.h>
|
|
@ -1,25 +0,0 @@
|
|||||||
--- tls/tls_config.c.orig Fri Jul 26 22:16:53 2019
|
|
||||||
+++ tls/tls_config.c Fri Jul 26 22:21:25 2019
|
|
||||||
@@ -15,6 +15,10 @@
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
+#ifdef _MSC_VER
|
|
||||||
+#define NO_REDEF_POSIX_FUNCTIONS
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
@@ -48,7 +52,11 @@ tls_config_load_file(struct tls_error *error, const ch
|
|
||||||
*buf = NULL;
|
|
||||||
*len = 0;
|
|
||||||
|
|
||||||
+#ifndef _WIN32
|
|
||||||
if ((fd = open(filename, O_RDONLY)) == -1) {
|
|
||||||
+#else
|
|
||||||
+ if ((fd = open(filename, O_RDONLY | O_BINARY)) == -1) {
|
|
||||||
+#endif
|
|
||||||
tls_error_set(error, "failed to open %s file '%s'",
|
|
||||||
filetype, filename);
|
|
||||||
goto err;
|
|
@ -1,25 +0,0 @@
|
|||||||
--- tls/tls_util.c.orig Fri Jul 26 22:17:04 2019
|
|
||||||
+++ tls/tls_util.c Fri Jul 26 22:21:22 2019
|
|
||||||
@@ -17,6 +17,10 @@
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
+#ifdef _MSC_VER
|
|
||||||
+#define NO_REDEF_POSIX_FUNCTIONS
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
@@ -161,7 +165,11 @@ tls_load_file(const char *name, size_t *len, char *pas
|
|
||||||
|
|
||||||
*len = 0;
|
|
||||||
|
|
||||||
+#ifndef _WIN32
|
|
||||||
if ((fd = open(name, O_RDONLY)) == -1)
|
|
||||||
+#else
|
|
||||||
+ if ((fd = open(name, O_RDONLY | O_BINARY)) == -1)
|
|
||||||
+#endif
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
/* Just load the file into memory without decryption */
|
|
Loading…
x
Reference in New Issue
Block a user