wolfSFTP for Windows

1. Clean up some type size warnings.
2. Fix the wrappers for FileRead() and FileWrite(). The Overlapped
struct is a little funky to use.
pull/122/head
John Safranek 2018-11-20 16:10:47 -08:00
parent 8f87568a91
commit b57e825381
3 changed files with 11 additions and 14 deletions

View File

@ -88,11 +88,9 @@ int wPwrite(WFD fd, unsigned char* buf, unsigned int sz, long ofst)
int ret; int ret;
WMEMSET(&offset, 0, sizeof(OVERLAPPED)); WMEMSET(&offset, 0, sizeof(OVERLAPPED));
offset.DUMMYUNIONNAME.DUMMYSTRUCTNAME.Offset = offset.Offset = (DWORD)(ofst & 0xFFFFFFFF);
(DWORD)(ofst & 0xFFFFFFFF); offset.OffsetHigh = (DWORD)((ofst & 0xFFFFFFFF00000000) >> 32);
offset.DUMMYUNIONNAME.DUMMYSTRUCTNAME.OffsetHigh = if (WriteFile(fd, buf, sz, &bytesWritten, &offset) != 0)
(DWORD)((ofst 0xFFFFFFFF00000000) >> 32);
if (WriteFile(XXX, data, sz, &bytesWritten, &offset) != 0)
ret = -1; ret = -1;
else else
ret = (int)bytesWritten; ret = (int)bytesWritten;
@ -108,11 +106,9 @@ int wPread(WFD fd, unsigned char* buf, unsigned int sz, long ofst)
int ret; int ret;
WMEMSET(&offset, 0, sizeof(OVERLAPPED)); WMEMSET(&offset, 0, sizeof(OVERLAPPED));
offset.DUMMYUNIONNAME.DUMMYSTRUCTNAME.Offset = offset.Offset = (DWORD)(ofst & 0xFFFFFFFF);
(DWORD)(ofst & 0xFFFFFFFF); offset.OffsetHigh = (DWORD)((ofst & 0xFFFFFFFF00000000) >> 32);
offset.DUMMYUNIONNAME.DUMMYSTRUCTNAME.OffsetHigh = if (ReadFile(fd, buf, sz, &bytesRead, &offset) != 0)
(DWORD)((ofst 0xFFFFFFFF00000000) >> 32);
if (ReadFile(XXX, data, sz, &bytesRead, &offset) != 0)
ret = -1; ret = -1;
else else
ret = (int)bytesRead; ret = (int)bytesRead;

View File

@ -22,7 +22,7 @@
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
#define _CRT_SECURE_NO_WARNINGS
#include <wolfssh/wolfsftp.h> #include <wolfssh/wolfsftp.h>
#ifdef WOLFSSH_SFTP #ifdef WOLFSSH_SFTP
@ -1588,7 +1588,7 @@ int wolfSSH_SFTP_RecvWrite(WOLFSSH* ssh, int reqId, word32 maxSz)
/* get length to be written */ /* get length to be written */
ato32(data + idx, &sz); idx += UINT32_SZ; ato32(data + idx, &sz); idx += UINT32_SZ;
ret = (int)WPWRITE(fd, data + idx, sz, ofst); ret = (int)WPWRITE(fd, data + idx, sz, (long)ofst);
WFREE(data, ssh->ctx->heap, DYNTYPE_BUFFER); WFREE(data, ssh->ctx->heap, DYNTYPE_BUFFER);
if (ret < 0) { if (ret < 0) {
#if defined(WOLFSSL_NUCLEUS) && defined(DEBUG_WOLFSSH) #if defined(WOLFSSL_NUCLEUS) && defined(DEBUG_WOLFSSH)
@ -1662,7 +1662,7 @@ int wolfSSH_SFTP_RecvRead(WOLFSSH* ssh, int reqId, word32 maxSz)
return WS_MEMORY_E; return WS_MEMORY_E;
} }
ret = (int)WPREAD(fd, data, sz, ofst); ret = (int)WPREAD(fd, data, sz, (long)ofst);
if (ret < 0) { if (ret < 0) {
WLOG(WS_LOG_SFTP, "Error reading from file"); WLOG(WS_LOG_SFTP, "Error reading from file");
WFREE(data, ssh->ctx->heap, DYNTYPE_BUFFER); WFREE(data, ssh->ctx->heap, DYNTYPE_BUFFER);

View File

@ -423,6 +423,7 @@ extern "C" {
#endif /* NO_WOLFSSH_DIR */ #endif /* NO_WOLFSSH_DIR */
#elif defined(USE_WINDOWS_API) #elif defined(USE_WINDOWS_API)
#include <windows.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <io.h> #include <io.h>
@ -442,7 +443,7 @@ extern "C" {
#define WFD HANDLE #define WFD HANDLE
int wPwrite(WFD, unsigned char*, unsigned int, long); int wPwrite(WFD, unsigned char*, unsigned int, long);
int wPread(WFD, unsigned char*, unsigned int, long); int wPread(WFD, unsigned char*, unsigned int, long);
#define WPWRITE(fd,b,s,o) wPwrite((fs),(b),(s),(o)) #define WPWRITE(fd,b,s,o) wPwrite((fd),(b),(s),(o))
#define WPREAD(fd,b,s,o) wPread((fd),(b),(s),(o)) #define WPREAD(fd,b,s,o) wPread((fd),(b),(s),(o))
#define WS_DELIM '\\' #define WS_DELIM '\\'