From 54ff8ffc6d4a9ad19c289ae769ddf36998f722c6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 15 Mar 2019 16:45:57 +0100 Subject: [PATCH] examples: fix various compiler warnings --- example/scp_nonblock.c | 4 ++-- example/sftp_RW_nonblock.c | 11 +++++++---- example/sftpdir.c | 18 ++++-------------- example/sftpdir_nonblock.c | 18 ++++-------------- example/x11.c | 9 ++++++++- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/example/scp_nonblock.c b/example/scp_nonblock.c index 45f66b83..1f8682d8 100644 --- a/example/scp_nonblock.c +++ b/example/scp_nonblock.c @@ -262,10 +262,10 @@ int main(int argc, char *argv[]) gettimeofday(&end, NULL); time_ms = tvdiff(end, start); - fprintf(stderr, "Got " LIBSSH2_STRUCT_STAT_SIZE_FORMAT " bytes in %ld ms = %.1f bytes/sec spin: %d\n", total, + fprintf(stderr, "Got %ld bytes in %ld ms = %.1f bytes/sec spin: %d\n", (long)total, time_ms, total/(time_ms/1000.0), spin); #else - fprintf(stderr, "Got " LIBSSH2_STRUCT_STAT_SIZE_FORMAT " bytes spin: %d\n", total, spin); + fprintf(stderr, "Got %ld bytes spin: %d\n", (long)total, spin); #endif libssh2_channel_free(channel); diff --git a/example/sftp_RW_nonblock.c b/example/sftp_RW_nonblock.c index 133815aa..797c75cb 100644 --- a/example/sftp_RW_nonblock.c +++ b/example/sftp_RW_nonblock.c @@ -90,6 +90,7 @@ int main(int argc, char *argv[]) char mem[1000]; struct timeval timeout; fd_set fd; + fd_set fd2; #ifdef WIN32 WSADATA wsadata; @@ -253,11 +254,12 @@ int main(int argc, char *argv[]) timeout.tv_usec = 0; FD_ZERO(&fd); - + FD_ZERO(&fd2); FD_SET(sock, &fd); + FD_SET(sock, &fd2); /* wait for readable or writeable */ - rc = select(sock+1, &fd, &fd, NULL, &timeout); + rc = select(sock+1, &fd, &fd2, NULL, &timeout); if(rc <= 0) { /* negative is error 0 is timeout */ @@ -312,11 +314,12 @@ int main(int argc, char *argv[]) timeout.tv_usec = 0; FD_ZERO(&fd); - + FD_ZERO(&fd2); FD_SET(sock, &fd); + FD_SET(sock, &fd2); /* wait for readable or writeable */ - rc = select(sock+1, &fd, &fd, NULL, &timeout); + rc = select(sock+1, &fd, &fd2, NULL, &timeout); if(rc <= 0) { /* negative is error 0 is timeout */ diff --git a/example/sftpdir.c b/example/sftpdir.c index c21f9b35..142790fc 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -36,21 +36,11 @@ #include #include -/* last resort for systems not defining PRIu64 in inttypes.h */ -#ifndef __PRI64_PREFIX #ifdef WIN32 -#define __PRI64_PREFIX "I64" +#define __FILESIZE "I64" #else -#if __WORDSIZE == 64 -#define __PRI64_PREFIX "l" -#else -#define __PRI64_PREFIX "ll" -#endif /* __WORDSIZE */ -#endif /* WIN32 */ -#endif /* !__PRI64_PREFIX */ -#ifndef PRIu64 -#define PRIu64 __PRI64_PREFIX "u" -#endif /* PRIu64 */ +#define __FILESIZE "llu" +#endif const char *keyfile1="~/.ssh/id_rsa.pub"; const char *keyfile2="~/.ssh/id_rsa"; @@ -274,7 +264,7 @@ int main(int argc, char *argv[]) } if(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) { - printf("%8" PRIu64 " ", attrs.filesize); + printf("%8" __FILESIZE " ", attrs.filesize); } printf("%s\n", mem); diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 1950e671..854c0e0a 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -36,21 +36,11 @@ #include #include -/* last resort for systems not defining PRIu64 in inttypes.h */ -#ifndef __PRI64_PREFIX #ifdef WIN32 -#define __PRI64_PREFIX "I64" +#define __FILESIZE "I64" #else -#if __WORDSIZE == 64 -#define __PRI64_PREFIX "l" -#else -#define __PRI64_PREFIX "ll" -#endif /* __WORDSIZE */ -#endif /* WIN32 */ -#endif /* !__PRI64_PREFIX */ -#ifndef PRIu64 -#define PRIu64 __PRI64_PREFIX "u" -#endif /* PRIu64 */ +#define __FILESIZE "llu" +#endif int main(int argc, char *argv[]) { @@ -217,7 +207,7 @@ int main(int argc, char *argv[]) } if(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) { - printf("%8" PRIu64 " ", attrs.filesize); + printf("%8" __FILESIZE " ", attrs.filesize); } printf("%s\n", mem); diff --git a/example/x11.c b/example/x11.c index dd01b3bc..5c8c777a 100644 --- a/example/x11.c +++ b/example/x11.c @@ -115,7 +115,10 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, struct sockaddr_un addr; struct chan_X11_list *new; struct chan_X11_list *chan_iter; - + (void)session; + (void)shost; + (void)sport; + (void)abstract; /* * Connect to the display * Inspired by x11_connect_display in openssh @@ -319,9 +322,13 @@ main (int argc, char *argv[]) if (set_debug_on == 1) libssh2_trace(session, LIBSSH2_TRACE_CONN); + /* ignore pedantic warnings by gcc on the callback argument */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" /* Set X11 Callback */ libssh2_session_callback_set(session, LIBSSH2_CALLBACK_X11, (void *)x11_callback); +#pragma GCC diagnostic pop /* Authenticate via password */ rc = libssh2_userauth_password(session, username, password);