mirror of https://github.com/wolfSSL/wolfssh.git
Fix missing pread() and pwrite()
1. configure.ac: Check that the DECLs for `pread()` and `pwrite()` exist in unistd.h. 2. port.c: If `pread()` or `pwrite()` aren't available, use the local versions that are wrappers around `seek()` and `read()` and `write()`.pull/383/head
parent
796423bfac
commit
ba42d6f732
|
@ -84,6 +84,7 @@ CPPFLAGS="$CPPFLAGS -I${wcpath}/include"
|
|||
|
||||
AC_CHECK_LIB([wolfssl],[wolfCrypt_Init],,[AC_MSG_ERROR([libwolfssl is required for ${PACKAGE}. It can be obtained from https://www.wolfssl.com/download.html/ .])])
|
||||
AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket wc_ecc_set_rng])
|
||||
AC_CHECK_DECLS([[pread],[pwrite]],,[unistd.h])
|
||||
|
||||
# DEBUG
|
||||
DEBUG_CFLAGS="-g -O0"
|
||||
|
|
22
src/port.c
22
src/port.c
|
@ -37,6 +37,13 @@
|
|||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
Flags:
|
||||
WOLFSSH_LOCAL_PREAD_PWRITE
|
||||
Defined to use local implementations of pread() and pwrite(). Switched
|
||||
on automatically if pread() or pwrite() aren't found by configure.
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(NO_FILESYSTEM) && !defined(WOLFSSH_USER_FILESYSTEM)
|
||||
int wfopen(WFILE** f, const char* filename, const char* mode)
|
||||
|
@ -82,6 +89,16 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* If either pread() or pwrite() are missing, use the local versions. */
|
||||
#if (defined(USE_OSE_API) || \
|
||||
!defined(HAVE_DECL_PREAD) || (HAVE_DECL_PREAD == 0) || \
|
||||
!defined(HAVE_DECL_PWRITE) || (HAVE_DECL_PWRITE == 0))
|
||||
#undef WOLFSSH_LOCAL_PREAD_PWRITE
|
||||
#define WOLFSSH_LOCAL_PREAD_PWRITE
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) && \
|
||||
!defined(NO_WOLFSSH_SERVER)
|
||||
|
||||
|
@ -90,7 +107,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
|
|||
|
||||
/* This is current inline in the source. */
|
||||
|
||||
#elif defined(USE_OSE_API)
|
||||
#elif defined(WOLFSSH_LOCAL_PREAD_PWRITE)
|
||||
|
||||
int wPwrite(WFD fd, unsigned char* buf, unsigned int sz,
|
||||
const unsigned int* shortOffset)
|
||||
|
@ -104,7 +121,6 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int wPread(WFD fd, unsigned char* buf, unsigned int sz,
|
||||
const unsigned int* shortOffset)
|
||||
{
|
||||
|
@ -117,7 +133,7 @@ int wfopen(WFILE** f, const char* filename, const char* mode)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#else /* USE_WINDOWS_API USE_OSE_API */
|
||||
#else /* USE_WINDOWS_API WOLFSSH_LOCAL_PREAD_PWRITE */
|
||||
|
||||
int wPwrite(WFD fd, unsigned char* buf, unsigned int sz,
|
||||
const unsigned int* shortOffset)
|
||||
|
|
Loading…
Reference in New Issue