Skip to content

Commit

Permalink
examples: fix various compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bagder committed Mar 17, 2019
1 parent bd5a620 commit 54ff8ff
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
4 changes: 2 additions & 2 deletions example/scp_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions example/sftp_RW_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
18 changes: 4 additions & 14 deletions example/sftpdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,11 @@
#include <stdio.h>
#include <ctype.h>

/* 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";
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 4 additions & 14 deletions example/sftpdir_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,11 @@
#include <stdio.h>
#include <ctype.h>

/* 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[])
{
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion example/x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 54ff8ff

Please sign in to comment.