From b5cd8fe1208acf07ab54b65554dda91af1bc6606 Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Sat, 10 Sep 2011 16:29:29 +0200 Subject: [PATCH] Fixed uint64_t printf. --- example/sftpdir.c | 31 ++++++++++++++++++++++--------- example/sftpdir_nonblock.c | 27 ++++++++++++++++++++------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/example/sftpdir.c b/example/sftpdir.c index 57f8b3b..006fd27 100644 --- a/example/sftpdir.c +++ b/example/sftpdir.c @@ -20,12 +20,15 @@ #ifdef HAVE_NETINET_IN_H # include #endif -# ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_UNISTD_H +# include #endif #ifdef HAVE_ARPA_INET_H # include #endif +#ifdef HAVE_INTTYPES_H +# include +#endif #include #include @@ -33,6 +36,22 @@ #include #include +/* last resort for systems not defining PRIu64 in inttypes.h */ +#ifndef __PRI64_PREFIX +#ifdef WIN32 +#define __PRI64_PREFIX "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 */ + int main(int argc, char *argv[]) { unsigned long hostaddr; @@ -186,13 +205,7 @@ int main(int argc, char *argv[]) } if(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) { - /* attrs.filesize is an uint64_t according to - the docs but there is no really good and - portable 64bit type for C before C99, and - correspondingly there was no good printf() - option for it... */ - - printf("%8lld ", attrs.filesize); + printf("%8" PRIu64 " ", attrs.filesize); } printf("%s\n", mem); diff --git a/example/sftpdir_nonblock.c b/example/sftpdir_nonblock.c index 1dfea17..38fb010 100644 --- a/example/sftpdir_nonblock.c +++ b/example/sftpdir_nonblock.c @@ -26,6 +26,9 @@ #ifdef HAVE_ARPA_INET_H # include #endif +#ifdef HAVE_INTTYPES_H +# include +#endif #include #include @@ -33,6 +36,22 @@ #include #include +/* last resort for systems not defining PRIu64 in inttypes.h */ +#ifndef __PRI64_PREFIX +#ifdef WIN32 +#define __PRI64_PREFIX "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 */ + int main(int argc, char *argv[]) { unsigned long hostaddr; @@ -193,13 +212,7 @@ int main(int argc, char *argv[]) } if(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) { - /* attrs.filesize is an uint64_t according to - the docs but there is no really good and - portable 64bit type for C before C99, and - correspondingly there was no good printf() - option for it... */ - - printf("%8lld ", attrs.filesize); + printf("%8" PRIu64 " ", attrs.filesize); } printf("%s\n", mem);