Merge pull request #228 from JacobBarthelmeh/compile

use off_t type with pwrite/pread
pull/232/head
John Safranek 2019-12-06 15:19:46 -08:00 committed by GitHub
commit 6129cf66d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -52,6 +52,7 @@ AC_PROG_INSTALL
AC_HEADER_STDC
AC_CHECK_SIZEOF([long long])
AC_CHECK_SIZEOF([long])
AC_CHECK_SIZEOF([off_t])
# Check headers/libs
AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket])

View File

@ -85,6 +85,16 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
#if (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) && \
!defined(NO_WOLFSSH_SERVER)
#ifndef SIZEOF_OFF_T
/* if not using autoconf then make a guess on off_t size based on sizeof
* long long */
#if defined(SIZEOF_LONG) && SIZEOF_LONG == 8
#define SIZEOF_OFF_T 8
#else
#define SIZEOF_OFF_T 4
#endif
#endif
#if defined(USE_WINDOWS_API) || defined(WOLFSSL_NUCLEUS) || \
defined(FREESCALE_MQX)
@ -122,7 +132,11 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
int wPwrite(WFD fd, unsigned char* buf, unsigned int sz,
const unsigned int* shortOffset)
{
long offset = ((long)shortOffset[1] << 32) | shortOffset[0];
off_t offset = (off_t)shortOffset[0];
#if SIZEOF_OFF_T == 8
offset = ((off_t)shortOffset[1] << 32) | offset;
#endif
return (int)pwrite(fd, buf, sz, offset);
}
@ -130,7 +144,11 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
int wPread(WFD fd, unsigned char* buf, unsigned int sz,
const unsigned int* shortOffset)
{
long offset = ((long)shortOffset[1] << 32) | shortOffset[0];
off_t offset = (off_t)shortOffset[0];
#if SIZEOF_OFF_T == 8
offset = ((off_t)shortOffset[1] << 32) | offset;
#endif
return (int)pread(fd, buf, sz, offset);
}

View File

@ -3807,7 +3807,9 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
atr->flags |= WOLFSSH_FILEATRB_SIZE;
atr->sz[0] = (word32)(stats.st_size & 0xFFFFFFFF);
#if SIZEOF_OFF_T == 8
atr->sz[1] = (word32)((stats.st_size >> 32) & 0xFFFFFFFF);
#endif
atr->flags |= WOLFSSH_FILEATRB_UIDGID;
atr->uid = (word32)stats.st_uid;
@ -3849,7 +3851,9 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
atr->flags |= WOLFSSH_FILEATRB_SIZE;
atr->sz[0] = (word32)(stats.st_size & 0xFFFFFFFF);
#if SIZEOF_OFF_T == 8
atr->sz[1] = (word32)((stats.st_size >> 32) & 0xFFFFFFFF);
#endif
atr->flags |= WOLFSSH_FILEATRB_UIDGID;
atr->uid = (word32)stats.st_uid;