mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
example, tests: address compiler warnings
Fix or silence all C compiler warnings discovered with (or without) `PICKY_COMPILER=ON` (in CMake). This means all warnings showing up in CI (gcc, clang, MSVS 2013/2015), in local tests on macOS (clang 14) and Windows cross-builds using gcc (12) and llvm/clang (14/15). Also fix the expression `nread -= nread` in `sftp_RW_nonblock.c`. Cherry-picked from: #846 Closes #861
This commit is contained in:
@ -71,14 +71,14 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
|
||||
writefd = &fd;
|
||||
|
||||
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
|
||||
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned long hostaddr;
|
||||
uint32_t hostaddr;
|
||||
libssh2_socket_t sock;
|
||||
int i, auth_pw = 1;
|
||||
struct sockaddr_in sin;
|
||||
@ -95,8 +95,9 @@ int main(int argc, char *argv[])
|
||||
char mem[1024 * 1000];
|
||||
size_t nread;
|
||||
size_t memuse;
|
||||
ssize_t nwritten;
|
||||
time_t start;
|
||||
long total = 0;
|
||||
libssh2_struct_stat_size total = 0;
|
||||
int duration;
|
||||
|
||||
#ifdef WIN32
|
||||
@ -258,29 +259,28 @@ int main(int argc, char *argv[])
|
||||
total += nread;
|
||||
|
||||
/* write data in a loop until we block */
|
||||
while((rc = libssh2_sftp_write(sftp_handle, mem, memuse)) ==
|
||||
while((nwritten = libssh2_sftp_write(sftp_handle, mem, memuse)) ==
|
||||
LIBSSH2_ERROR_EAGAIN) {
|
||||
waitsocket(sock, session);
|
||||
}
|
||||
if(rc < 0)
|
||||
if(nwritten < 0)
|
||||
break;
|
||||
|
||||
if(memuse - rc) {
|
||||
if(memuse - nwritten) {
|
||||
/* make room for more data at the end of the buffer */
|
||||
memmove(&mem[0], &mem[rc], memuse - rc);
|
||||
memuse -= rc;
|
||||
memmove(&mem[0], &mem[nwritten], memuse - nwritten);
|
||||
memuse -= nwritten;
|
||||
}
|
||||
else
|
||||
/* 'mem' was consumed fully */
|
||||
memuse = 0;
|
||||
|
||||
} while(rc > 0);
|
||||
} while(nwritten > 0);
|
||||
|
||||
duration = (int)(time(NULL)-start);
|
||||
|
||||
fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
||||
total, duration, total/(double)duration);
|
||||
|
||||
(long)total, duration, (double)total / duration);
|
||||
|
||||
fclose(local);
|
||||
libssh2_sftp_close(sftp_handle);
|
||||
|
Reference in New Issue
Block a user